Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Reschedule a recurrent job? #36

Open
srehne opened this issue Mar 9, 2023 · 0 comments
Open

Question: Reschedule a recurrent job? #36

srehne opened this issue Mar 9, 2023 · 0 comments

Comments

@srehne
Copy link

srehne commented Mar 9, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant