This topic provides some coding conventions to help you better manage scheduled tasks and ensure the stability of the development and production environments.
Name a scheduled task in the
Assume that a system is named Scheduler and has a scheduled task for junk flow cleanup named
truncate_flow_record. In this case, we recommend that you name the scheduled task
EC_TASK_SCHEDULER_TRUNCATE_FLOW_RECORD. This naming format helps you easily understand the business feature of the scheduled task based on the task name.
In the development environment, use the Cron expression
0 0 0 * * ?
0 0 0 * * ?indicates to trigger a scheduled task at 00:00:00 every day.
The development environment contains a few business servers. At the early stage of development, if you use a Cron expression similar to
* 0/1 * * * ?, scheduled tasks will be triggered at a high frequency, that is, once every minute. If any business server fails, restarts, or has new code deployed, the message receiving capability may be insufficient due to the limited number of servers. As a result, a large number of messages will fail to be delivered. In addition, due to the high reliability of SOFAMQ, these messages will be retried continuously in several days.
In the scenario described above, the Cron expression wastes server resources. In addition, too many messages will lead to unexpected charges and affect the stability of the development environment. Therefore, we recommend that you set a Cron expression similar to
0 0 0 * * ?, which triggers scheduled tasks at a low frequency. You can manually trigger the scheduled tasks during joint debugging and then adjust the trigger frequency to a desired one during stability testing.