1

I want to create a delayed job which will run after one year interval continuously? That is at particular date on every year. How can i achieve this using delayed job?

Paulo Fidalgo
  • 21,709
  • 7
  • 99
  • 115
Kavitha Velayutham
  • 663
  • 1
  • 9
  • 27

3 Answers3

1

Use whenever gem. Here is good screenacast

Grosefaid
  • 138
  • 1
  • 7
  • 1
    I agree with @grosefaid. You don't want to use Delayed Job for this. Use a gem like `whenever`, which is a nice ruby abstraction for `cron`. – Daiku Aug 25 '14 at 13:28
0

Use delay-jobs gem, so you can add time of running as params as the following:

Notifier.delay(run_at: 1.years.from_now).signup(@user)

See RailsCasts for delay-jobs

For run this code as daily tasks, you need to read Resque gem, resque-scheduler gem, and see helpful question

Community
  • 1
  • 1
Mohamed Yakout
  • 2,868
  • 1
  • 25
  • 45
0

Personally I like rufus-scheduler. From the documentation you'll have a lot of ways to schedule your tasks:

require 'rufus-scheduler'

scheduler = Rufus::Scheduler.new

# ...

scheduler.in '10d' do
  # do something in 10 days
end

scheduler.at '2030/12/12 23:30:00' do
  # do something at a given point in time
end

scheduler.every '3h' do
  # do something every 3 hours
end

scheduler.cron '5 0 * * *' do
  # do something every day, five minutes after midnight
  # (see "man 5 crontab" in your terminal)
end

Also, be aware that if you kill you application, it will loose the schedule, so it's advised to save the information on database and retrieve it on startup.

Paulo Fidalgo
  • 21,709
  • 7
  • 99
  • 115