Skip to content

Instantly share code, notes, and snippets.

@lastcanal
Created April 28, 2011 05:51
Show Gist options
  • Select an option

  • Save lastcanal/945870 to your computer and use it in GitHub Desktop.

Select an option

Save lastcanal/945870 to your computer and use it in GitHub Desktop.
#!/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
#!/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