All Products
Search
Document Center

SchedulerX:Script jobs

Last Updated:Jan 15, 2024

This topic describes how to create jobs by writing Shell, Python, or Go scripts.

Create a script job

Step 1: Select a script language

On the Task Management page, create a job. For more information, see Job management. In the Create task panel, set Task type to ScriptTask and select a language from the Script drop-down list The following languages are supported: Shell, Python, and Go.

Step 2: Write a script

You can directly write a script or copy and paste an existing script to the code input box.

image.png

Important

If you copy a script from a Windows system to a Linux system, set File format to unix.

Step 3: Select an executor

Agent

  • Before you proceed, make sure that a SchedulerX Agent is deployed to run the script. For more information, see Use the agent to connect an application to SchedulerX (Script or HTTP jobs).

  • Execution modes:

    • Stand-alone operation: If you deployed multiple SchedulerX Agents and set Execution mode to Stand-along mode, SchedulerX randomly selects a SchedulerX Agent to run the script each time.

    • Broadcast run: If you deployed multiple SchedulerX Agents and set Execution mode to Broadcast run, SchedulerX broadcasts the script to all the SchedulerX Agents to run. This setting is preferred in batch O&M scenarios.

    • For more information, see Sharding models for different programming languages.

Elastic Container Instance

  • Before you proceed, make sure that an application of the Elastic Container Instance type is created. For more information, see Step 1: Configure the parameters in the Basic configuration step.

  • Configurations of the elastic container instance:

    • Image: Enter the base image of the script job.

    • Image Pull Policy: You can set the value to Always, Never, or IfNotPresent.

    • CPU: Specify the number of CPUs.

    • Memory: Specify the memory size. Unit: GB.

    • Automatically Create EIP: Specify whether to enable automatic creation of elastic IP addresses (EIPs). If the elastic container instance needs to access the Internet and the security group of the application that runs on the elastic container instance does not provide the Internet access permissions, you can enable this feature.

Demo

Shell

Built-in and custom parameters are supported.

Sample Shell job that uses built-in parameters

The following table describes the built-in parameters that are supported.

Parameter

Description

#{schedule.timestamp}

The point in time when the Shell job is scheduled to run.

#{data.timestamp}

The data timestamp of the job instance.

image.png

Sample Shell job that uses custom parameters

If you configure multiple custom parameters for a Shell job, separate the custom parameters with spaces. The first parameter is rendered by using $0 and the second parameter is rendered by using $1. If you have more parameters, follow the rule to render the parameters.

image.png

Python

image.png

Go

image.png