Skip to main content

Cron

Recourse to scheduling of periodic executions. This resource uses the library Quartz Scheduler for execution scheduling. When using Cron, you must configure the expression that defines when the job will run. Below are indications of how the configuration should be performed.

Cron expressions supported formats

FIELD NAMEMANDATORYACCEPTED VALUESALLOWED SPECIAL CHARACTERS
SecondsYES0-59, - * /
MinutesYES0-59, - * /
HoursYES0-23, - * /
Month's dayYES1-31, - * ? / L W
MonthYES1-12 or JAN-DEC, - * /
WeekdayYES1-7 or SUN-SAT, - * ? / L #
YearNOempty, 1970-2099, - * /

Examples of Cron expressions

EXPRESSIONMEANING
1 * * * * ?It runs on the second number 1 of every minute.
0 0 12 * * ?Starts at 12:00 a.m. every day
0 15 10 ? * *Starts at 10:15 a.m. every day
0 15 10 * * ?Starts at 10:15 a.m. every day
0 15 10 * * ? *Starts at 10:15 a.m. every day
0 15 10 * * ? 2005Starts at 10:15 a.m. every day during 2005
0 * 14 * * ?Starts every minute starting at 2:00 p.m. and ends at 2:59 p.m., every day
0 0/5 14 * * ?Starts every 5 minutes starting at 2:00 p.m. and ends at 2:55 p.m. every day
0 0/5 14,18 * * ?It starts every 5 minutes starting at 2:00 p.m. and ends at 2:55 p.m. Afterwards, it starts every 5 minutes starting at 6:00 p.m. and ends at 6:55 p.m., every day
0 0-5 14 * * ?Starts every minute starting at 2:00 p.m. and ends at 2:05 p.m. every day
0 10,44 14 ? 3 WEDIt starts at 2:10 p.m. and at 2:44 p.m. every Wednesday in March.
0 15 10 ? * MON-FRIStarts at 10:15 a.m. every working day of the week (Monday to Friday)
0 15 10 15 * ?Starts at 10:15 a.m. on the 15th of each month
0 15 10 L * ?Starts at 10:15 a.m. on the last day of each month
0 15 10 L-2 * ?Starts at 10:15 a.m. on the penultimate day of each month
0 15 10 ? * 6LStarts at 10:15 a.m. on the last Friday of every month
0 15 10 ? * 6LStarts at 10:15 a.m. on the last Friday of every month
0 15 10 ? * 6L 2002-2005Starts at 10:15 a.m. every last Friday of every month during 2002, 2003, 2004 and 2005
0 15 10 ? * 6#3Starts at 10:15 a.m. on the third Friday of every month
0 0 12 1/5 * ?It starts at 12:00 a.m. every 5 days of each month, starting on the first day of each month.
0 11 11 11 11 ?It starts every 11th of November at 11:11 a.m.

checkExists


_cron.checkExists(key: string) : boolean

Description

Checks if the scheduled service key exists.

How To Use
if (_cron.checkExists("pricesUpdate")) {
_out.print("The scheduled service 'pricesUpdate' exists!")
}

Attributes
NAMETYPEDESCRIPTION
keystringJob ID key name.
Return

( boolean )

Whether the scheduled service was found.


config


_cron.config() : void

Description

Configures periodic scheduling by importing the configuration file.

Return

( void )


delete


_cron.delete(key: string) : boolean

Description

Removes a service execution schedule.

How To Use
_cron.delete("pricesUpdate")

Attributes
NAMETYPEDESCRIPTION
keystringJob ID key name.
Return

( boolean )

Whether it was possible to delete the scheduled service.


interrupt


_cron.interrupt(key: string) : boolean

Description

Interrupts a service execution schedule.

How To Use
_cron.interrupt("pricesUpdate")

Attributes
NAMETYPEDESCRIPTION
keystringJob ID key name.
Return

( boolean )

Whether it was possible to stop the scheduled service.


pause


_cron.pause(key: string) : boolean

Description

Changes the execution state to pause, in this state the associated service is not executed.

How To Use
_cron.pause("pricesUpdate")

Attributes
NAMETYPEDESCRIPTION
keystringJob ID key name.
Return

( boolean )

Whether it was possible to pause the scheduled service.


remove


_cron.remove(key: string) : boolean

Description

Removes a service execution schedule.

How To Use
_cron.remove("pricesUpdate")

Attributes
NAMETYPEDESCRIPTION
keystringJob ID key name.
Return

( boolean )

Whether it was possible to delete the scheduled service.


resume


_cron.resume(key: string) : boolean

Description

Changes the execution state to resume, after a schedule is in the pause state, it can be reactivated via resume.

How To Use
_cron.resume("pricesUpdate")

Attributes
NAMETYPEDESCRIPTION
keystringJob ID key name.
Return

( boolean )

Whether it was possible to continue the scheduled service.


schedule


_cron.schedule(key: string, config: string, url: string) : Cron

Description

Creates a service execution schedule.

How To Use
_cron.schedule("updatePrices", "1 * * * * ?", "/services/jobs/update-prices",
_val.map()
.set("categoryId", 1)
.set("productId", 1)
)
Attributes
NAMETYPEDESCRIPTION
keystringJob ID key name.
configstringCron Scheduling Time Expression, see table above.
urlstringURL to be run by the job.
Return

( Cron )

The current Cron instance.


_cron.schedule(key: string, config: string, url: string, params: Values) : Cron

Description

Creates a service execution schedule.

How To Use
_cron.schedule("updatePrices", "1 * * * * ?", "/services/jobs/update-prices",
_val.map()
.set("categoryId", 1)
.set("productId", 1)
)
Attributes
NAMETYPEDESCRIPTION
keystringJob ID key name.
configstringCron Scheduling Time Expression, see table above.
urlstringURL to be run by the job.
paramsValuesData to pass as a parameter to service.
Return

( Cron )

The current Cron instance.


schedules


_cron.schedules() : Values

Description

List of all application service schedules.

Return

( Values )

The list of all scheduled services of the application that are configured in Cron.