-
-
Save pglombardo/4486693 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
# In the web request | |
def start_job(*args) | |
# Log the fact that we're starting a job, and send the job with the current | |
# task id | |
Oboe::API.force_trace do | |
Oboe::API.start_trace('job', nil, { :Async => True }) do | |
task_id = Oboe::Context.toString unless not Oboe::Context.isValid | |
Resque.enqueue(Archive, task_id, *args) | |
end | |
end | |
end | |
# Worker one | |
class Archive | |
@queue = :file_serve | |
def self.perform(task_id, arg1) | |
Oboe::Context.fromString(task_id) | |
# Make sure to continue the task here | |
Oboe::API.trace(@queue, { :task_id => task_id}) do | |
# Do work here | |
puts "did some work", arg1 | |
arg2 = 'arg2' | |
end | |
xtrace = Oboe::Context.toString | |
# Relinquish control of current task, and pass ID to second worker | |
Resque.enqueue(Process, xtrace, arg2) | |
end | |
end | |
# Worker two | |
class Process | |
@queue = :file_serve | |
def self.perform(task_id, arg2) | |
Oboe::Context.fromString(task_id) | |
# Make sure to continue the task here | |
Oboe::API.trace(@queue, { :task_id => task_id }) do | |
# Do work here | |
puts "did some more work, stored a file in S3" | |
end | |
xtrace = Oboe::Context.toString | |
# Finish the job, pushing back onto the context temporarily | |
Oboe::Context.fromString(xtrace) | |
end | |
end | |
# Helpers | |
def finish_job | |
Oboe::Context.createEvent | |
end | |
def current_task_id() | |
Oboe::Context.isValid and Oboe::Context.toString | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment