Call Sales +1 702-848-6759 | Email Sales sales@flux.ly — Call Support +1 702-879-4130 | Email Support support@flux.ly

Job Scheduling and File Transfer

time expressions and business calendars flux job scheduler and batch processing

Describing time – even in a job scheduler – is not a trivial matter. While Flux does not provide a plutonium reactor and a capacitor, Flux does provide a clean and concise way to describe time.

Time expressions are simple, compact, textual representations of time- and date-based schedules. Time expressions are used in several places throughout Flux (including engine configuration options as well as trigger and action properties) to specify when and how often particular tasks will execute on the Flux scheduling engine.

Time expressions make it easy to instruct workflows and events to run at specific times, on a recurring basis, or even relative to other times (or relative to the last run of the same event).

In Flux, there are two different types of time expressions:

  • Cron-style time expressions typically model schedules that occur at a specific time, date, or frequency, according to a set of constraints. For example, a typical use case for a Cron-style time expression might be an event that needs to occur every 30 minutes from 08:00 to 17:00. Cron-style time expressions are modeled after Unix Cron (Flux’s Cron-style time expressions are, however, much more powerful and expression than Unix Cron).
  • Relative time expressions model schedules where each event is scheduled relative to a certain time or date, or relative to the time and date of the previous event. Relative time expressions are especially useful for schedules that Cron-style expressions cannot express: for example, use cases for a Relative time expression might be an event that needs to run on the first Monday after the previous event, or an event that must run on election day in the United States (the first Tuesday after the first Monday in November).

This post describes the general syntax for using relative time expressions in Flux and provides some specific examples to demonstrate how time expressions can be used in your scheduling.

Relative Time Expressions

Relative time expressions specify an offset, relative to a specific point in time.

Examples include:

+90s (90 seconds in the future)
-45s (45 seconds in the past)
+2H+30m+15s (2 hours, 30 minutes, 15 seconds in the future)
>thu (forward to next Thursday)
>2sat (forward 2 Saturdays)
>oct (advance to October)
^M (go to the beginning of the current month)
@fri (go to the first Friday of the current month)
@!fri (go to the last Friday of the current month)
@2fri (go to the second Friday of the current month)
^M>3fri (go to the third Friday of the current month)
+M^M>2tue (go to the second Tuesday of next month)
@22d (go to the 22nd day of the current month)
@3H (go to 3 AM on the current day)
>b (advance to the next business day)
+M^M>b@9H (advance to 9 AM on the first business day of next month)
<b (back up to the previous business day)
?sat{-d}?sun{+d} (if today is Saturday, back up to Friday but if today is Sunday, advance to Monday}

Relative time expressions consist of the following syntax. They may be combined to form more complex time expressions.

Relative Time Expression Syntax

The syntax for a relative time expression is simply:

+ <number> <unit>

Which reads as “Move forward in time by number of units.” A unit can be years, months, weeks, days, hours, minutes, seconds, or milliseconds. If number is omitted, it defaults to 1.

– <number> <unit> Move backward in time by number years, months, weeks, days, hours, minutes, seconds, or milliseconds. If number is omitted, it defaults to 1.
> <number> <unit> Move forward in time by number absolute days-of-the-week, absolute months, holidays, non-holidays, weekdays, weekend days, or business days. If number is omitted, it defaults to 1. If date is already on the given day-of-week or month, then number is first decremented by 1.
< <number> <unit> Move backward in time by number absolute days-of-the-week, absolute months, holidays, non-holidays, weekdays, weekend days, or business days. If number is omitted, it defaults to 1. If date is already on the given day-of-week or month, then number is first decremented by 1.
^ <unit> Go to the beginning of the current year, month, week, day, hour, minute, second, or millisecond. Going to the beginning of one time-unit (such as hour) also causes any sub-units (such as minute, second, and millisecond) to go to the beginning.
$ <unit> Go to the end of the current year, month, week, day, hour, minute, second, or millisecond. Going to the end of one time-unit (such as hour) also causes any sub-units (such as minute, second, and millisecond) to go to the end.
@ <n> <unit> Go to the nth year, month, day-of-month, hour, minute, second, or millisecond. Recognized units are y, M, d, H, m, s, and S.
@ <n> <day> Go to the nth day-of-week in the current month. n is 1-based. If n is omitted, go to the first day-of-week in the current month. Recognized day-of-week values are sun, mon, tue, wed, thu, fri, and sat.
@ ! <day> Go to the last day-of-week in the current month.
? <unit>{<then-time-expression>} {<else-time-expression>} If the current time occurs on the given unit (day-of-week, month-of-year, business day, etc), apply the then-time-expression. Otherwise, apply the optional else-time-expression. These conditional time expressions may be nested.

Relative Time Units

The following units are recognized in relative time expressions.

Recognized Units Unit
y Year
M Month
w Week
d Day
H Hour
m Minute
s Second
S Millisecond
 
h Holiday
n Non-holiday
D Weekday: Monday through Friday
e Weekend day: Saturday through Sunday
b Business day: A day specified using a business interval to define an acceptable business day. For instance, a day that is not a weekend or holiday.
   
mon Monday
tue Tuesday
wed Wednesday
thu Thursday
fri Friday
sat Saturday
sun Sunday
 
jan January
feb February
mar March
apr April
may May
jun June
jul July
aug August
sep September
oct October
nov November
dec December

Even More Examples

+30d-8H Move forward 30 days, then backup 8 hours.
-12H+30s Move backward 12 hours, then forward 30 seconds.
+23y-23M+23S-8m Move forward 23 years, then backup 23 months, then move forward 23 milliseconds, then backup 8 minutes.
>sat Move forward to Saturday.
>3sat>nov Move forward 3 Saturdays, then skip ahead to November.
<5may>fri Move backward 5 Mays, then advance to Friday.
@2005y+2y<sun Go to the year 2005, then move forward 2 years, then backup to Sunday.
(2M)22d (8H)30m Go to March 22nd, 8:30 AM of the current year.
^M>4mon Go to the beginning of the month, then advance 4 Mondays.
+M^M>4mon Go to the beginning of next month, then advance 4 Mondays.
^d+7H Go to the beginning of today, then advance 7 hours.
>3D Move forward three weekdays.
<4e Move backward 4 weekend days.
>n Move forward to the next non-holiday.
?D{+d} If today is a weekday, advance a day.
?b{}{+2d} If today is not a business day, advance two days.

In Closing

Flux Time expressions provide a powerful means to model complex time requirements. Time expressions make it easy to instruct Flux workflows and events to run at specific times, on a recurring basis. Relative time expressions provide a means to depict time in terms relative to other times (or relative to the last run of the same event).

Top