Time-Driven Trigger to run every X minutes during a given time period? - timeout

I have a script that I have to run every 10 minutes but only during say 1AM - 2AM Local time.
Long story short; the script updates about 80+ internal Google Spreadsheets but it must only do this during the hours mentioned above so the chance of a user being in a spreadsheet doing work at the time is almost zero.
I've looked at the Time-Driven Triggers and it has both the functions (to run every 10 minutes and also to run between 1am-2am) however I need to fuse these two triggers together.
Is this possible?

Related

PC wakes up automatically only for a few minutes(I need more time)

I set up Jenkins to run some jobs(It runs 10 minutes) at night. In that time PC is already went sleep. Thats why i set up Task Scheduler:
Triggered every days. Actions cmd.exe/c"exit". This think wake up PC only for two minutes, but i need 10(and more in the future). Do you mind helping me solve this problem?

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

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

Run a Rails job at precise time (accurate to the second)

I'm making an application that needs to run a job at extremely precise intervals of time (say 30 seconds, maximum acceptable delay is +-1 second).
I'm currently doing so using an external Go application that polls an API endpoint built within my application.
Is there a way that I could run the task on a worker machine (eg a Heroku dyno) with delays less than one second?
I've investigated Sidekiq and delayed_job, but both have significant lag and therefore are unsuitable for my application.
Schedule the job for 60 seconds prior to when you need it run. Pass in the exact time you need the job executed, as a parameter. Then, run sleep until Time.now == exact_time_down_to_the_second?

Managing timezones for different users

I have a website where I have many users coming from different countries. Users can schedule a task based on their timezone. Now there is a cron running on the server after every min, the cron executes a script which checks if there are any scheduled task of any user and if so it does the needful.
Since my server is based in the US, the script executed by the cron considers the timezone of the US. What do I have to do in my script that will execute the user's task based on user's timezone instead of server's timezone?
Thanks in advance for any ideas
Lookup the user's timezone.
Compute the current time in the user's timezone.
For each job, look up the last time it was run and compute the next time it should run.
For any job whose next run time is now or in the past, run that job and update the record of the last time each job was run.
I did something similar on the iPhone a few months ago.
My solution was to capture the time as a string. So if the user selected 8am, I would just capture 08:00 and their time zone e.g. Europe/London.
Every 5 minutes or so on my server, I could then convert this 08:00 into the current UTC time based on the timezone. If this time was "present", I would carry about a check on the user's transport status and issue alerts.
To help me with the TimeZones, I used NodaTime. http://noda-time.blogspot.co.uk/

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