Skip to content

Instantly share code, notes, and snippets.

@pglombardo
Forked from trjordan/gist:4475869
Last active December 10, 2015 20:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pglombardo/4486693 to your computer and use it in GitHub Desktop.
Save pglombardo/4486693 to your computer and use it in GitHub Desktop.
# 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