sites
sites

Reputation: 21775

Periodic tasks with Delayed Job gem

class A < ActiveRecord::Base
  def self.a
    A.first.touch
    delay(run_at: Proc.new{ 10.seconds.from_now }).a
    log.info 'Added job to run at ' + 10.seconds.from_now.to_s
  end

  def self.log
    @log ||= Logger.new 'dj.log'
  end
end

Why do I see this in worker log:

Added job to run at 2013-04-26 01:04:53 UTC
Added job to run at 2013-04-26 01:04:53 UTC
Added job to run at 2013-04-26 01:04:54 UTC
Added job to run at 2013-04-26 01:04:54 UTC
Added job to run at 2013-04-26 01:04:55 UTC

NOTE: Not separated 10 seconds.

Upvotes: 3

Views: 1681

Answers (1)

cortex
cortex

Reputation: 5206

If what you want is to run recurring tasks, for example, each day. You can use rufus-scheduler:

rufus-scheduler is a Ruby gem for scheduling pieces of code (jobs)

Also there are some extensions for resque and sidekiq.

Hope it helps!

Upvotes: 3

Related Questions