Skip to main content

Scheduling using a Cron job

Introduction#

We have already seen how to schedule certain actions using the Timer component but sometimes business needs determine that more functionality may be needed. How so? Perhaps you set up an intergration to run and you don't need the resources to be on all of the time but may only need the resources provisioned when the integration runs, lets say once a month. That way the business could save the money allocated for the provisioning of those resources and only spin up containers when necessary.

VisionsCorp’s request#

VisionsCorp (VC) needs to schedule a job but don't want the integration running 24/7 in the background, accumulating costs. They have used the Cron Syntax in the past with their previous integration framework and they have heard that Jetic fully supports this. They have tasked you to find a way to schedule a recurring integration in such a way that when the integration finishes, it will stop the cluster yet still retain the ability to formulate itself again based on the specifications. With that you decide to use the Quartz component (one of but a few ways to schedule jobs in Jetic).

  • Quartz
  • Set Headers
  • Set Body
  • Log
  • Timer
  • Direct

Step 1: Add a Cron based Component#

Docusaurus

  • Add a Quartz component to the first route lane and add a CRON of 0 * * * * ?

  • Check DELETE JOB

  • Check AUTO START SCHEDULER

  • Under the Quartz component drag in a Set Headers component

  • For the Header Name put Metadata, Language: Simple, Value: Hello

  • Under the Set Headers component add a Set Body component

  • For the EXPRESSION add World

  • Add a Log component and for the MESSAGE add something such as Execution metadata is '${header.metadata}' and execution data is '${body}'.

    This next section is optional but will showcase a) the Direct component and b) how a Timer differs from a Cron job

Step 2: Looking at the difference#

Docusaurus

  • Add a Timer component to the second route lane and add a PERIOD of 30000
  • Under the Timer component add a Direct component
  • You may leave the ENDPOINT NAME as direct
  • In the third route lane add another Direct component
  • Leave ENDPOINT NAME as direct
  • Add a Log with a MESSAGE as Processing new event triggered by timer
  • Run the integration

Notice "Execution metadata is 'Hello' and execution data is 'World'. Processing new event triggered by timer. Processing new event triggered by timer. Execution metadata is 'Hello' and execution data is 'World'." You can also look at the Execution Log and Build Log and view the instance stopping and starting back up rather than continuing to repeat.

🎉 Congratulations you have successfully created your integration with a Cron based Component. With Quartz and other scheduling capabilities you can use your resources frugally and better control your output. You have also seen how to dynamically swith lane's with the Direct component. As your routes grow increasingly larger you may decide to use the Direct component to move routes so that they can be easily tracked. 🎉