Import Maven Dependency
<dependency>
<groupId>org.apache.shardingsphere.elasticjob</groupId>
<artifactId>elasticjob-cloud-executor</artifactId>
<version>${latest.release.version}</version>
</dependency>
Develop Job Details
public class MyJob implements SimpleJob {
@Override
public void execute(ShardingContext context) {
switch (context.getShardingItem()) {
case 0:
// do something by sharding item 0
break;
case 1:
// do something by sharding item 1
break;
case 2:
// do something by sharding item 2
break;
// case n: ...
}
}
}
Develop Job Bootstrap
Define main
method and call JobBootstrap.execute()
, example as follows:
public class MyJobDemo {
public static void main(final String[] args) {
JobBootstrap.execute(new MyJob());
}
}
Pack Job
tar -cvf my-job.tar.gz my-job
API Authentication
curl -H "Content-Type: application/json" -X POST http://elasticjob_cloud_host:8899/api/login -d '{"username": "root", "password": "pwd"}'
Response body:
{"accessToken":"some_token"}
Publish Job
curl -l -H "Content-type: application/json" -H "accessToken: some_token" -X POST -d '{"appName":"my_app","appURL":"http://app_host:8080/my-job.tar.gz","cpuCount":0.1,"memoryMB":64.0,"bootstrapScript":"bin/start.sh","appCacheEnable":true,"eventTraceSamplingCount":0}' http://elasticjob_cloud_host:8899/api/app
Schedule Job
curl -l -H "Content-type: application/json" -H "accessToken: some_token" -X POST -d '{"jobName":"my_job","appName":"my_app","jobExecutionType":"TRANSIENT","cron":"0/5 * * * * ?","shardingTotalCount":3,"cpuCount":0.1,"memoryMB":64.0}' http://elasticjob_cloud_host:8899/api/job/register
当前内容版权归 ElasticJob 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 ElasticJob .