Using the Task Scheduler in AppMaster
Learn how to use the task scheduler in AppMaster.

Task Scheduler in the backend of the AppMaster application, as in the classic case of the backend, creates repeating scenarios. For example, when you need to do a specific action on a schedule. A classic example of such tasks is an example of cleaning up temporary files on the server, weekly backups, generating reports according to a given algorithm, etc.
Let's consider an example of using the task scheduler in the AppMaster application backend. Suppose you want to build a process that every morning at 9.00 am will send the user the weather to his mobile phone number.
Thus, the task is divided into several logical stages:
- Installing and configuring the module for sending mobile messages
- Creating and configuring an external request API process
- Setting up a scheduler in the application backend
1. Installing and configuring the module for sending mobile messages.The Nexmo module allows you to integrate into the AppMaster application the ability to send SMS messages to a selected number.

- API Key - API key that can be obtained in your Nexmo account ( https://dashboard.nexmo.com/settings);
- API Secret - a private key that is used in conjunction with the API key to identify the user. You can also get it in your Nexmo account ( https://dashboard.nexmo.com/settings);
- From number - number specified during registration in your Nexmo account.
The following business processes are installed automatically with the module installation:
- Nexmo.Send SMS - allows you to send messages to the specified number through the
Nexmo module:
- Phone[phone] - the phone number to which the message will be sent;
- Content [string] - text message;

2. The free OpenWeather API web resource will be used as a weather data source ( https://openweathermap.org/api).The first step is to create an external request API template. API request templates are presented in the Business Process section of the External API Requests tab. To create a new template, click on Create API request.

Request type: GET
Request address: https://api.openweathermap.org/data/2.5/weather
Query Params:
- Lat [string] - latitude
- Lon [string] - longitude
- Appid [string] - OpenWeather API Key
As part of this task, we are only interested in a few fields of the response body in the main ( https://openweathermap.org/api/one-call-3).
- Temp [float] - temperature
- Temp_min [float] - min temperature
- Temp_max [float] - max temperature
- Pressure [float] - pressure
- Humidity [float] - humidity

3. Before setting up the task scheduler, you need to create a Business Process that will receive weather information via the API. The business Process looks as follows:

- Make Weather Query Model In - creates a virtual request parameter model. Lon, lat - coordinates of the desired location, appid - API key of the OpenWeather service;
- API Request: Weather - the business process responsible for interacting with OpenWeather API
- Expand Weather: Body Model Out - needed in order to deploy the Body response model

- Expand Weather: Body Model Out_main - expands the main model of the body of the request-response Body in order to get the temperature (temp).
- To String - converts temp field value into string type;
- Nexmo: Send SMS - sends a message with information about the temperature (Content) to the specified phone number (Phone)
Set up a scheduler in the business process section of the Scheduler tab.
Scheduler settings in the Schedule tab differ depending on their type.
Let's consider each of them in detail
1. Daily - allows configuring daily schedules

- Time - defines the time in UTC+0 at which the scheduler will start the selected BP;
- Days of the week - defines the days of the week for the scheduler to work;
- Automatically start - if set to True, a new BP will not start if the previous one has not been completed. Default value: False.
- Automatically retry - restarts the process automatically if it was interrupted/not started successfully.
Retry failed items processing - number of attempts to restart the process;
Wait before each retry attempt - delay time before each shot to restart the process;
- Force quit - forcefully terminate the process if not completed within a few seconds. True, by default. The number of seconds until completion is 3 seconds, by default.
2. Monthly - monthly planner

- Time - defines the time in UTC+0 at which the scheduler will start the selected BP;
- Days of the week - consist of two settings:
Repeat frequency:
- Every first
- Every second
- Every third
- Every fourth
- This day
Day of the week - defines the day of the week
- Month - the month is determined
- Auto Start - If set to True, a new PSU will not be started unless completed soon. Default value: False.
- Automatically retry - restarts the process automatically if it was interrupted/not started
Retry processing failed items - the number of process restarts;
Wait before each retry - delay time before each attempt to restart the process;
- Force Quit - Terminates a process if it is not completed within a few seconds. True, by default. The number of seconds until completion is 3 seconds, by default.
3. Periodically - allows you to flexibly configure the frequency of the scheduler

- Every - the ability to set repeatability every N seconds/minutes/hours/days. Default: every 1 hour.
- Automatically start - if set to True, a new BP will not start if the previous one has not been completed. Default value: False.
- Automatically retry - restarts the process automatically if it was interrupted/not started successfully
Retry failed items processing - number of attempts to restart the process;
Wait before each retry attempt - delay time before each shot to restart the process;
- Force quit - forcefully terminate the process if not completed within a few seconds. True, by default. The number of seconds until completion is 3 seconds, by default.
4. After starting the app - the single-time task planner

- Delay - defines the delay between application start and startup. Default - 0 sec
- Automatically retry - restarts the process automatically if it was interrupted/not started successfully
Retry failed items processing - number of attempts to restart the process;
Wait before each retry attempt - delay time before each shot to restart the process;
- Force quit - forcefully terminate the process if not completed within a few seconds. True, by default. The number of seconds until completion is 3 seconds, by default.
5. Before finishing the app - run the scheduler each time the application ends

- Automatically retry - restarts the process automatically if it was interrupted/not started successfully
Retry failed items processing - number of attempts to restart the process;
Wait before each retry attempt - delay time before each attempt to restart the process;
- Force quit - forcefully terminate the process if not completed within a few seconds. True, by default. The number of seconds until completion is 3 seconds, by default.
In the Params tab of the scheduler settings, it is also possible to pass parameters to the BP input when it is launched by the scheduler:

In our example, the scheduler settings look like this:
- Messages will be sent every day at 9 am UTC+0
- Automatically tries to restart the process 3 times with a delay of 10 minutes between attempts if the process did not start immediately;
- Forcefully terminates a process if it has not been completed within three seconds.

Our application lives and works in the backend, so for it to work, it is enough to publish it.
FAQ
A task scheduler runs a Business Process at a time or interval you choose. You can use it for recurring work such as backups, report generation, cleanup jobs, or sending a daily weather SMS.
Create a Business Process that gets the weather data and sends the SMS, then attach a daily scheduler to that process. Set the run time to 09:00 UTC+0 and provide the process inputs, such as location, API key, and phone number.
The Daily schedule runs a Business Process on selected days at a chosen UTC+0 time. Use it when the task should happen once per day, such as a morning notification or nightly cleanup.
The Monthly schedule lets you choose a month, a weekday, and an occurrence such as the first or third. It suits tasks like a report on the first Monday of each month.
Choose Periodically when a task must repeat every set number of seconds, minutes, hours, or days. For example, you can run a check every hour or refresh data every 15 minutes.
After starting the app runs a Business Process once after the application starts. You can set a delay, which helps when startup work needs to wait briefly before it runs.
Before finishing the app runs its Business Process whenever the application shuts down. Use it for work that should happen at the end of an application session, provided the process can finish within the configured limit.
Turn on automatic retry to have AppMaster start the Business Process again after a failed or interrupted run. Set the number of attempts and the wait time between them so temporary service errors do not stop the task immediately.
When automatic start is enabled, AppMaster does not start another run while the previous Business Process still runs. This helps prevent overlapping jobs, such as two report generations using the same data.
Use the Params tab to pass values into the Business Process when the scheduler starts it. In the weather example, you can pass the latitude, longitude, OpenWeather API key, destination phone number, and message settings.


