How to set workflow condition that runs 2AM everyday? - date

I am to create email alert which works together with workflow rule.
My goal is to set the workflow that runs 2am everyday &&
my custom object field 'startDate' is tomorrow.
Basically every 2am workflow checks my custom object and see if startDate is tomorrow.
I'm at workflow page looking at Date predefined variable,
I see:
DATE
DATEVALUE
DAY
MONTH
NOW
TODAY
YEAR
For the startDate, I can set condition startDate = today() + 1
For second condition which is 2am everyday I can't think of a way. I don't see HOUR variable etc..
Has anyone done this before?
UPDATE
This might work I have to test though..
Change NOW() datetime output to String (done by TEXT)
Start from index 12 and grab 2 chars to the right (done by MID)
This means I obtained hour part of current time and if the value equals to '02' which means
2am at night.
MID(TEXT(NOW()), 12, 2) = '02'
Wait a sec.. but WHEN does salesforce check this workflow???
If they check workflow once a day, what time it would be? If check is done past 2am, this workflow would never get looked at??? I'm a bit confused.

Work flow only triggers on some event (object update, create, etc.). So having it run at 2am without a some sort of trigger is impossible.
The trick is to use schedulable apex to insert an object (or update a field) every day at 2am and set your workflow to trigger on that insert/update. Then your workflow would fire off on that object at whatever time your scheduled apex ran.

Related

Schedule Builds not adhering to CRON in Foundry

Schedule has been set to update this table between 14th to 25th of every month Mon-Fri. Although, the build got triggered recently on 12th of August which shouldn't happen according to the specified CRON.
The culprit seems to be a limitation of the cron expression, outside of Foundry - specifically this part:
The day of a command's execution can be specified by two fields — day of month, and day of week. If both fields are restricted (i.e., aren't *), the command will be run when either field matches the current time. For example, ``30 4 1,15 * 5'' would cause a command to be run at 4:30 am on the 1st and 15th of each month, plus every Friday.
So the cron schedule 30 8 14-25 * 1-5 will run between the 14th and 25th of the month and every Monday through Friday. (See for example crontab.guru (https://crontab.guru/#30_8_14-25_*_1-5).)
The generated description for it is not accurate, unfortunately we don't have much control over it as we use a library to turn the cron expressions into human readable expressions.
Related:
https://unix.stackexchange.com/questions/602328/are-the-day-of-month-and-day-of-week-crontab-fields-mutually-exclusive
https://unix.stackexchange.com/questions/602216/when-will-an-interval-cron-execute-the-first-time-ex-3-days/602222#602222
https://blog.healthchecks.io/2022/09/schedule-cron-job-the-funky-way/

Set trigger time of periods in Zabbix

I have a host that I monitor in 08:00-20:00 and trigger which acts when no ping.
Sometimes a host can be switched off in period of 20:00-08:00. I want in this situation dont't to trigger that act till 10:00 next day. Is it possible?
You can use the time() trigger function. Appending this to the existing function should work (replace ... with the reference to the same item as already in the expression):
and time(...) > 080000 and time(...) < 200000
Note that this will make the trigger ignore the time period outside of the bounds, so it will fire at 08:00 only if the problem condition still persists. Not sure how 10:00 fits in your original description.
On newer versions of Zabbix you can set Working hours for items, so the collect just will happens in a specific range..
https://www.zabbix.com/documentation/2.0/manual/appendix/time_period

How can I schedule bi-weekly jobs?

My app requires users to schedule recurring events that can recur daily, weekly, monthly, or bi-weekly.
By bi-weekly, I mean every fortnight (14 days) starting from an arbitrary date value provided at the time of creation.
My jobs table has two columns to support this: job_frequency_id and job_frequency_value. I'm able to schedule all types except for bi-weekly.
The first col is an FK to the job_frequencies table; it contains daily, weekly, monthy, bi-weekly values. The job_frequency_value contains the value corresponding to the frequency.
For example: If a job has a job_frquency_id == 3 and job_frequency_value == 10, it will run every 10th day of the month.
How do I add bi-weekly support without tampering with my db structure? I will use the job_frequency_value col to store the start date of the 14 day period, but I'm unsure of the calculation going forward.
Say your starting date is stored as a variable named 'createdDate'.
nextFortnight = DateAdd("ww", job_frequency_value*2, createdDate);
can you wrap your scheduled task in a and set it to run every week?
Something like
<cfif DateDiff('ww',CreateDate(2011,01,01),Today'sDate) MOD 2 EQ 1>
That way if the weeks are odd your scheduled task runs completely and if it's an odd week then it runs the scheduled task, but ignore all your code.

How to insert forever repeated events in sqlite3 iphone database?

I have one iphone application in which recurring events happens.the duration are like every day,every 2nd day,every 3rd day..,every week on mon,every week on tues,...,every second week on mon,..,every month on 1sr,every month on 2nd...,every second month on 1st,every second month on 2nd,... For some events there is end date but some events occurs forever.so how can i insert them automatically in sqlite3 database.eg.If an event repeats every 3rd day.how can i store it automatically after 3 days.or should i store all the events at the time of creation.If i store all the evnets at time of creation then the events that repeats forever.upto what duration i should store the value of them in database.
For this i have thought 2 approaches.one is storing just one occurance with repeated duration like every day.but in my application edit and delete functionality is also there.suppose event has one field event description then it can be different for different dates if user edit the events.events are displayed datewise on screen for a particular month and user can navigate to any previous and next month for current ,next and previous years.So if i use only single occurance then where should those edited or deleted events should be stored.
And if i take second approach store each occurance in database.Then upto what duration i should store the events which has no enddate.or is there a way that insert is automatically performed after specified duration.
Two ways, one an easy hack, one more difficult but correct :)
(1) Store each individual event for the next 10 years or so (or however long you want to!)
Good :
Easy and quick to implement
Bad :
Your db will get big very quickly.
What if the user wants to edit the details - how do you edit all of them at once?
What if the user wants to cancel / move the event- you have to delete all of them!
(2) Store some sort of 'event recurrence' information in the database with each event i.e. 'Every tuesday'
Good :
Only one event in the database, regardless of how many times it repeats.
Easy for the user to edit / delete the event - there's only one row in the database.
Bad:
More complicated event object - each event must have a list of 'when this event happens' information.
Makes very complicated event timings hard - i.e. 'last friday of every month'
Takes longer to implement
EDIT : My personal choice
I would choose option (2) - it takes longer to implement but I think option (1) will et you into trouble in the future.
I would have a data model like
Event has many Occurances
where your Event is the thing that the user has created with a description, start date etc and an Occurance is some sort of object that will say 'every friday' or 'not on the 4th'.
As part of creating an event, the user will say 'occurs once on Friday 13th' or 'occurs every Wednesday'. That information is used to create an array of Occurance objects.
Occurance would be a protocol that simply has the method occursOn: so you can have lots of different types of occurance (and you can add new types as your app gets more complicated).
The Event object would have a method something like occursOn: where you give it an NSDate and it returns if it occurs on that day. It does this by asking each of it's occurances in turn to see if they apply to that day.
To deal with deleted events, just add an Occurance to the end of the Event's array that overrides the others - i.e. 'not on Friday 13th'.
For example :
(1)
A user creates an event called 'My Event' starting on 1st Jan, occurring every Friday.
Your app would store
Event
description : 'My Event',
start date : 1st Jan 2011
occurances :
WeeklyOccurance
day : Friday
where WeeklyOccurance implements the <Occurance> protocol
(2)
The user asks to show the week's events, starting on Sunday the 8th Jan 2011
The app would :
For each day in the week
For each event in the database
if occursOn: this day
show the event on the ui
and for our event 'My Event', it would implement occursOn: like
- (BOOL)occursOn:(NSDate *)date
is this date before this event starts
if it is, return NO
set remembered = NO
for each occurance
does this occurance say 'yes','no' or '?' for this date?
if 'yes' set remembered YES
if 'no' return NO
if '?' continue the loop
return remembered
Because WeeklyOccurace only knows that it occurs on Fridays, it would return 'yes' for Fridays and '?' for all other days so the ui would show 'My Event' on Friday and not on any other days.
To add different types of occurance, just implement the <Occurance> protocol in different ways.
(3)
The user says actually it should be on every Friday apart from the 22nd
The app would create another Occurance, this time a NotOnThisDayOccurance and add it to the end of the Event's array i.e.
Event
description : 'My Event',
start date : 1st Jan 2011
occurances :
WeeklyOccurance
day : Friday
NotOnThisDayOccurance
day: 22nd Jan 2011
Now, if the users asks to display the weekly events, 'My Event' would look do this :
Ask the WeeklyOccurance if it's valid for friday the 22nd - this would return yes.
Ask the NotOnThisDayOccurance if it's valid for friday the 22nd - this would override the previous result and say NO
Therefore, the event would not show up on the 22nd but would show up on all the other fridays.

How to write trigger from given day and given time

Can anybody please tell me how to write a trigger in Quartz Scheduler which starts at Wednesday (17:23:12) and runs till Sunday (20:00:00). I am not sure about no. of repeations.
It's hard to say how you should do this when you aren't sure about the number or timing of the repeats. Knowing that would help decide which type of trigger to use (e.g. CronTrigger vs. SimpleTrigger).
However, regardless of the type of trigger, you would create a Date that is Wednesday at 17:23:12 and set that as the trigger's startTime property, and another Date that is Sunday at 20:00:00 and set that as the trigger's endTime property.
Then if a SimpleTrigger, you would set a repeat interval of XXX and a repeat count of "indefinitely". If a CronTrigger you would set a cron expression that represents the time(s) of day that you want the firing to occur.