0

I want to create a cron job in my rails application.

for example:

def job(message)
  send_message_to_someother_service(message)
end

This job will take input parameters and run against a cron expression. Now I will be sending requests to my rails app to add more cron expression, input parameters pair. (Lets say that these will be stored in DB)

for example:

[
  {cron: (0 0/1 * 1/1 * ? *), parameters: {message: "test1"}},
  {cron: (0 0/5 * 1/1 * ? *), parameters: {message: "test2"}
]

My job should run for all the cron expressions with corresponding input parameters.

Expected behaviour: The other service just prints the message it receives with the time stamp

[12:00:00]: test1
[12:00:00]: test2
[12:01:00]: test1
[12:02:00]: test1
[12:03:00]: test1
[12:04:00]: test1
[12:05:00]: test1
[12:05:00]: test2

Can anyone help me to acheive this?

Kaushik Vijayakumar
  • 755
  • 3
  • 10
  • 19
  • You tagged `sidekiq-cron`. If you're using `sidekiq` for running jobs, did you read the documentation from the `sidekiq` site? You might also want to look at [A cron job for rails best practices](https://stackoverflow.com/questions/285717/a-cron-job-for-rails-best-practices) – lurker Jun 18 '20 at 14:16
  • My project has already installed the `sidekiq-cron` gem(Thats why tagged it), but uses a `Sidekiq::Cron::Job.load_from_hash YAML.load_file(schedule_file)` and the schedule has hardcoded cron, class pair. I wanted to make it dynamic. – Kaushik Vijayakumar Jun 18 '20 at 15:43

0 Answers0