plashchynski / crono

A time-based background job scheduler daemon (just like Cron) for Rails
https://github.com/plashchynski/crono
Apache License 2.0
687 stars 56 forks source link

Crono runs the task just the first time #45

Closed vandamon closed 8 years ago

vandamon commented 8 years ago

This is an awesome gem, if only it can do what it says.

Crono runs my tasks, but just once, for the first time.

My cronotab looks like this:

require 'rake'
Quadra::Application.load_tasks

class InvoiceUpsert
  def perform
    Rake::Task['invoice:batch_upsert'].invoke
  end
end

class PaymentUpsert
  def perform
    Rake::Task['payment:batch_upsert'].invoke
  end
end

Crono.perform(PaymentUpsert).every 1.day, at: { hour: 02, min: 15 }
Crono.perform(InvoiceUpsert).every 15.minutes

Any suggestions? Or is this a bug?

Blacksmoke16 commented 8 years ago

+1

klausmeyer commented 8 years ago

Try using Rake::Task#execute instead of Rake::Task#invoke.

Background: Invoke only runs the task "if needed". Since crono doesn't boot a fresh instance of your application per job execution (like regular cronjobs would do) the task is considered als already executed after the first run if you use invoke.

vandamon commented 8 years ago

@klausmeyer Thanks a lot for the suggestion. I have it working now.