Laravel Scheduler monthlayAt weekdays combination - laravel

I'm quite new to the Laravel Scheduler. Currently there's an email sent out every 1st day of the month like this:
$schedule->job(new SendMonthlyUpdate)
->monthlyOn(1, '9:00')
->timezone('Europe/Amsterdam');
How would I change this if I want to always send it on the 1st day of the month, EXCEPT from weekends? In case the 1st (or 2nd) day is in a weekend, it should be triggered on Monday after the weekend.
I was considering something like this:
$schedule->job(new SendMonthlyUpdate)
->monthlyOn(1, '9:00')
->weekdays()
->timezone('Europe/Amsterdam');
But I'm not sure if:
A. This will entirely skip this job if the 1st day is in the weekend, rather than sending it later?
B. How to test this
Any help would be appreciated!

It's even simpler than that:
$schedule->job(new SendMonthlyUpdate)
->monthly()
->weekdays();
Should do the job once per month as soon as it's a weekday.
In order to test it you will have to change the date of your system.

Related

does monthlyOn() works with between in laravel scheduler?

I have made a custom command and want it to run on month last day at 02:00 but I also want it to run after that between some period of time like 02:00 till 15:00 following is my scheduler
`$schedule->command('billing:generate')
->monthlyOn(Carbon::now()->endOfMonth()->subHours(5)->format("d"), "02:00");`
now what I think Ill do to achieve this is like this:
$schedule->command('billing:generate')
->monthlyOn(Carbon::now()->endOfMonth()->subHours(5)->format("d"), "02:00")
->between("02:00", "15:00");
will it work as I want? I am on laravel version 6.
As you are on Laravel 6, you can schedule your command to run every day, but just check is that day the last day of the month, something like this:
// Runs exactly on "02:00" every month on its last day.
// (Actually runs every day, but doesn't execute if the day is not the last day of the month).
$schedule->command('billing:generate')->dailyAt('02:00')->when(function () {
return Carbon::now()->endOfMonth()->isToday();
});
// Runs between "02:00" and "15:00" every month on its last day.
// (Actually runs every day, but doesn't execute if the day is not the last day of the month).
$schedule->command('billing:generate')->daily()->between("02:00", "15:00")->when(function () {
return Carbon::now()->endOfMonth()->isToday();
});
If you are on newer versions of Laravel you can use lastDayOfMonth to which you can provide a time, and if needed, you can also chain between on it.
Also, to achieve what you want, you can specify 2 schedules and resolve the problem.
It should be like this:
// Runs exactly on "02:00" every month on its last day.
$schedule->command('billing:generate')->lastDayOfMonth("02:00");
// Runs between "02:00" and "15:00" every month on its last day.
$schedule->command('billing:generate')->lastDayOfMonth()->between("02:00", "15:00");

How to do a every 3 months cron job in laravel?

I am using laravel to schedule a job to run every 3 months at 2am, so I created:
$schedule->command('clean:market-history')->cron( '0 0 0,2 ? 1/3 * *');
But according to my research (by using: this reference) this indicates it will run every 3 months starting in January at 2 am. I got most of it right, I do want it to run every three months at 2 am, but if it starts in January does that not mean if I deploy in august, for example, that it wont start running till January?
Some resources stated to use: */3 how ever, the site, linked above, states the same, starting in January at 2 am.
Is this correct or am I missing something? Can some one explain?
If you want to run your command quarterly (First day of Jan, April, July, October) you can use Laravel's pre-canned quarterly function:
$schedule->command('YourCommandHere')->quarterly('02:00')->timezone('America/New_York');
If you want to run this command every three months starting from time of implementation (ie every 3 months starting now) you can use Laravel's cron function that lets you pass a custom cron line and that cron line would look like this:
$schedule->command('YourCommandHere')->cron('0 2 * */3 *')->timezone('America/New_York');
You can configure any iteration of laravel's cron function. Just use the crontab.guru reference I shared below. It's a lifesaver. Also, don't forgot to define timezone as I do if you intend on using a different timezone than what the server is set to.
To get all of the Laravel schedule features review this documentation: https://laravel.com/docs/8.x/scheduling
My most frequently used url to identify what my cron line should look like: https://crontab.guru

What is "INTERVAL=0" means in Oracle Schedular?

My Oracle DBA have setup a task with following repeat_interval:
Start Date :"30/JAN/20 08:00AM"
Repeat_interval: "FREQ=DAILY; INTERVAL=0; BYMINUTE=15"
Can I ask what is "Interval=0" means?
Does it means this task will run daily from 8AM, and will repeat every 15 mins until success?
I tried to get the answer from Google, but what I find is what is Interval=1, but nothing for 0.
So would be great if anyone can share me some light here.
Thanks in advance!
INTERVAL is the number of increments of the FREQ value between executions. I believe in this case that a value of 0 or 1 would be the same. The schedule as shown would execute once per day (FREQ=DAILY), at approximately 15 minutes past a random hour (BYMINUTE=15, but BYHOUR and BYSECOND are not set).
Schedule has nothing to do with whether or not the previous execution succeeded or not. Start Date is only the date at which the job was enabled, not when it actually starts processing.
If you want it to run every 15 minutes from the moment you enable it, you should set as follows:
FREQ=MINUTELY; INTERVAL=15
If you want it to run exactly on the quarter hour, then this:
FREQ=MINUTELY; BYMINUTE=0,15,30,45; BYSECOND=0
If you want it to run every day at 8am, then this:
FREQ=DAILY; BYHOUR=8; BYMINUTE=0; BYSECOND=0

Run a job every other monday

I would like to use Heroku scheduler to run every OTHER Monday. However, it only runs hourly, daily, every 10 minutes.
I read this...
How can I schedule a 'weekly' job on Heroku?
However, I'm not sure what code can be used. I think I can figure out every Monday, but not every OTHER Monday.
thanks
As you get more complicated, I'd recommend checking out scheduling gems. If you want to stick to vanilla Ruby, look at a combination of monday? and cweek, which tells you the week number in the current year. Run your job on Mondays in even-numbered weeks.
date = Date.today
date.monday? && date.cweek.even?
Note that cweek can return 53, since 365 isn't divisible by 7 and it has to handle that last, partial week. The new year's first week will be 1 (it doesn't count from 0), so you have to either skip a week or do two runs in a row when Monday falls in week 53.

Scheduling a task to run at the end of every month. (Windows Server 2003 - Scheduled Tasks)

I need to schedule a task to run on the last night of each month, on a Windows 2003 Server.
I see that you can schedule it to run on the "first or last Mon-Fri", or even on the nth day of each month - but, not how to get it to run on the last day (regardless of day of the week or number).
Thanks in advance.
Note: I did check "How do you schedule tasks in Windows?", etc...
Looks like you have to set up multiple schedules for your task. One schedule for the months with 31 days, another for those with 30, and one more for February. See this: http://support.microsoft.com/kb/936627
I do it a little differently - I run one task every day but since the task is in vbscript - I do this:
DIM datecur, datefut
datecur = DATEPART("m",NOW())
datefut = DATEPART("m",NOW()+1)
If (datecur <> datefut) then
'insert code you want to run here
end if
Simple and it works - hope this helps someone
As of November 2022, much newer Windows version (2019)
I see this option in Triggers:
WinScheduler Task Triggers
Begin the task: On a schedule
Settings:
Monthly
On: Last > then select All weekdays

Resources