Want to schedule a task on every 2 hours from 8am to 12pm on heroku through scheduler add on - ruby-on-rails

I want to create a task that run on every 2 hours from morning 8 to midnight. I have created task and tested locally , when i made a job through scheduler it just gives me three times daily , hourly and every 10 min. How can i customize it.

You'll have to upgrade the Heroku Scheduler Add-On to make more precise settings. With the free dyno you can only choose between these 3.
The only way to achieve this would make these cron jobs from the framework itself. With a gem like https://github.com/jmettraux/rufus-scheduler

Related

how to call sidekiq worker every times with certain duration of time between calls?

So I have a worker. I want him to start every 2 weeks to clean some data. How can I do this? I know about perform_in and perform_at but this is not what I need.
Scheduled, recurring jobs are not part of the core Sidekiq functionality. You can either upgrade to Sidekiq Pro, which includes support for scheduled jobs, or use an open-source scheduling plugin like sidekiq-scheduler.
With the latter, to run your job every two weeks, you'd use a config like:
your_job_name_here:
every: 2w
class: YourWorker
queue: default
description: "Runs every two weeks"

User faced scheduler for rails

I need to implement user faced scheduler, like users have reports and might choose schedule when they want those reports being sent to them.
Requirements are quote complex, like there should be schedules like each 12 hours, each 30 minutes, each second day, at Fridays at 1am, last Sunday of the months etc.
Is there Rails solution for that our should I create it from the ground?
Thanks!
Most schedulers for rails and ruby depend on a static file. You can use a queuing system like Delayed Job and make every job enqueue itself for next time after success. Or you can do a basic SheduledJob model which relates to the user, and stores the periodicity, next execution and last execution. And use a normal (frequent) scheduled task engine like clockwork to check for pending jobs.

How do I implement something like cron job on Heroku?

I know about Heroku Scheduler addon but is it very flexible like I want to be able run a task on the 1st and 15th of every month as well as at daily intervals.
What else can I use or is Scheduler the best option for Heroku?
According to my knowledge Scheduler is the best option. It is good and reliable go for it.
If you lowest frequency of running a task is it daily then config scheduler to run daily and then in the code that it runs check the day of the month and perform your desired tasks whether it be day 1, day 15 or day x.
If that doesn't suit then you'd need to look at one of the background processors like Sidekiq, DelayedJob etc that allowed scheduled jobs and then have your jobs requeue themselves at whatever frequency you want but you'll need to be running a worker for this to work in a similar fashion to scheduler.

Fortnightly task on Heroku scheduler

I have the Heroku Scheduler add-on set up and I came across techniques for running a task weekly. However, I need a task that runs every other week, but I can't think of any elegant/simple way to do this.
How about setting it to run weekly on Heroku, but then in your actual task make the first step be to check if the task was already run last week, and if so abort. This would also involve storing the current date every time the task is successfully run.

If Heroku runs cron daily, do we still need 'if time.now.hour...`?

I'm trying to figure out how Heroku daily cron works, specifically in this way:
As per Heroku's own cron docs, cron tasks are often written like this:
if Time.now.hour == 0 # run at midnight
User.send_reminders
end
Well, what happens if I set up cron at a time other than midnight? At least from my debugging, it seems that whenever Heroku cron runs (nearly always not at midnight), the above section of code is simply ignored.
Is it good practice to eliminate the time element from cron.rake and have the simple statement User.send_reminders, to be executed whenever that document is run?
The Heroku FAQ says this:
Cron jobs execute based on when you
enable the add-on. If you enable the
hourly add-on at 9:35 in the morning,
for instance, the cron job will run at
35 minutes past the hour every hour;
if you enabled the daily add-on at the
same time, it would run every day at
9:35.
I believe this is how my daily cron jobs run, although I didn't pay too much attention to that. I don't have any time checks in my daily cron task.
The time check in the Heroku example would be useful when using hourly cron, but not when using daily.

Resources