You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2020/07/18 07:33:20 UTC

[shardingsphere-elasticjob] branch master updated: translate user manual, job-interface for job-api. (#1127)

This is an automated email from the ASF dual-hosted git repository.

zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere-elasticjob.git


The following commit(s) were added to refs/heads/master by this push:
     new 13029bd  translate user manual, job-interface for job-api. (#1127)
13029bd is described below

commit 13029bda13e8a792f1a1e8cb0630ad74ad9adc94
Author: Zonglei Dong <do...@apache.org>
AuthorDate: Sat Jul 18 15:33:11 2020 +0800

    translate user manual, job-interface for job-api. (#1127)
    
    * translate user manual, job-interface for job-api.
    
    * fix document title.
---
 .../usage/job-api/job-interface.en.md              | 101 ++++++++++++++++++++-
 .../usage/job-api/spring-namespace.en.md           |   2 +-
 2 files changed, 101 insertions(+), 2 deletions(-)

diff --git a/docs/content/user-manual/elasticjob-lite/usage/job-api/job-interface.en.md b/docs/content/user-manual/elasticjob-lite/usage/job-api/job-interface.en.md
index 41d1143..23be4b9 100644
--- a/docs/content/user-manual/elasticjob-lite/usage/job-api/job-interface.en.md
+++ b/docs/content/user-manual/elasticjob-lite/usage/job-api/job-interface.en.md
@@ -4,4 +4,103 @@ weight = 1
 chapter = true
 +++
 
-TODO
+ElasticJob-Lite and ElasticJob-Cloud provide a unified job interface, developers need to develop business jobs only once, and then they can be deployed to different environments according to different configurations and deployments.
+
+ElasticJob has two kinds of job types: Class-based job and Type-based job.
+Class-based jobs require developers to weave business logic by implementing interfaces;
+Type-based jobs don't need coding, just need to provide the corresponding configuration.
+
+The method parameter `shardingContext` of the class-based job interface contains job configuration, slice and runtime information.
+Through methods such as `getShardingTotalCount()`, `getShardingItem()`, user can obtain the total number of shards, the serial number of the shards running on the job server, etc.
+
+ElasticJob provides two class-based job types which are `Simple` and `Dataflow`; and also provides a type-based job which is `Script`. Users can extend job types by implementing the SPI interface.
+
+## Simple job
+
+It means simple implementation, without any encapsulation type. Need to implement `SimpleJob` interface.
+This interface only provides a single method for coverage, and this method will be executed periodically.
+It is similar to Quartz's native interface, but provides functions such as elastic scaling and slice.
+
+```java
+public class MyElasticJob 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: ...
+        }
+    }
+}
+```
+
+## Dataflow Job
+
+For processing data flow, need to implement `DataflowJob` interface.
+This interface provides two methods for coverage, which are used to fetch (fetchData) and process (processData) data.
+
+```java
+public class MyElasticJob implements DataflowJob<Foo> {
+    
+    @Override
+    public List<Foo> fetchData(ShardingContext context) {
+        switch (context.getShardingItem()) {
+            case 0: 
+                List<Foo> data = // get data from database by sharding item 0
+                return data;
+            case 1: 
+                List<Foo> data = // get data from database by sharding item 1
+                return data;
+            case 2: 
+                List<Foo> data = // get data from database by sharding item 2
+                return data;
+            // case n: ...
+        }
+    }
+    
+    @Override
+    public void processData(ShardingContext shardingContext, List<Foo> data) {
+        // process data
+        // ...
+    }
+}
+```
+
+***
+
+**Streaming**
+
+Streaming can be enabled or disabled through the property `streaming.process`.
+
+If streaming is enabled, the job will stop fetching data only when the return value of the `fetchData` method is null or the collection is empty, otherwise the job will continue to run;
+If streaming is disabled, the job will execute the `fetchData` and `processData` methods only once during each job execution, and then the job will be completed immediately.
+
+If use the streaming job to process data, it is recommended to update its status after the `processData` method being executed, to avoid being fetched again by the method `fetchData`, so that the job never stops.
+
+## Script job
+
+Support all types of scripts such as `shell`, `python`, `perl`.
+The script to be executed can be configured through the property `script.command.line`, without coding.
+The script path can contain parameters, after the parameters are passed, the job framework will automatically append the last parameter as the job runtime information.
+
+The script example is as follows:
+
+```bash
+#!/bin/bash
+echo sharding execution context is $*
+```
+
+When the job runs, it will output:
+
+```
+sharding execution context is {"jobName":"scriptElasticDemoJob","shardingTotalCount":10,"jobParameter":"","shardingItem":0,"shardingParameter":"A"}
+```
+
diff --git a/docs/content/user-manual/elasticjob-lite/usage/job-api/spring-namespace.en.md b/docs/content/user-manual/elasticjob-lite/usage/job-api/spring-namespace.en.md
index 6fdf337..68a45e4 100644
--- a/docs/content/user-manual/elasticjob-lite/usage/job-api/spring-namespace.en.md
+++ b/docs/content/user-manual/elasticjob-lite/usage/job-api/spring-namespace.en.md
@@ -39,6 +39,6 @@ Through the way of DI (Dependency Injection), developers can easily use data sou
 </beans>
 ```
 
-## Start job
+## Job start
 
 If the Spring container start, the xml that configures the Spring namespace will be loaded, and the job will be automatically started.