amitree / delayed_job_recurring

Extends delayed_job to support recurring jobs
MIT License
84 stars 33 forks source link

Job is not recurring #14

Closed ghost closed 6 years ago

ghost commented 7 years ago

I've defined a job along the lines of:

class HealthCheckTask
  include Delayed::RecurringJob

  run_every 5.minutes
  ...

And schedule it with:

HealthCheckTask.schedule!

But it only executes once. Any suggestions as to why?

jonaizen commented 7 years ago

Try inheriting instead of including.

ghost commented 7 years ago

Thanks Jonathon, I'll give it a try. Is this dependent on ActiveJob version?

On 27 Oct 2016 9:32 pm, "Jonathan Aizen" notifications@github.com wrote:

Try inheriting instead of including.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/amitree/delayed_job_recurring/issues/14#issuecomment-256627878, or mute the thread https://github.com/notifications/unsubscribe-auth/AAKVYUadnpL6VIyR0DlBIB02CSJurHD0ks5q4JnJgaJpZM4KiGgR .

jonaizen commented 7 years ago

Now that I look at our code, I see we do it like this:

module Recurring
  class SomeClass
    include Delayed::RecurringJob

So including is the right way to go. I'm not sure why it is only executing once for you. After it executes, do you see the newly created Delayed::Job in your database or not?

ghost commented 7 years ago

When I schedule it the first time I see it, but after it executes one it doesn't seem to reschedule itself (doesn't appear in the table again).

On 28 Oct 2016 7:10 am, "Jonathan Aizen" notifications@github.com wrote:

Now that I look at our code, I see we do it like this:

module Recurring class SomeClass include Delayed::RecurringJob

So including is the right way to go. I'm not sure why it is only executing once for you. After it executes, do you see the newly created Delayed::Job in your database or not?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/amitree/delayed_job_recurring/issues/14#issuecomment-256784412, or mute the thread https://github.com/notifications/unsubscribe-auth/AAKVYfZFLe_sOb-vY_UJE8GMelOVxbCrks5q4SFAgaJpZM4KiGgR .

derrelldurrett commented 7 years ago

I'm possibly experiencing this issue.

As an update to the information above, If I execute rails restart it does not update the schedule of the jobs.

afn commented 7 years ago

Can you try with the latest version of the gem? (0.3.6)

If you're still having issues, what version of delayed_job and delayed_job_active_record are you using?

derrelldurrett commented 7 years ago

After a lot of work in the meantime (unsurprising, given the amount of time passed), I think I have a different issue.

FWIW, I'm currently using 0.3.6.

rdemuth commented 6 years ago

I'm having exactly this issue. i have a class like the following:

class `NightlyBatchJobs`
    include Delayed::RecurringJob
    run_every 1.day
    run_at '03:30pm'
    timezone 'US/Pacific'
    queue 'nightly'
    def perform
...
    end

I have a rake task (as suggested) that I run at deployment time to schedule the jobs. A record gets put in the delayed_jobs table, and the job executes once. But afterwards, there is no longer a record in the table and the job does not execute again. I was using 0.3.5, but just upgraded to 0.3.6. delayed_job 4.1.1 and delayed_job_active_record 4.1.0. Here's what the handler in the db looks like: --- !ruby/object:NightlyBatchJobs schedule_options: :run_at:

(that's with the parameters updated to an every 5 minutes run of the job so I could try to figure out what is going on).

afn commented 6 years ago

Let me see if I can reproduce this issue. Can you share your entire NightlyBatchJobs class? (Or better yet, replace the body of the perform method with something simple, like puts "hello", and confirm that it's still failing to reschedule the job)

rdemuth commented 6 years ago

Thanks for responding. I had already commented out nearly all the functionality in the class.  It looked like this:

class NightlyBatchJobs include Delayed::RecurringJob run_every 1.day run_at '03:30pm' timezone 'US/Pacific' queue 'nightly' def perform d = ApplicationHelper.get_market_date(Date.today) return if d != Date.today()

Commented out stuff

end

def success(job) logger.info 'Successfully completed nightly job' end

def error(job, exception) logger.info "Nightly job error: #{exception}" end

def failure(job) logger.info 'Nightly job failure' end endThe success method ran the one time.

On Monday, October 30, 2017, 12:50:45 PM PDT, Tony Novak <notifications@github.com> wrote:  

Let me see if I can reproduce this issue. Can you share your entire NightlyBatchJobs class? (Or better yet, replace the body of the perform method with something simple, like puts "hello", and confirm that it's still failing to reschedule the job)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

afn commented 6 years ago

Ah, I see what's happening. Delayed::RecurringJob reschedules itself in the success and failure methods, so overriding these methods prevents rescheduling.

There may be a better way to handle this, but for now, if you define success or failure, you'll need to call super.

rdemuth commented 6 years ago

Well, that at least makes sense. 

On Tuesday, October 31, 2017, 5:05:20 AM PDT, Tony Novak <notifications@github.com> wrote:  

Ah, I see what's happening. Delayed::RecurringJob reschedules itself in the success and failure methods, so overriding these methods prevents rescheduling.

There may be a better way to handle this, but for now, if you define success or failure, you'll need to call super.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.