Module: Faktory::Trackable
- Included in:
- Job
- Defined in:
- lib/faktory/tracking.rb
Instance Method Summary collapse
-
#track_progress(percent, desc = nil, reserve_until: nil) ⇒ Object
Tracking allows a long-running Faktory job to report its progress:.
Instance Method Details
#track_progress(percent, desc = nil, reserve_until: nil) ⇒ Object
Tracking allows a long-running Faktory job to report its progress:
def perform(...)
track_progress(10, "Calculating values")
# do some work
track_progress(20, "Sending emails")
# do some more work
track_progress(20, "Sending emails", reserve_until: 10.minutes.from_now)
# do some more work
end
Note:
-
jobs should be small and fine-grained (and so fast) if possible.
-
tracking is useful for long-running jobs, tracking a fast job will only add overhead
-
tracking only works with a single job, use Batches to monitor a group of jobs
-
reserve_until allows a job to dynamically extend its reservation so it is not garbage collected by Faktory while running
-
you can only reserve up to 24 hours.
25 26 27 28 29 |
# File 'lib/faktory/tracking.rb', line 25 def track_progress(percent, desc=nil, reserve_until:nil) hash = { 'jid' => jid, 'percent' => percent.to_i, 'desc' => desc } hash["reserve_until"] = convert(reserve_until) if reserve_until Faktory.server {|c| c.set_track(hash) } end |