How to run a job on specific times every day from Monday to Friday in Rundeck? - job-scheduling

Is there any way to run the job every day from Monday to Friday at 45 mins time interval from 2.45 pm to 5 pm. (The job should run at 2.45pm , 3.30pm, 4.15, 5.00). Please help.
Thank you.

I know of two ways:
One way is to create four jobs scheduled at a single time every Mon-Fri. Give each a single step, which is a job reference to the real job. For example, the first job would be scheduled to run at 2.45pm every Mon-Fri, the second at 3.30pm, etc. You're not making copies of the existing job, just single-step jobs that reference the original.
That approach lets you manage each scheduled time individually.
Another way is to schedule it every 15 minutes from 2.00pm to 5.45pm, and add an initial step that fails if the time is before 2.45pm or after 5.01pm. If you don't want to see these failures, you could add an error step to that first step which marks the job succeeded even if it's really skipping all the real steps.
Paul M. Lambert
Platform Solutions Architect
Rundeck, Inc.

Related

Task scheduler to run tasks only during the last full workweek of the month

I have multiple tasks that need to be scheduled during the last full workweek (Monday through Friday) of every month. These will be scheduled from a Windows Server 2016 server. I cannot figure out the logic to do it.
Additional info to help:
July 2020 is a perfect month to just say run on the last Monday/Tuesday/etc. Most months will not end with a full workweek though. It may end on a Tuesday and the full workweek ended 4 days before that.
I have ideas of how to do this, but they are not fully formulated:
Find the last Friday of the month and start 4 days before that.
Find the last Monday with at least 4 additional days in the month after.
If the last day of the month is Sunday, start 6 days before that; Saturday, start 5 days before that; etc.
What is the cleanest method to do this in task scheduler? (The scripts being scheduled are in PowerShell, though I don’t think that matters).
So, your situation is: "I have a script, I have a complicated date schedule, and I would like my script to be launched according to that schedule.",
and your question is: "How to perform this scheduling in Windows task scheduler?"
My answer would be:
Don't do it like that, but write a new script which verifies the current date, and verifies if the current date corresponds to the complicate date schedule (in that case, launch your original script), and use Windows task scheduler to launch this new script on a daily basis.
As for making that new script, this URL explains how to perform date handling in Powershell.
This particular use case can actually be done fully in the Task Scheduler.
When adding a new trigger, select Monthly then for Months select <Select all months>. Then, change the radio button below it to Onand chooseLastand`.
May I suggest a solution:
In VBA write a very short Sub routine indicating the current date (using "Now() + 1".
Then use "instr(1,string1,""/"")" to see whether the second entry in the resulting date (such as "5/1/2022") is a "1". If it is, then you can issue a warning on a prepared Notepad.txt the day before the 1st of the month that also provides an answer to your question regarding scheduling an event on the 1st of every month. The routine is to run (in the background) every day until it reaches this particular occurrence.

Why are all of my Airflow dags one run behind?

I'm setting up Airflow right now and loving it, except for the fact that my dags are perpetually running behind. See the picture below - this was taken on 2/19 at 15:50 UTC, and you can see that for each of the dags, they should have run exactly one more time between the last time they ran and the present time (there are a couple for which this is not true - those ones are currently turned off). Is there some piece of configuration I missed?
False alarm! Airflow just labels execution times differently than how I expected. Turns out an hourly job that runs at 15:00 is labels "14:00" and includes data up to 14:00+1:00.
From https://airflow.apache.org/scheduler.html:
Note that if you run a DAG on a schedule_interval of one day, the run stamped 2016-01-01 will be trigger soon after 2016-01-01T23:59. In other words, the job instance is started once the period it covers has ended.
Let’s Repeat That The scheduler runs your job one schedule_interval AFTER the start date, at the END of the period.
Execution time is the lower bound of the batch.
Ex:
Say your execution schedule is hourly and its the run corresponding to the 13:00 schedule.
Your execution_time will be 12:00.
This is because we usually run the batch for 12:00 - 13:00 at 13:00(after the data is available for the batch).
But in my experience, we sometimes use the schedule based on the time its scheduled for(because we want the schedule to start and there are checks inside of the DAG/job that verify data readiness). In those cases, I just end up using next_execution_time(13:00) instead of execution_time(12:00).

Crontab on week numbers

I would like to set a cronjob on certain week numbers. The reason for that, I have a script that should run once a day except of week number 8 and 9. There it should run twice a day.
How can I set a cronjob based on week numbers?
Cron doesn't offer that level of scheduling flexibility, so you have to make your script smarter.
Make your cron job run twice a day, leaving some log file or other artifact that shows it has run. Then have it check whether it's already run that day, and finally also check the week number to see if it's OK for it to run the second time.

Testing Quartz JDBC Job Store

I am using Quartz JDBC Job store (org.quartz.impl.jdbcjobstore.JobStoreTX) and MySQL for scheduling jobs.
I have the following setup:
org.quartz.jobStore.class=org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.StdJDBCDelegate
org.quartz.jobStore.dataSource=foo
org.quartz.dataSource.foo.driver=com.mysql.jdbc.Driver
org.quartz.dataSource.foo.URL=jdbc:mysql://localhost:3306/myDB
org.quartz.dataSource.foo.user=user
org.quartz.dataSource.foo.password=*****
org.quartz.dataSource.foo.maxConnections=5
org.quartz.dataSource.foo.validateOnCheckout=true
org.quartz.dataSource.foo.validationQuery=SELECT 1
I am able to schedule a job with Quartz picking up the job from the database when the time is due.
There are some jobs that can be scheduled up to 3 or 4 weeks in the future. How do I test this?
Right now I go manually change the system time. For example, if I schedule a job to run on 2/5/2013 12:45 PM, then I go change the system clock time to 2/5/2013 12:43 PM, then wait for a couple of minutes to see if Quartz picks up the job from the DB. This works fine for me.
I don't want to change the system clock time every time I need to test. Is there a better way to do this?
I noticed that changing the system time frequently sometimes messes up with Quartz with some jobs not picked up.
You could use the Quartz TriggerUtils methods to find out whether the future executions are the expected.
More specifically the computeFireTimes(org.quartz.spi.OperableTrigger trigg, Calendar cal, int numTimes) method returns a list of Dates that are the next fire times of a Trigger.
I hope this helps.

How to run a per second cron job every two minutes

I have to set up a cron job on my hosting provider.
This cron job needs to run every second. It's not intensive, just doing a check.
The hosting provider however only allows cron jobs to be run every two minutes. (can't change hosting btw)
So, I'm clueless on how to go about this?
My thoughts so far:
If it can only run every two minutes, I need to make it run every second for two minutes. 1) How do I make my script run for two minutes executing a function every second?
But it's important that there are no interruptions. 2) I have to ensure that it runs smoothly and that it remains constantly active.
Maybe I can also try making it run forever, and run the cron job every two minutes checking whether it is running? 3) Is this possible?
My friend mentioned using multithreading to ensure it's running every second. 4) any comments on this?
Thanks for any advice. I'm using ZF.
Approach #3 is the standard solution. For instance you can have the cron job touch a file every time it runs. Then on startup you can check whether that file has been touched recently, and if it has then exit immediately. Else start running. (Other approaches include using file locking, or else writing the pid to a file and on startup check whether that pid exists and is the expected program.)
As for the one second timeout, I would suggest calling usleep at the end of your query, supplying the number of milliseconds from now to when you next want to run. If you do a regular sleep then you'll actually run less than once a second because sleeps sometimes last longer than expected, and your check takes time. As long as your check takes under a second to run, this should work fine.
I don't think cron allows second level resolution. http://unixhelp.ed.ac.uk/CGI/man-cgi?crontab+5
field allowed values
----- --------------
minute 0-59
hour 0-23
day of month 1-31
month 1-12 (or names, see below)
day of week 0-7 (0 or 7 is Sun, or use names)
So, even if your hosting provider allows you can't run a process that repeats every second. However, you can user command something like watch for repeated execution of your script. see here

Resources