I'm trying to set a biweekly Cron job for a small Slack bot that I run at work off of App Engine. I previously had set it up in App Engine using the custom interval from the documentation to run every other week:
schedule: 1st,third Wednesday 10:00
I was waiting for the Slack bot to message today and it never came. Now the obvious solution is that I missed the 5th Wednesday of the month in my original scheduling statement. The problem here is that next week we will also get a message because it will again be the 1st Wednesday of the month. Is there a way to get the job to run as
schedule: every two Wednesday 10:00
or similar so that the job will run every two weeks?
In the documentation about formatting the schedule you can see under the "Custom Interval" tab what syntax options you have.
Given that you can specify days up to the 31st, I believe adding 5th to the expression you are using would fix the issue with "fifth" Wednesday:
schedule: 1st, 3rd, 5th Wednesday of month 10:00
If you don't mind the week day that you receive the update, you can also just set it to run every 14 days for simplicity:
schedule: 1, 14, 28 of month 10:00
Related
Background: where I park my car, during the winter it is cleaning day once a week (=parking is not allowed) so I have to move the car before that to avoid getting a ticket. I want to create an iCal reminder about that but the pattern is very complicated.
The season starts Nov 1 and ends May 15.
Only weekdays are cleaning nights.
There are two repeating patterns, yearly (Nov to May) and every 4/6 days (see the examples below for details)
Examples:
I am parked on a street where Wednesday is the cleaning day (i.e., "Wednesday street") so Tuesday evening I move the car to a street that just was cleaned (i.e., a "Tuesday street"). Every week the day I have to move the car is moved forward one day. The repeating pattern is "every 6th day".
However, if I have parked on a Monday street, the situation is different - then I want to move the car on the Friday, not the Sunday. Suddenly the repeating pattern is "every 4th day".
I have read this question Can iCal schedule an event for the first weekday after BYMONTHDAY if BYMONTHDAY is a weekend? and have figured out a couple things:
I can set BYMONTH=11,12,1,2,3,4,5 to limit it to Nov to May.
BYDAY=MO,TU,WE,TH,FR limits it to weekdays
but after that I am stuck. I have been playing around at http://recurrence-expansion-service.appspot.com/ with different combinations but so far without success.
How do I limit it to mid-May?
How do I write a rule that "skips" the weekends when I have parked on a Monday street?
How do I achieve two repeating patterns (a yearly pattern - Nov to May - and a 4/6 day pattern)?
I'm struggling to format a cron schedule for gcp properly and the docs aren't really helping me out.
Cron #1: Run every 50 minutes from 11:00 to 21:00 only on the months from march to october inclusive
schedule: every 50 minutes from 11:00 to 21:00 of mar,apr,may,jun,jul,aug,sep,oct
Cron #2: Run every day at 22:00 only on the months from march to october inclusive
schedule: every day 22:00 of mar,apr,may,jun,jul,aug,sep,oct
Neither of those work, but they were one of my attempts. What am I doing wrong here?
Referring to the Formatting the schedule docs below.
There is no supported syntax for your 1st cron:
specifying minutes in an [INTERVAL_VALUE] is only supported by END-TIME INTERVAL and START-TIME INTERVAL formats, but neither of them allows specifying months in the [INTERVAL_SCOPE].
the only format supporting month specification in [INTERVAL_SCOPE] is CUSTOM INTERVAL, but that only supports day specifications in [INTERVAL_VALUE].
But you can achieve an equivalent functionality by using the finer time specification in cron.yaml and making a check for the remaining conditions inside the cron job itself, doing nothing if the condition is not met. So your 1st cron would be achieved with:
this cron.yaml entry:
schedule: every 50 minutes from 11:00 to 21:00
an additional check for the current month inside the cron job itself, doing nothing (just returning) if the month is Jan, Feb, Nov or Dec.
Your 2nd cron is possible using a CUSTOM INTERVAL, you just need to place the hour at the end of the [INTERVAL_SCOPE]. From the doc:
[INTERVAL_SCOPE]: Specifies a clause that corresponds with the
specified [INTERVAL_VALUE]. Custom intervals can include the of
[MONTH] clause, which specifies a single month in a year, or a
comma-separated list of multiple months. You must also define a
specific time for when you want the job to run, for example: of
[MONTH] [HH:MM].
So your entry would be:
schedule: every day of mar,apr,may,jun,jul,aug,sep,oct 22:00
I've read the docs, but I'm scratching my head on how to do this. I want to run a cron job during business hours. So my cron.yaml would look something like:
cron:
- description: My Cool Cron Job
url: /myCoolCronJob.php
schedule: every 5 minutes from 06:00 to 19:00 every monday, tuesday, wednesday, thursday, friday
timezone: America/Los_Angeles
That doesn't work, obviously. But it should give you an idea of what I want to do. How can I make this cron job run during business hours?
The Schedule format doesn't offer a combination between the high-frequency
every N (hours|mins|minutes) ["from" (time) "to" (time)]
and the low frequency
("every"|ordinal) (days) ["of" (monthspec)] (time)
The way to obtain what you desire is to:
configure the high frequency portion of the schedule in cron.yaml:
schedule: every 5 minutes from 06:00 to 19:00
check the weekday condition inside the cron job itself, at the beginning and exiting without doing anything if the day of execution is Saturday or Sunday.
The complete description would be:
run a cron job in every 15 minutes, from 8:00 am to 5:00pm, every weekday (MON-FRI) pacific time. Also it would be better to be adjustable to daylight saving changes
How to do it in a cron.yaml in GAE?
You can't. Cron gives you one of two formats, but not both:
every N (hours|mins|minutes) ["from" (time) "to" (time)]
or
("every"|ordinal) (days) ["of" (monthspec)] (time)
Your best workaround would be to use:
every 15 minutes from 8:00 to 17:00
and then in code filter out weekends.
Worst case, you can create a new cron job for each day of the week! E.g.,
every monday ...
every tuesday ...
every wednesday ...
and of course skip the weekends.
I am trying to add a feature on one of my applications. Here is a sample:
Company ABC
Business hours:
Sunday closed
Monday 7am - 5pm
Tuesday 7am - 5pm
Wednesday 7am - 5pm
Thursday 7am - 5pm
Friday 7am - 5pm
Saturday closed
Company DEF
Sunday 10am - 12pm
Monday 8am - 4pm
Tuesday 8am - 4pm
Wednesday 8am - 4pm
Thursday 8am - 4pm
Friday 8am - 4pm
Saturday closed
Now, what I want to do is to have my users be able to search/filter the business hours. For example, only return businesses who are open during Monday 2PM, or Saturday 1PM, or Monday any time.
My idea is to use datetime in SQL Server, but it appears I may need to create 7 columns for each day (Sunday to Saturday) and different columns for Starting time to open to Closing time to open.
The next idea is to make these columns searchable such that I will be able to filter them. for example, if a user searches for Monday 12PM, the search will be Monday (open time) <= (user search, 12pm) <= (close time).
So basically, it will be similar to:
SELECT *
FROM Companies
WHERE [user_search_time] IS "BETWEEN open_time AND close_time WHERE day=[user_search_day]
I'm having a hard time designing this, let alone how to implement it.
Technology used is C#/ASP.Net and SQL Server 2008.
The problem is how to design/implement this feature using the technologies mentioned above.
Any idea/tips will be appreciated. Thanks!
Might want to push this to codereview, or programmers. I think you are on the right path, but instead of adding columns, add a new table. called business_hours
BUSINESS_HOURS
business (company fk)
open_time (datetime)
close_time (datetime)
day (M,T,W,TH,F,S,Sun) // you can do this however u want 1-7 would work as well
Then your query is almost the same as what you have.
SELECT *
FROM
business_hours
WHERE
business = user_company_id
[user_search_time] IS BETWEEN open_time AND close_time and
day=[user_search_day]
Benefits to a table is it's more denormalized and you could support hours that have breaks in them. I could suport 12-2 as well as 5-8. You would just insert a new record and it would work. I am not a big fan of doing all day by doing a range from 12AM to 12PM but it will work, and keep your design simple.