I a’m trying to rechedule job automatically. For example
On January 1st, an admin activates the monthly auto-wire at +15 days for client John
We schedule a job in sidekiq to run on January 31st + 15 days so the ~ February 15th
On February 15, sidekiq performs the job alone, without cron or intervention on our part, he sends the invoice
After sending the invoice, we re-schedule a job in sidekiq to run on February 31 + 15 days, so March 15
and so on
AutoWireJob.set(wait_until: (today.end_of_month + 15.days).to_time).perform_later(self.user.id.to_s)
class AutoWireJob < ActiveJob::Base
user = User.find(user_id)
# send the invoice
user = User.find(self.arguments.first)
client = user.client_profile
I expect to have recurring job but it executes only one time. What is wrong?
I did this on the go. Now that I have some time to explain it.
With the Time methods you can automate practically anything. I never liked Cron and never use it.
If Time.now.day == 31 && Time.now.hour == 23 && Time.now.min == 00 ;
Kernal.system “sudo apt-get update”
By creating a .rb file with all of your tasks like so, or even individual files for each task, you can start them automatically two ways.
.rc_local (this starts all scripts at boot level, or when the bootloader starts the computer)
.bash_rc (this starts all scripts at the user login level. Meaning the files won’t start until that user logs in)
Using .bash_rc is a easier route and can be found in the /home/$USER Folder. I recommend this for newer users. Also you don’t have to edit the .bash_rc file directly. You can create a new file in your user folder as .bash_elias to load all your scripts at.