You can use Serverless Application Engine (SAE) to create a Job template. This template lets you run tasks on a schedule or trigger them manually by sending an HTTP/HTTPS request. After a task is complete, the associated compute resources are automatically released.
Scenarios
Jobs are suitable for asynchronous, offline scenarios that are not sensitive to latency. You can run them once or on a recurring schedule. For example, you can use a Job to generate batch statistical reports or send coupons at a specific time.
Preparations
Ensure that you have activated Serverless Application Engine and EventBridge and granted the required permissions.
Run a Job periodically
On the SAE Job Templates page, select the destination region and namespace, and then click Create Job Template. Configure the following parameters.
Enter a Task Template Name.
For Task Deployment Method, select Select Image Deployment. You can use the default Demo image. In a real-world scenario, you can click Set Image to specify a custom image for the task execution.
Keep the default settings for the other parameters and click Next.
In the Task Settings section, configure the following parameters.
For Task Type, select Periodic Task.
Set Cron Expression to
*/1 * * * ?. This expression means the task is executed once per minute.Keep the default settings for the other parameters and click Create. Then, wait for the task to be created.
In the navigation pane on the left, click Task History. You can view the execution records of the periodic task. Click the refresh button in the upper-right corner of the page to view the latest results.
In the navigation pane on the left, choose . You can view the execution result of the most recent task. In this example, the program prints a string of numbers to the console.
Trigger a one-time Job with an HTTP/HTTPS request
On the SAE Job Templates page, select the destination region and namespace, and then click Create Job Template. Configure the following parameters.
Enter a Task Template Name.
For Deployment Method, select Image Deployment. You can use the default demo image. In a real-world scenario, you can click Set Image to specify a custom image for the task execution.
Keep the default settings for the other parameters and click Next.
In the Task Settings section, configure the following parameters.
Set Task Type to Manually Triggered Node Instance.
For Request Type, select HTTP&HTTPS. This allows the task to be triggered by both HTTP and HTTPS requests.
For Request Method, select GET and POST. This allows the task to be triggered by both GET and POST requests.
Keep the default settings for the other parameters and click Create. Then, wait for the task to be created.
On the Job Template Details page, go to the Task Settings section and copy the Public Request URL. To trigger the task, paste the URL into the address bar of your browser and press Enter.
In the navigation pane on the left, click Task History. You can view the execution record of the one-time task. Click the refresh button in the upper-right corner of the page to view the latest results.
In the navigation pane on the left, choose . You can view the execution result of the most recent task. In this example, the program prints a string of numbers to the console.
Clean up resources
After you complete this tutorial, delete the resources that you created to avoid incurring unnecessary fees.
On the SAE Job Templates page, select the destination region and namespace, find the Job template that you created, click Delete in the Actions column, and then follow the on-screen instructions.
What to do next
In a real-world scenario, you can create a Job template using an application image, a code package, or a Shell script. For more information, see Manage job templates.