Created
April 28, 2011 05:51
-
-
Save lastcanal/945870 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/zsh | |
| alias redis='redis-cli --raw' | |
| # pop ID from queue | |
| id=$(redis rpop "jobs:queue") | |
| # check if we have an ID | |
| if (( $#id > 0 )); then | |
| echo "running workflow $(redis hget "job:${id}:data" process)" && sleep 2 | |
| # push response back to client | |
| redis lpush "job:${id}:response" ${1-1} | |
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/zsh | |
| alias redis='redis-cli --raw' | |
| # Generate unique ID | |
| id=$(redis incr 'job:uuid') | |
| # Set key for metadata | |
| data_key="job:${id}:data" | |
| # Set metadata as hash values | |
| redis hset $data_key process ${1-sample_job} | |
| redis hset $data_key ccid 1000ab | |
| redis hset $data_key app_id 10 | |
| # Send ID to atrium queue for processing. | |
| redis lpush "jobs:queue" $id | |
| # Wait for response. Timeout in seconds or 0 for no-timeout. | |
| # brpop blocks the process on an empty queue and returns KEY\nVALUE | |
| exit_value=$(redis brpop "job:${id}:response" 600 | awk 'END { print }') | |
| # Store response value in a 'log' list. brpoplpush only returns the value. | |
| #exit_value=$(redis brpoplpush "job:${id}:log" "job:${id}:log" 600 ) | |
| # The process has finished so we can delete $data_key | |
| redis del $data_key | |
| echo exiting with value $exit_value | |
| exit $exit_value |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment