Skip to content

Question: Reschedule a recurrent job? #36

Open
@srehne

Description

@srehne

Hi. Sorry for trying to get help to the gem in here.

I am trying to make the recurrent timing (run_every and run_at) dependant on a variable.
I have my sample code here:

class RecurringSyncDataJob
    include Delayed::RecurringJob
    run_every Setting.value_of('ad_sync_data_delay_min').to_i.minutes
    run_at Time.now + Setting.value_of('ad_sync_data_delay_min').to_i.minutes
    timezone 'Europe/Copenhagen'
    queue 'low'
    def perform
	# DO THE STUFF I NEED DONE
      new_delay = Setting.value_of('ad_sync_data_delay_min').to_i.minutes
      new_time = Time.now + new_delay
      puts "new_delay: #{new_delay.to_s}, new_time: #{new_time.to_s}"
      schedule!(run_at: new_time, run_every: new_delay)
  end
end

So using the schedule command I hoped that I could change the current jobs run_at and run_every values dynamically.
But this does not seem to work.
The "puts" gives the right values - but the schedule does not update the times inside the Delayed::Job.

Has anyone an idea on how to solve this?

Kind regards
Søren

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions