快速入门

引入maven依赖

  1. <!-- 引入elastic-job-cloud执行器模块 -->
  2. <dependency>
  3. <groupId>io.elasticjob</groupId>
  4. <artifactId>elastic-job-cloud-executor</artifactId>
  5. <version>${latest.release.version}</version>
  6. </dependency>

作业开发

  1. public class MyElasticJob implements SimpleJob {
  2. @Override
  3. public void execute(ShardingContext context) {
  4. switch (context.getShardingItem()) {
  5. case 0:
  6. // do something by sharding item 0
  7. break;
  8. case 1:
  9. // do something by sharding item 1
  10. break;
  11. case 2:
  12. // do something by sharding item 2
  13. break;
  14. // case n: ...
  15. }
  16. }
  17. }

Java启动方式

需定义Main方法并调用JobBootstrap.execute(),例子如下:

  1. public class JobDemo {
  2. public static void main(final String[] args) {
  3. JobBootstrap.execute();
  4. }
  5. }

打包作业

tar -cvf yourJobs.tar.gz yourJobs

发布APP

  1. curl -l -H "Content-type: application/json" -X POST -d '{"appName":"foo_app","appURL":"http://app_host:8080/yourJobs.tar.gz","cpuCount":0.1,"memoryMB":64.0,"bootstrapScript":"bin/start.sh","appCacheEnable":true,"eventTraceSamplingCount":0}' http://elastic_job_cloud_host:8899/api/app

发布作业

  1. curl -l -H "Content-type: application/json" -X POST -d '{"jobName":"foo_job","appName":"foo_app","jobClass":"yourJobClass","jobType":"SIMPLE","jobExecutionType":"TRANSIENT","cron":"0/5 * * * * ?","shardingTotalCount":3,"cpuCount":0.1,"memoryMB":64.0}' http://elastic_job_cloud_host:8899/api/job/register

详细的开发方式请参考开发指南