Skip to content

Instantly share code, notes, and snippets.

@trjordan
Last active December 10, 2015 18:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save trjordan/4475869 to your computer and use it in GitHub Desktop.
Save trjordan/4475869 to your computer and use it in GitHub Desktop.
Tracing a set of Resque jobs.
# 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