JobContext parameters
更新时间:
复制 MD 格式
The JobContext object provides runtime information about the current job execution, including identifiers, scheduling times, retry state, sharding details, and upstream workflow data.
Basic usage
Access JobContext parameters through getter methods in your job handler:
public class SampleJobProcessor extends JavaProcessor {
@Override
public ProcessResult process(JobContext context) throws Exception {
// Job and instance identifiers
long jobId = context.getJobId();
long instanceId = context.getJobInstanceId();
// Scheduling metadata
DateTime scheduledTime = context.getScheduleTime();
DateTime dataTime = context.getDataTime();
// Static parameters configured in the SchedulerX console
String params = context.getJobParameters();
// Dynamic parameters passed through API calls
String dynamicParams = context.getInstanceParameters();
// Retry state
int currentAttempt = context.getAttempt();
int maxRetries = context.getMaxAttempt();
System.out.println("Job " + jobId + ", instance " + instanceId
+ ", attempt " + currentAttempt + "/" + maxRetries);
return new ProcessResult(true);
}
}Job and instance identifiers
| Parameter | Type | Description |
|---|---|---|
jobId | long | Job ID. |
jobInstanceId | long | Job instance ID. |
jobType | String | Job type. |
taskId | long | Task ID within a distributed job. The root task ID is 0. |
taskName | String | Task name. |
task | Object | Task body. |
Scheduling times
| Parameter | Type | Description |
|---|---|---|
scheduleTime | DateTime | Scheduled time of the instance. |
dataTime | DateTime | Time when the job is run on the instance. |
Job parameters
| Parameter | Type | Description |
|---|---|---|
jobParameters | String | Static parameters configured in the SchedulerX console. Maximum size: 10,000 bytes. |
instanceParameters | String | Dynamic parameters passed when an instance is triggered through an API call. |
Retry parameters
| Parameter | Type | Description |
|---|---|---|
maxAttempt | int | Maximum number of retries for the job instance. |
attempt | int | Current retry count for the job instance. |
taskMaxAttempt | int | Maximum number of retries for the task. |
taskAttempt | int | Current retry count for the task. |
Sharding parameters
Available only when Execution mode is set to Broadcast run or Shard run.
| Parameter | Type | Description |
|---|---|---|
shardingId | Long | Shard ID. Available in Broadcast run and Shard run modes. |
shardingParameter | String | Sharding parameter. Available only in Shard run mode. |
shardingNum | int | Total number of shards. Available in Broadcast run and Shard run modes. |
Example:
public class ShardJobProcessor extends JavaProcessor {
@Override
public ProcessResult process(JobContext context) throws Exception {
Long shardId = context.getShardingId();
int totalShards = context.getShardingNum();
String shardParam = context.getShardingParameter();
System.out.println("Processing shard " + shardId + " of " + totalShards);
return new ProcessResult(true);
}
}Workflow parameters
Available when the job runs as part of a workflow.
| Parameter | Type | Description |
|---|---|---|
workflowId | Long | Workflow ID. |
wfInstanceId | long | Workflow instance ID. |
upstreamData | List<JobInstanceData> | Data from upstream job instances in the workflow. A workflow may have multiple upstream instances, so this parameter returns a list. |
该文章对您有帮助吗?