Create a scheduling task
After you publish an application, you can create scheduling tasks for it.
Procedure
Log on to the SOFAStack console.
In the navigation pane on the left, choose Middleware > Task Scheduling > Task Configuration.
Choose Add Task > Cluster Task, and then configure the following parameters:
Parameter
Description
Task Name
The name of the task. This name is used to identify the task.
Application Name
Enter or select the name of the target application.
The name can contain English letters, Chinese characters, digits, underscores (_), and hyphens (-). It must be up to 50 characters long. The name must be the same as the application name that is configured for
spring.application.namein theapplication.propertiesfile of the project.Scheduling Type
The scheduling type of the task. Valid values:
Cron expression trigger: A task of this type is triggered at a scheduled time based on a CRON expression that you configure when you create the task.
Event trigger: A task of this type is triggered by an external event.
Cron Expression
The CRON expression that is used to trigger the task at a scheduled time. For more information about how to configure a CRON expression, see CRON expression details.
This parameter is required only when you set Scheduling Type to Cron expression trigger.
Task Splitting
Enter the names of the splitting processor and the execution processor. For more information about how to obtain the names, see Task splitting and execution.
Task Group (Optional)
Select or create a task group to facilitate task management.
Custom Parameters (Optional)
Custom parameters allow you to pass parameters from the console to a task. Parameters can also be passed between tasks. The format is
key=value.The parameters are described as follows:
Parameter Name: The name of the custom parameter.
The name can contain uppercase and lowercase English letters, digits, and underscores (_). The name cannot exceed 128 characters in length.
Type and Parameter Value: The following types and parameter value configurations are available.
STRING: A generic string.
LIST: An array of strings, for example,
["aaa","bbb"].BOOLEAN: `true` or `false`.
PLACEHOLDER: A parameter that can be replaced. The following variables are supported:
${sharding}: Replaces the current shard value. Use this with simple jobs.${shardingCount}: Replaces the number of shards that is configured for a simple job.${triggerTime}: Replaces the expected trigger time.
NoteYou can also get and overwrite custom parameters in your application code using the context object. The object must implement `Serializable`. The following code shows an example:
public class SimpleTaskDemo implements ISimpleJobHandler { @Override public ClientCommonResult handle(JobExecuteContext context) { // Get the object based on the key. Object obj = context.getCustomParam("intObj"); // Get custom parameters. Map<String, Object> paramsMap = context.getCustomParams(); context.putCustomParams("num", 2); List<String> listparam = newArrayList <>(); listparam.add("aaaaaa"); listparam.add("111111"); context.putCustomParams("intparam", 111); context.putCustomParams("stringparam", "dfadsfad1243"); context.putCustomParams("listparam", listparam); // Note: The object must implement Serializable. context.putCustomParams("objectParam", newObject()); return ClientCommonResult.buildSuccessResult(); } .... }Routing Policy
The policy to route the task for execution. Valid values:
Random: The task is randomly distributed to a client server for each execution.
Directed: The task is distributed to the same client server for each execution.
Specifying a client server IP address is not supported.
Polling: The task is sequentially distributed to each client server for each execution.
Communication Mode
The communication mode of the task. Valid values:
ONEWAY: A one-way operation that does not have a return value. The console does not record trigger records. No timeout or retry is supported.
This mode is recommended for high-frequency, non-critical tasks.
CALLBACK: A bidirectional operation that has a return value. You can view trigger records, set a timeout period, and configure retries in the console.
This mode is recommended for critical tasks. The trigger interval must be at least 5 minutes.
Task Mutual Exclusion
Specifies whether to enable the mutually exclusive mode for the task. If you enable this mode, a task that is in the "Executing" or "Paused" state cannot be triggered again, even if its next scheduled trigger time is reached. The status of this scheduled execution is marked as "Skipped".
By default, this mode is disabled. This parameter is available only when you set Communication Mode to CALLBACK.
Missed Trigger Policy
The policy to handle missed triggers. Valid values:
Ignore: No compensatory action is taken.
Trigger Immediately: The task is immediately retriggered.
Trigger When Time is Sufficient: A compensatory trigger depends on whether there is enough time before the next scheduled trigger. If `Current Time + Timeout Period < Next Trigger Time`, a compensatory trigger is performed and recorded. Otherwise, the task is not triggered. If multiple triggers are missed, only one compensatory trigger is performed during recovery.
This parameter is available only when you set Communication Mode to CALLBACK and Scheduling Type to Cron expression trigger.
Timeout Policy
The policy to handle a task execution timeout. Valid values:
Do Nothing: The statuses of both the trigger record and the execution record are marked as failed.
Stop Subsequent Triggers: The execution record status is marked as failed, the trigger record status is marked as timeout, and the task cannot be triggered again. This option is available only if you enable the mutually exclusive mode.
This parameter is available only when you set Communication Mode to CALLBACK.
Timeout Period
The timeout period for task execution. If the task does not return a callback within this period, the execution is considered to have failed. You can set the unit to Minutes or Hours.
This parameter is available only when you set Communication Mode to CALLBACK.
Failure Handling Policy
The policy to handle a failed task execution. Valid values:
No Retry: The task is not retried after it fails.
Retry up to Three Times: The task is immediately retried after it fails, up to a maximum of three times.
Priority
Used to identify the importance of the task. This parameter has no other effect.
The default value is Medium.
Advanced Options
Specifies whether to configure advanced options. If you enable this feature, you can configure the following parameters as needed:
If you set Communication Mode to ONEWAY, you can configure the following parameter:
Maximum processing rate per machine: The maximum amount of data that a single client can process per unit of time. The default value is the maximum processing rate of the machine.
If you set Communication Mode to CALLBACK, you can configure the following parameters:
Maximum processing rate per machine: The maximum amount of data that a single client can process per unit of time. The default value is the maximum processing rate of the machine.
Maximum number of parallel index chunks: The maximum number of parallel index chunks for the cluster. A chunk is a data shard that is split from a task in a single execution step. Index chunks are evenly allocated to clients.
If the maximum number of parallel index chunks per machine is x, the maximum number of parallel index chunks for the cluster is y, and the number of clients is m, the actual maximum number of parallel index chunks per client is
min(x, y/m).Maximum number of parallel index chunks per machine: The maximum number of parallel index chunks for a single client. The default value is 5.
Maximum number of data entries to skip for a single failed shard: The maximum number of data entries to skip after a single shard fails to be processed. If a single shard fails, the next n data entries in the queue can be skipped. By default, no data is skipped.
Description (Optional)
The description of the task, such as its business purpose or scope of impact. The description can be up to 1024 characters in length.
Click Submit.
In the task list, turn on the Enable switch for the target task.
If a client is online, it is automatically registered for the newly configured task. Even when a task is disabled, you can manually trigger it once by clicking Trigger in the Actions column.
