Relative Time Expressions in Flux Job Scheduler

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

FEATURES  RESOURCES  CONTACT DOCUMENTATION DOWNLOAD  SEARCH

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 con guration 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 work ows and events to run at speci c 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 speci c 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 rst Monday after the previous event, or an event that must run on election day in
the United States (the rst Tuesday after the rst Monday in November).

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

RELATIVE TIME EXPRESSIONS


Relative time expressions specify an offset, relative to a speci c 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 rst 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 rst 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.

Move backward in time by number years, months, weeks, days, hours, minutes, seconds, or milliseconds. If number is omitted,
– <number> <unit>
it defaults to 1.

Move forward in time by number absolute days-of-the-week, absolute months, holidays, non-holidays, weekdays, weekend
> <number> <unit> 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 rst decremented by 1.

Move backward in time by number absolute days-of-the-week, absolute months, holidays, non-holidays, weekdays, weekend
< <number> <unit> 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 rst decremented by 1.

Go to the beginning of the current year, month, week, day, hour, minute, second, or millisecond. Going to the beginning of one
^ <unit>
time-unit (such as hour) also causes any sub-units (such as minute, second, and millisecond) to go to the beginning.

Go to the end of the current year, month, week, day, hour, minute, second, or millisecond. Going to the end of one time-unit
$ <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.

Go to the nth day-of-week in the current month. n is 1-based. If n is omitted, go to the rst day-of-week in the current month.
@ <n> <day>
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-
If the current time occurs on the given unit (day-of-week, month-of-year, business day, etc), apply the then-time-expression.
expression>} {<else-
Otherwise, apply the optional else-time-expression. These conditional time expressions may be nested.
time-expression>}

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

Business day: A day speci ed using a business interval to de ne an acceptable business day. For instance, a day that is not a
b
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 work ows and events to run at speci c 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).

Flux Sales
 +1 (720) 930-4239  sales@flux.ly

Flux Suppor t
 +1 (720) 441-1844  support@flux.ly

© 2 0 2 0 F l u x Co r p o ra t i o n

You might also like