This is Midburn's tickets processing queue. Each batch of order requests submitters (say 100 orders) will be enqueue into an ordered queue (say: tier_001) which will be processed later by a worder.
Navigate to /resque
to follow processing order (or clearing past tasks).
Submit a new order by POST /enqueue
with a JSON file and Content-Type: application/json
. The following curl command will work:
curl -X POST http://midburn-tickets-queue.herokuapp.com/enqueue -d '{"firstname": "elad", "lastname": "gariany", "email":"[email protected]"}' --header "Content-Type: application/json"
Sinatra web controller code:
This service have no root route, requests will be redirected to midburn.org
get '/' do
redirect "http://midburn.org"
end
The resque-web web interface to monitor progress of tasks.
- /resque/queues/worker - The
worker
queue - /resque/working - Current worker processes (chewing on the
worker
queue)
Notice: In order to access the monitor you will need to set env values RESQUE_WEB_HTTP_BASIC_AUTH_USER
and RESQUE_WEB_HTTP_BASIC_AUTH_PASSWORD
. If those will not be provided the interface will be open to everyone.
Big reset will reset all the queues and 'tasks' (process orders). This should be perform before each sell.
post '/big-reset' do
# assuming ENV['ADMIN_SECRET_TOKEN'] is correct, reset all queues
end
admin_secret_token
- the environment's admin secret key
Enqueue new order to process.
post '/enqueue' do
# calculate tier number using ENV["QUEUE_TIER_SIZE"], the amount of tasks on queues and completed tasks.
# Add a new task to order on the relevant queue.
end
The following curl
command will queue a new order to process:
curl -X POST http://midburn-tickets-queue.herokuapp.com/enqueue -d '{"firstname": "elad", "lastname": "gariany", "email":"[email protected]"}' --header "Content-Type: application/json"
firstname
- Submitter's first name.lastname
- Submitter's last name.email
- Submitter's email address (profile on profile.midburn.org)
- Orders in the system are limited to 500 * QUEUE_TIER_SIZE (say, 50,000 in case each tier size is 100).
def process_order(json = {"firstname":"elad","lastname":"gariany","email":"[email protected]"})
# process order
# - validate with profile system, to confirm user have a profile
# - generate the email to be send to a client
# - send the email for purchase
end
class OrderTier_1
@queue = :tier_001
def self.perform(json)
process_order(JSON.parse(json))
end
end
-
Close the queue:
heroku run bundle exec rake midburn:close_queue --app midburn-queue
-
Open the queue:
heroku run bundle exec rake midburn:open_queue --app midburn-queue
-
Getting the list of emails in the queue
heroku run bundle exec rake midburn:list --app midburn-queue
-
Reset queue:
heroku run bundle exec rake midburn:reset --app midburn-queue
-
Checking the heroku logs:
heroku logs -t --app midburn-queue
The MIT License (MIT)
See: LICENSE file.