Last active

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Tracing a set of Resque jobs.

View gist:4475869
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
# 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
Something went wrong with that request. Please try again.