Quartz.Net cron expression for immediate fire followed by 1 minute gap - quartz-scheduler

I need help on a proper cron expression that will fire the job immediately after it's launched, then reoccurring every minutes thereafter. So far I have
0 0/1 * 1/1 * ? *?
But that only fires at the minute mark (i.e. 3:31:00, 3:32:00). So if I launch the job at 3:45:54, I want it to execute right away, then the next fire would be at 3:46:54.
thanks.

You cannot do that with a cron expression but you can use SimpleScheduleBuilder using WithSimpleSchedule:
ITrigger trigger = TriggerBuilder
.Create()
.WithIdentity("trigger1", "gruppone")
.StartNow()
.WithSimpleSchedule(s => s.WithIntervalInMinutes(1).RepeatForever())
.Build();
and this would be the end result:
27/09/2015 12:28:28 +01:00
27/09/2015 12:29:28 +01:00
27/09/2015 12:30:28 +01:00
27/09/2015 12:31:28 +01:00
27/09/2015 12:32:28 +01:00
27/09/2015 12:33:28 +01:00

Related

Postgres with cron job doesn't work on get request

I am working on a cron job to return results for every minute.
select
cron.schedule(
'webhook-every-minutex', -- name of the cron job
'* * * * *', -- every minute
$$
select content::json->'results'
from http_get('https://swapi.dev/api/people');
$$
);
Unfortunately it doesn't return results but when I manully run the select query, it returns json results. (The code was tested on supabase)
My goal is to run the above cron job for every minute.
A test case:
SELECT cron.schedule('test', '* * * * *', $$SELECT 1$$);
schedule
----------
4
--Where 4 is job number
--In Postgres log
2022-03-14 11:18:00.001 PDT [63241] LOG: cron job 4 starting: SELECT 1
2022-03-14 11:18:00.007 PDT [63241] LOG: cron job 4 completed: 1 row
2022-03-14 11:19:00.002 PDT [63241] LOG: cron job 4 starting: SELECT 1
2022-03-14 11:19:00.008 PDT [63241] LOG: cron job 4 completed: 1 row
2022-03-14 11:20:00.002 PDT [63241] LOG: cron job 4 starting: SELECT 1
2022-03-14 11:20:00.010 PDT [63241] LOG: cron job 4 completed: 1 row
Nothing shows up in psql, which I assume is the console you are referring to.
So:
create table cron_test(fld_1 int, ts timestamptz default now());
SELECT cron.schedule('test', '* * * * *', $$insert into cron_test(fld_1) select 1$$);
schedule
----------
4
--Postgres log
2022-03-14 11:22:00.001 PDT [63241] LOG: cron job 4 starting: insert into cron_test(fld_1) select 1
2022-03-14 11:22:00.008 PDT [63241] LOG: cron job 4 COMMAND completed: INSERT 0 1 1
2022-03-14 11:23:00.002 PDT [63241] LOG: cron job 4 starting: insert into cron_test(fld_1) select 1
2022-03-14 11:23:00.012 PDT [63241] LOG: cron job 4 COMMAND completed: INSERT 0 1 1
2022-03-14 11:24:00.001 PDT [63241] LOG: cron job 4 starting: insert into cron_test(fld_1) select 1
2022-03-14 11:24:00.006 PDT [63241] LOG: cron job 4 COMMAND completed: INSERT 0 1 1
2022-03-14 11:25:00.003 PDT [63241] LOG: cron job 4 starting: insert into cron_test(fld_1) select 1
2022-03-14 11:25:00.010 PDT [63241] LOG: cron job 4 COMMAND completed: INSERT 0 1 1
select * from cron_test ;
fld_1 | ts
-------+-------------------------------
1 | 2022-03-14 11:22:00.007153-07
1 | 2022-03-14 11:23:00.010206-07
1 | 2022-03-14 11:24:00.004967-07
1 | 2022-03-14 11:25:00.008177-07
If you want to see the results of a command you will need to put them somewhere you can retrieve from. The issue being that pg_cron opens a separate libpq connection to run the job. This means you will not see the results in the console you started the job in.

Github Action won't allow cron starting in custom year period

The following cron expression:
0 3 1 5-5/3 *
“At 03:00 on day-of-month 1 in every 3rd month from May through May.”
Is not accepted by Github actions:
on:
schedule:
- cron: "0 3 1 5-5/3 *" ## Day 1, every 3rd month May-May
With the following output:
ERROR: String does not match the pattern of "^(((\d+,)+\d+|((\d+|\*)/\d+|((JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)(-(JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC))?))|(\d+-\d+)|\d+|\*|((MON|TUE|WED|THU|FRI|SAT|SUN)(-(MON|TUE|WED|THU|FRI|SAT|SUN))?)) ?){5}$".yaml-schema: GitHub Workflow
How is it possible to run a cron starting 1st of May, every 3 months, until the next May?
Your cron expression probably does not what you expect. The part 5-5/3 restricts the execution times to May only. This results in a job that will be run at 03:00 on the first day of every May:
2022-05-01 03:00:00
2023-05-01 03:00:00
2024-05-01 03:00:00
The regex that GitHub is using to verify the cron expression (according to the error message in your question) does not allow defining a range and step at the same time. This might be a bug as such expressions would usually be valid.
To fix this, you could list all months in the cron expression directly like 0 3 1 5,8,11,2 * which results in the following schedule:
2022-05-01 03:00:00
2022-08-01 03:00:00
2022-11-01 03:00:00
2023-02-01 03:00:00
2023-05-01 03:00:00
2023-08-01 03:00:00
2023-11-01 03:00:00
2024-02-01 03:00:00

crontab executing hour apart , both set to BST: 2 servers. Why?

I've just moved servers and have overlap on crontabs running.
Both servers set to BST, but one sends me a log at
08:00 BST the other old one 09:00 BST
The crontab entry for both is
0 9 * * * /root/phpmaillog.sh > /dev/null 2>&1
Mystery?

Why my cron job runs every 10 seconds?

Environment: Liferay 6.1
In my liferay-portlet.xml I have this cron job:
<scheduler-entry>
<scheduler-event-listener-class>com.shorex.b2b.web.billing.IndexJob</scheduler-event-listener-class>
<trigger>
<cron>
<cron-trigger-value>0 0 6 1/1 * ? *</cron-trigger-value>
</cron>
</trigger>
</scheduler-entry>
This expresion "0 0 6 1/1 * ? *" means that there is a process which will be execute once every day at 6:00:00.
The problem is that this process is been executed since 6:00:00 every 10 seconds. that is, at 6:00:00, 6:00:10, 6:00:20, 6:00:30...
Could anyone tell me why is it happening?
<cron-trigger-value>0 0 6 ? * *</cron-trigger-value>
thats every day at 6.

schtasks /change

I wan't to change the repeat time from one task from 5 minutes to 1 minute. The task is there:
Folder: \
HostName: ZSERVER
TaskName: \Check_IIS_Server
Next Run Time: 04.10.2012 16:30:45
Status: Ready
Logon Mode: Interactive/Background
Last Run Time: 04.10.2012 16:25:45
Last Result: 0
Author: WACKER\createuser
Task To Run: powershell.exe powershell.exe -Noninteract
ive -Command "&{C:\Logfiles_Poly\Check_IIS_Server.ps1}"
Start In: N/A
Comment: N/A
Scheduled Task State: Enabled
Idle Time: Disabled
Power Management: Stop On Battery Mode, No Start On Batteries
Run As User: WACKER\Adminuser
Delete Task If Not Rescheduled: Enabled
Stop Task If Runs X Hours and X Mins: 01:00:00
Schedule: Scheduling data is not available in this format.
Schedule Type: Daily
Start Time: N/A
Start Date: N/A
End Date: N/A
Days: Every 1 day(s)
Months: N/A
Repeat: Every: 0 Hour(s), 5 Minute(s)
Repeat: Until: Time: None
Repeat: Until: Duration: 24 Hour(s), 0 Minute(s)
Repeat: Stop If Still Running: Disabled
Now my change command is, i wan't to edit the repeat time to one minute:
C:\Users\username>schtasks /change /tn "Check_IIS_Server_Poly" /ri 1
ERROR: The parameter is incorrect.
Why did I can't edit this job over command?
Thanks,
Horst
You need to provide full path to the task, in your case it'll be \Check_IIS_Server. I don't see anything else that could be wrong here.
I create a task (schtasks /change /mo 1 /tn "Test") with repeat time one minute and edit the other settings manuell.
Horst