does monthlyOn() works with between in laravel scheduler? - laravel

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");

Related

Power Automate Recurrence Trigger : how to find last 5 working days of the month?

I need to create a recurrence in Power Automate so that it only runs in the last 5 working days of the month. I can't use a generic rule because months like February are different.
What I have done so far was using a similar recurrence that finds the last working day of the month but need help with optimising it for the last 5 working days instead.
The logic is that the flow runs every day and looks at the first day of the next month, then comes backwards to find the first working day and excludes Monday-Sunday. however, I need it to find the last 5 working days instead of 1.
Also the functions used are like this:
startOfMonth(addToTime(variables('Date'),1,'Month'))
addDays(variables('DateCountDown'),-1)
dayOfWeek(variables('DateCountDown'))
#and(not(equals(variables('DayOfWeek'), 0)), not(equals(variables('DayOfWeek'), 6)))
addDays(variables('DateCountDown'), -1)
dayOfWeek(variables('DateCountDown'))
disclaimer: I am not a pro user of power automate and found this flow in an old GitHub repository (written by Michael Ziemba) - thanks all for your help.
in response to teylin:
I get today (as before)
I get first day of next month (as before)
I go 7 days down now > addDays(variables('DateCountDown'),-7)
I initialize a variable to find week day > dayOfWeek(variables('DateCountDown'))
then varCounter variable as you said (varCounter > integer > 1)
then DO UNTIL loop until varCounter = 7
inside the loop I have 3 conditions: day of week <> 0 , dayof week <> 6 and formatDateTime(variables('DateCountDown'), 'dd-MM-yyyy') = formatDateTime(variables('Date'), 'dd-MM-yyyy') (to check today)
then trigger my stuff if yes,
increment varCounter by 1
Don't overthink this. Conceptually:
Get the first day of the next month (you already know how to do this)
get DayX by subtracting 7 from that date (you already do this with 1, now do it with 7)
By definition, 2 of the seven days between that DayX and the next month will be on a weekend. So, next, you start a loop that runs 7 times. Inside the loop, you have these actions:
add a condition with the following two checks
check if DayX is a weekday (you already know how to do this) AND
check if DayX is = today
In the Yes branch of the condition run the steps that you want to run on the last 5 weekdays, in the No branch do nothing
below the condition step, increment DayX by one day
loop
For the loop, first initialise a counter variable to the value 1. Add a Do Until action and set it to run until the counter is greater than 7. Inside the loop, do your calculations and your condition etc. As the last step of the loop, increment the counter variable by 1.

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

Laravel Scheduler monthlayAt weekdays combination

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.

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.

Logic for tracking hours worked

I was wanting to write a program in C that I can simply type in the hours that I worked for each day of the week, including time on break, that will take my input and return the total number of hours I have worked for that week. It's dumb, I know, but I am not sure how to do the math for this regarding time on the clock.
Thank you
At beginning of work: get the current date, make it into seconds.
At end of work: get the current date, make it into seconds.
So working seconds = end seconds - beginning seconds
Then you'll just have to make those into hours.

Resources