Last active
December 10, 2015 18:38
-
-
Save trjordan/4475869 to your computer and use it in GitHub Desktop.
Tracing a set of Resque jobs.
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 | |
ctx = Oboe::Context.toString | |
Oboe::API.log_entry('job', { :Async => true }) | |
task_id = Oboe::Context.toString unless not Oboe::Context.isValid | |
Oboe::Context.fromString(ctx) | |
Resque.enqueue(Processdoc, task_id, *args) | |
end | |
# Worker one | |
class ProcessDoc | |
@queue = :file_serve | |
@task_name = :process_doc | |
def self.perform(xtrace, doc) | |
# Make sure to continue the task here | |
result, xtrace = Oboe::API.start_trace(@task_name, xtrace) do | |
# Do work here | |
doc.process | |
puts "did some work on", doc.name | |
end | |
# Relinquish control of current task, and pass ID to second worker | |
Resque.enqueue(Archive, xtrace, doc) | |
end | |
end | |
# Worker two | |
class ArchiveDoc | |
@queue = :file_serve | |
@task_name = :archive_doc | |
def self.perform(task_id, doc) | |
# Make sure to continue the task here | |
result, xtrace = Oboe::API.start_trace(@task_name, task_id) do | |
# Do work here | |
puts "did some more work, stored a file in S3" | |
end | |
# Finish the job, pushing back onto the context temporarily | |
Oboe::Context.fromString(xtrace) | |
Oboe::API.log_exit('job') | |
Oboe::Context.clear() | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment