Skip to content
Mike Perham edited this page Oct 14, 2021 · 4 revisions

Faktory Enterprise can automatically expire jobs which have passed a preset time. Expiring jobs are very useful for actions which aren't useful after some time: things like cache invalidation, creating time-sensitive reports, etc.

You provide an expiration time in the job's custom data:

require 'time'
one_hour_from_now = (Time.now + 3600).utc

job = {
  'jobtype' => 'SomeJob', 
  'args' => [1,2,3],
  'custom' => { 'expires_at' => one_hour_from_now.iso8601 } # "2018-10-10T21:19:35Z"
}
client = Faktory::Client.new
client.push(job)

In v1.5.5+, you can also provide a relative time in seconds using expires_in. Assume you want to issue a cron job every minute BUT you don't want duplicates. Just configure it to expire in 60 seconds:

[[cron]]
  schedule = "* * * * *"
  [cron.job]
    type = "MinutelyJob"
    queue = "critical"
    [cron.job.custom]
      expires_in = 60

Faktory will log a message when it expires a job; this is so jobs don't just "disappear" and there is a record of their expiration.

D 2018-10-08T21:24:05.846Z JID 3374020d83e39c34: Halt: job expired

Jobs are expired when a worker fetches a job from the queue; they will accumulate in queue if no workers are fetching jobs from that queue.

Clone this wiki locally