How to run pg_cron job as per local time? - cron

Currently pg_cron works as per UTC/ GMT time only. There is no configuration option available to run job as per local time server time. How to run pg_cron job as per local time?

When you define cronjob with pg_cron you can set first the timezone
SELECT cron.schedule('manual vacuum', '0 22 * * *', 'SET LOCAL TIME ZONE \'Europe/Rome\'; VACUUM FREEZE pgbench_accounts');

Related

Gitlab backups - multiple per day

We have used a working once per day at 2am backup via crontab for gitlab. A project to make the whole backup/restore process more automated was embarked upon and we're mostly there. The one issue we keep running into is that omnibus updates are fairly frequent as of late, and because the backup then auto-upgrade is staggered, our backups are 24 hours behind, and as such, we get version mis-match errors when restoring on a day immediately following an upgrade.
The more complicated solution is build in a version check to our backup/restore script and postpone 24 hours but that doesn't seem ideal without adding more complexity to both monitor how long the job is postponed compared to the set schedule once per week or every second saturday of the month for tests.
The simpler solution I thought would be the best route was to simply increase the gitlab backup frequency and utilize the STRATEGY=copy option detailed here. That said, after changing the cron to reflect a once every 6 hours backup schedule, I'm not seeing any actual increase in backup count.
Is there a limitation in gitlab in regards to how frequently a backup can be run?
Old Cron (once per day at 2am):
- 0 2 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create CRON=1 && /root/datadog_success_push.sh
New Cron (that isn't working as expected - “At minute 30 past every 6th hour from 0 through 23.”)
- 30 0/6 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create STRATEGY=copy CRON=1 && /root/datadog_success_push.sh

Cron Schedule for a job that runs every minute from 8 am to 7:30 pm

I can't figure out how to create a job that ends at a specific hour and minute
If you break your cronjob into two, it would look like:
* 8-19 * * * command
0-30/1 19 * * * command
first line runs every minute from 8-19, and second line every minute from 19-19:30.
Cron triggers are not quite suitable for these types of schedules. If you do not insist on using a Cron trigger, I recommend that you check the Daily Time Interval trigger that is designed for use-cases such as yours. I am attaching a screenshot of a Daily Time Interval Trigger configuration for your use-case.

Can you programmatically switch serverless cron functions on/off

Scenario:
I want function A to run every minute, but not 24/7. More like 5-10 hours per week. However, a simple cron outlining these times will not do here because the 5-10 hours per week are dynamic and keep changing.
Function B will run e.g. every 30 minutes and determine whether Function A should be running or not. If so, it will switch it 'on', if not, it will switch it 'off'
Is this doable using Serverless.com (or any of the FAAS providers it uses)?
Thanks in advance!
Solution #1: Use s3 to save switch state
You can have the second function write to a file on S3 the state of the switch (ON or OFF).
Schedule the first function to run every min. But make sure it checks the content of the "switch file" from S3 before it starts executing it's logic.
Cost
It won't cost you a lot because: 60 times an hour * 24 hours a day * 31 days a month = 44,640 calls / month. If it would take an extra 100ms to read the flag and you've set the memory to 1GB then this will translate to 44,640 * (0.00001667 GB-SECOND / 10 -100ms per second-) = $0.07441488 / month.
In addition to 44,640 S3 GET request (0.001 per 1,000 requests) = 44,640 * (0.001 / 1000) = $0.04464 / month.
Solution #2: Control the cron of func1 from func2
In function 2, using the AWS CloudWatchEvents API you can create/update the rule's ScheduleExpression (e.g. "cron(* * * * * *)") that that triggers function 1. Read more here

Azure function CRON Schedule expression

If I wish to run my function app at 11.15 PM to next day 1.15 AM(That mean MONDAY 11.15 PM start and TUESDAY 1.15 AM will end) and it will trigger every minute during this time.
Can anyone help me to write this CRON expression?
The timer triggers are designed for a single repeating interval. The only way to do this completely within a Function is to run the trigger once per minute, then abort if the current time isn't in the desired target time period.
Alternately, put your logic into an HTTP trigger configured to act as a webhook, then use an Azure scheduler to configure start and stop times and intervals.
You won't be able to use the scheduler free plan since it can only run once per hour, but the standard plan can run once per minute. Scheduler pricing here.
You'll have to do this in three lines I think,
15-59 23 * * *
* 0 * * *
0-15 1 * * *
This will run it from 23:15-23:59 then 00:00-00:59 then 1:00-1:15

node js scheduler it definite time with agenda

I am trying to create scheduler with a help of agenda module. I want to do something simple: to run some job every 30 min. For this one I can use agenda.every('30 minutes', 'my task') function. But how can I tell to agenda to do it exactly in 00 or in 30 minutes of every hour? Since I use for deployment heroku that reboots dynos from time to time I can't be sure that heroku won't move my scheduler from 30 minutes to 45 for example.
You can use cron package from npm also - https://www.npmjs.com/package/cron.
It supports cron syntax. As a result you can write schedules like 0,30 * * * * *.

Resources