Timers are very simple to create, update, and delete. Let’s give it a go. For our example, we’ll deal with a common use case within the ClearBlade platform: Polling an external internet site for information on a regular basis. Specifically, let’s pretend we’re polling a weather service such as NOAA for the daily weather report in your area.
For the sake of this example, we won’t actually write the code to do that. Just assume we have a ClearBlade code service called “myWeatherForcast” that can download weather forcasts for your area.
Creating a Timer
The first thing you need to do is, in the “Code” section of your application, find and select the “myWeatherForcast” code service. Once you’ve done that, locate and click on the icon and select the “Timers” tab. You should see a window like this:
Now, set “Logging enabled” to “Yes”. This simplifies the debugging process. Once you’ve finished debugging the timer, you can disable logging.
Now, click on “Add Timer +”. You should now see this:
Now, follow the following steps:
- In the “Name:” text box, give the timer a name. It must be unique within your system. You can also optionally enter a description.
- We’ll run our timer for a year, so enter “365” in the “Repetitions” text box.
- In the “Frequency” text box, enter “1”. In the “Frequency” pulldown menu, select “Days”.
- Tap in the box next to “Start Time” and select tomorrow’s date. In the time boxes below, enter 12 00 AM.
Now, your window should look something like this (the date will obviously be different):
Tap on Apply. The timer is now ready to run. Note: You’ll want to debug your code service first to make sure it works. Otherwise, you have to wait until the first scheduled time to know if your code is correct.
Updating a Timer
Suppose we love this timer so much that we want to run it forever. You can accomplish this by following these steps:
- Locate and select the “myWeatherForcast” code service in your application.
- Click on the icon and select the “Timers” tab.
- Locate the timer you created above.
- Either make the “Repetitions” textbox blank or set it to “-1”.
- Table the “Apply” button, and tap the “Confirm” button in the popup dialog.
Deleting a Timer
Normally, you don’t have to delete a timer. They delete themselves when they expire. However, if you have a timer that runs for a long time, or forever, you might want to get rid of it at some point.
To delete a timer, follow steps 1-3 in the “Updating a Timer” section above. Next, find and tap the icon. Next, tap the “Confirm” button in the pop up dialog.