model an Administration Page for a Job

A job is a sequence of operations that has to be executed asynchronously by the application. It's possible to schedule a job at a specific time or interval, which means that jobs can be automatically triggered (scheduled when the application starts). It's also possible to schedule a job at runtime: the user navigation can schedule a new job instance. To get started with Jobs please refer to this article.
Schedule Policy Cron Expression
Now NOW
In X Minutes IN_X
Every Day seconds minutes hours * * ?
Every X Seconds 0/X * * * * ?
Every X Minutes 0 0/X * * * ?
Every X Hours 0 0 0/X * * ?
Once a week seconds minutes hours ? * day
Once a month seconds minutes hours day * ?
Once a year seconds minutes hours day month ?
Specific Date seconds minutes hours day month ? year

This article discusses how to model a Job Administration Page for your Web application, in which the user can manage the Job Schedule at runtime, which means while the user is navigating the application. This page lets the user schedule a job or deleting a scheduled one. Let's see which are the steps to * Add a Page to the Web Model, named "Job Administration Page"
*
Add an Entry Unit to the page and name it "Schedule Job". To understand which are the fields necessary to the user in order to be able to Schedule a Job, you need to know how the Schedule Job Unit works. The available cases are reported in the table on the right. Considering these cases, let's add Fields to the Entry Unit.

Add six Selection Fields ("When" - in which there's the list of all the schedule policy options - "Year","DayInt","Hour","Minutes","Seconds"). Add a Slot both label and output to each field. Add the two last Selection Fields "Day" and "Month".

Add three Fields ("Every X Seconds","Every X Hours","In/Every X Minutes") of "Integer" type.

* Add a Script Unit to the page and name it "Prepare Form". This Script Unit prepares the options for all the selection fields of the Schedule Job form. In order to extract some information such as the day names, the month lists and the years, it uses the Calendar class taking also into consideration the current locale used by the user in order to view the page. For the other information, just build a list with the correct range of numbers. This is the sample code # Connect the Script Unit and the Entry Unit with a transport link and make the coupling just like the figure on the right.
# Add a Variable named "schedulePolicy" to the page so that you can show to the user different fields, depending on the Schedule Policy choice. In the Properties View choose "String" for the Variable type, choose the Schedule Job Entry Unit for the Unit property and choose the "When" field for the Parameter property.
# Add a Schedule Job Unit outside the page. In the Properties View, choose "Custom Cron Expression" for the Schedule Policy, then choose a modeled Job. Note that the Administration page allows you to manage the scheduling of one job. If you want to manage different jobs, you have to add an additional Field in the Entry Unit which contains the Job list, and then use a set of Schedule Job Unit, with a Switch Unit preceding them, and choosing wich one of them should be processed.
# Add a Script Unit outside the page. This unit builds the correct cron expression for each schedule policy chosen by the user and passes it to the Schedule Job Unit. The Groovy script just consider the schedule policy and uses a subset of the input parameter in order to build the cron expression. This is the sample code.