Skip to content

Creating Workflow

manikvenkat edited this page Nov 6, 2019 · 13 revisions

A workflow is a sequence of tasks necessary to complete a job. Tasks can be dependant on other tasks. Each task is defined as part of the workflow. A workflow can then be scheduled for execution by attaching a trigger to it. Multiple triggers can be attached to a workflow.

Creating a workflow in Kronos

Step 1: Create workflow

A workflow in Kronos is defined as:

KEY DESCRIPTION TYPE DEFAULT MANDATORY
name name of the workflow string None yes
namespace namespace the workflow belongs to (used in multi-tenancy) map None yes
description a short description about workflow map None no
tasks list of tasks part of the workflow defined as workflow task(see below) list None yes
properties global properties available to each workflow task within the workflow. The task can refer to a property defined at a workflow level as ${workflow.prop_name} where prop_name is the name of the property defined at workflow level map None no
emailOnSuccess list of recipient to send email on success list None no
emailOnFailure list of recipient to send email on failure list None no

Note: Email notifications will be sent only if mail service is configured while starting the scheduler. To configure mail service in scheduler check out configuring email notifications guide.

A workflow task in Kronos is defined as:

KEY DESCRIPTION TYPE DEFAULT MANDATORY
name name of the task string None yes
type type of task (used to identify the task handler for executing the task) string None yes
properties properties required by the task handler to execute the task map None no
dependsOn list of tasks (name) current task depends on list None no
maxExecutionTimeInMs max allowed time for the task to finish execution in millisecond long 86400 no
enabled enable/ disable a task, disabled tasks won’t be picked for execution boolean true no
policies set of policies to apply on task completion. As of now only retry policy is supported. policy None no

Note: If a task is marked as disabled (enabled=false), All the tasks depending on it should be explicitly marked as disabled otherwise the scheduler will throw a validation exception.

Workflow Task Properties

Workflow task properties can be set in 3 different ways in Kronos.

  1. Fixed properties - A fixed key/value pair where key is a string and value can be any fixed value.
  2. Workflow properties - A workflow task can refer to properties defined at a workflow level. The properties defined at workflow level can be referred as ${workflow.param_name} where param_name is the property key defined at the workflow level.
  3. Properties from dependee task - A task can also refer to output variable of its dependee task or any of the task in its dependee hierarchy. For e.g. If task C depends on B and B depends on A. Task C can refer to property of A via ${A.keyName} or B via ${B.keyName}, where keyName is the output of task A or B.

Workflow Task Policy

As of now Kronos supports only retry policies at a task level which is applied on failure. A task will be retried on failure independent of the failure reason.

retry

KEY DESCRIPTION TYPE DEFAULT MANDATORY
type type of policy (should be retry) enum None yes
maxRetryCount number of times to retry the task on failure int 1 no

Step 2: Create a trigger for the workflow

A workflow trigger in Kronos is defined as:

KEY DESCRIPTION TYPE DEFAULT MANDATORY
name name of the trigger string None yes
workflow name of the workflow to assign the trigger string None yes
namespace namespace the workflow trigger belongs to (used in multi-tenancy) map None yes
startAt time in millis to start the scheduling of workflow long None no
schedule defines the schedule (can be a cron/ simple/ fixed/ daily or calendar type) schedule None yes
endAt time in millis to stop the scheduling of workflow long None no
enabled enable/ disable a trigger, disabled trigger won’t schedule workflow for execution boolean true no
properties properties to be overridden defined at a workflow level before execution map None no

Schedule

Kronos supports 5 type of schedule.

  • simple - defines strict/literal interval-based schedules for workflow (can be compared directly with quartz simple schedule)
  • cron - defines CronExpression based schedules for workflow (can be compared directly with quartz cron based schedule)
  • calendar - defines calendar time (day, week, month, year) interval-based schedules for workflow (can be compared directly with quartz calendar interval schedule)
  • daily_time - provide an extra convenient method for you to set the trigger's start time and end time of the day (can be compared directly with quartz daily time interval schedule)
  • fixed - schedule workflow at a fixed delay, each execution is scheduled relative to the actual execution time of the previous execution of workflow.

simple

KEY DESCRIPTION TYPE DEFAULT MANDATORY
type type of schedule (should be simple) enum None yes
misfireInstruction set the trigger mis fire instruction int 0 no
repeatIntervalInMs the interval at which the trigger should repeat in milliseconds long None yes
repeatForever specify that the trigger will repeat indefinitely boolean false no
repeatCount the number of time the trigger will repeat int None no

reapeatCount takes precedence over repeatForever.

cron

KEY DESCRIPTION TYPE DEFAULT MANDATORY
type type of schedule (should be cron) enum None yes
misfireInstruction set the trigger mis fire instruction int 0 no
cronExpression cron expression string to base the schedule on string None yes
timezone the time zone for which this CronExpression will be resolved string None no

timezone should be either an abbreviation such as "PST", a full name such as "America/Los_Angeles", or a custom ID such as "GMT-8:00".

calendar

KEY DESCRIPTION TYPE DEFAULT MANDATORY
type type of schedule (should be calendar) enum None yes
misfireInstruction set the trigger mis fire instruction int 0 no
repeatInterval the interval at which the trigger should repeat long 1 no
repeatIntervalUnit the time unit (IntervalUnit) of the interval intervalunit Day no
preserveHourOfDayAcrossDaylightSavings If intervals are a day or greater, this property (set to true) will cause the firing of the trigger to always occur at the same time of day,(the time of day of the startTime) regardless of daylight saving time transitions. boolean false no
skipDayIfHourDoesNotExist If intervals are a day or greater, and preserveHourOfDayAcrossDaylightSavings property is set to true, and thehour of the day does not exist on a given day for which the trigger would fire, the day will be skipped and the trigger advanced a secondinterval if this property is set to true. boolean false no
timezone the time zone for which this CronExpression will be resolved string None no

timezone should be either an abbreviation such as "PST", a full name such as "America/Los_Angeles", or a custom ID such as "GMT-8:00".

Available values for repeatIntervalUnit are: MILLISECOND, SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, YEAR

daily_time

KEY DESCRIPTION TYPE DEFAULT MANDATORY
type type of schedule (should be daily_time) enum None yes
misfireInstruction set the trigger mis fire instruction int 0 no
repeatInterval the interval at which the trigger should repeat long 1 no
repeatIntervalUnit the time unit (IntervalUnit) of the interval string Minute no
repeatCount the number of time the trigger will repeat int -1 no
startTimeOfDay set the trigger to begin firing each day at the given time timeofday no
endTimeOfDay set the trigger to end firing each day at the given time timeofday no
daysOfWeek set the trigger to fire on the given days of the week set [1,2,3,4,5,6,7] no

startTimeOfDay is set to beginning of day (0:0:0) is not specified and endTimeofDay is set to end of the the day (23:59:59) if not specified by default.

daysOfWeek refer to set of days in a week where Sunday is 1 and Saturday is 7.

Available values for repeatIntervalUnit are: MILLISECOND, SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, YEAR.

fixed

KEY DESCRIPTION TYPE DEFAULT MANDATORY
type type of schedule (should be fixed) enum None yes
intervalInMs the interval in milliseconds at which the trigger should repeat from the previous execution long 0 no

Sample workflows and triggers are available here for reference.