Klover Triggers - Part 2: Smart Parking Example with Scheduled TriggersAugust 15, 2017
In this article, we will learn more about using Klover’s Scheduled Triggers by implementing a Smart Parking “Surge Pricing” solution using them. It is the second in a multi-part series describing how to use Klover Triggers to implement user-defined rules and execute Actions. If you missed the initial article, you can come up to speed on basic Trigger concepts, before diving into Scheduled Triggers here: Klover Triggers - An Introduction
Concepts in the article include:
- Jobs, Schedules (e.g., Scheduled Triggers), and Actions
- Creating a Job with multiple Scheduled Triggers that run at exact date/times
- Configuring an Action to invoke a pre-defined Process from the Scheduled Triggers
- Property binding of values from a Scheduled Trigger to Process Instance variables.
We will be using Scheduled Triggers today. Scheduled Triggers provide extensibility within the Klover Smart Transportation Platform by allowing non-technical, business users to define business logic in the form of Actions that execute at a specific date/time or interval, similar to Linux cron tabs. Klover provides a user-friendly interface to define and manage your Scheduled Triggers, because who wants to write expressions like this all day!?
30 08 10 06 * /home/jason/executeCoolKloverStuff
A good time to use a Scheduled Trigger is when you want to perform the same logic at each interval. For instance, with Klover you can create a Scheduled Trigger to run every 2 minutes with an Action that will update a dynamic message sign (DMS) with the latest trip travel time for a route.
Another time to use Scheduled Triggers is when you want to perform some logic at an exact time in the future. Today, we will focus on this type of Scheduled Trigger. In our fictional example, a Smart City manages parking prices based on demand. When the local NFL team has a home game, parking ramps should implement “Surge Pricing” to collect higher fees for high-demand parking lots around the stadium. Each gameday, this involves telling drivers the current price and ensuring the parking management software charges the correct rate.
We’ve already designed our BPMN 2.0 (Business Process Modeling Notation) process flow to execute when the Scheduled Trigger runs (Figure 1). It is called “Implement Surge Pricing” and it takes a single process variable called “price” that is required to run the process instance.
As you can see in Figure 2, the diagram has two steps. The first step in the flow is a RestServiceTask. RestServiceTasks can be configured in Klover to call any REST API. The step “Set Pricing for Event” uses REST to inform a 3rd Party parking management system of the new price to charge for the game.
Working with the Job Scheduler
Our "Implement Surge Pricing" process needs to be started for each NFL home game, so we need to create a Job with a Scheduled Trigger per game. Let’s see how to create our Surge Pricing Job and Scheduled Triggers.
Add a Job
Under Manage > Job Scheduler, you can click the FAB (+) and enter a new Job. We will give it a Job Key called “price” with datatype of “Number”. This will hold the price we want to have set each time the job is triggered. Each Scheduled Trigger could set a different value for the Job Key "price" when it runs, but for our purposes it will always be the same.
We also ensure the Job is “Enabled = True”. You can toggle “Enabled = False” anytime you want to pause a Job. This is a handy way to stop it from running, while keeping it around to easily re-start it again later. You could always delete it, but then you'd have to re-create it and all of it's schedules again. Depending on the Job, that may be a lot of work.
Define the Schedules for the Job
Next, we will define the Job's Scheduled Triggers that will run at set times. A Job can have one or more Scheduled Triggers. By clicking on the Schedules tab (Figure 4), we are presented with a form where we can enter a Schedule name, how often it will repeat, when to start and stop running. Imagine you have the NFL home game schedule for your team in front of you. At this point, you will follow the NFL home game schedule and enter each home game as a different schedule that will fire only once. Since we defined a Job Key called “price”, it shows up in the Schedule UI for us to enter a value. We enter $15.00 for this, meaning parking will be $15.00 / hour during the game.
After entering two weeks from the NFL home game schedule, we see the Schedules starting to list under the Schedules tab (Figure 5). Each home game would be entered in a similar way to execute the Surge Pricing logic for each game.
Define an Action
Last but not least, we will define an Action that will be executed each time a Scheduled Trigger is fired (Figure 6). We click on Actions tab for the Job, then Add Action button, and choose a Process Action. We intend to invoke the “Implement Surge Pricing” process flow that was pre-defined for us. Each process can have zero to many process variables. If you remember, there was a process variable called "price" in our flow. When the process flow is chosen, the UI will show the process variables that are required to run the process flow. Klover’s property binding makes it easy to map the Job Key “price” value to the process variable “price”. After we do this, each time the Scheduled Trigger runs, it will pass a value of $15.00 into the “Implement Surge Pricing” process.
There you have it! We used Klover Smart Transportation Platform’s Schedule Triggers feature to implement a Smart Parking solution that allowed parking lots to charge a premium or “Surge Pricing” during NFL home games. In a real world solution don't forget to set parking prices back to normal levels after the game! This can easily be done using the same Scheduled Triggers features to pass in the lower price after each game is over.