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:37:21 UTC
[shardingsphere-elasticjob] branch master updated: Update
job-listener doc (#1129)
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 dfea320 Update job-listener doc (#1129)
dfea320 is described below
commit dfea3200a4e974b6dfe7ba1f8496700a560f36aa
Author: Liang Zhang <te...@163.com>
AuthorDate: Sat Jul 18 15:37:11 2020 +0800
Update job-listener doc (#1129)
---
.../usage/job-api/spring-namespace.cn.md | 8 +-
.../usage/job-api/spring-namespace.en.md | 2 +-
.../usage/job-listener/_index.cn.md | 6 +-
.../usage/job-listener/java-api.cn.md | 51 ++++++++++
.../job-listener/{_index.cn.md => java-api.en.md} | 2 +-
.../usage/job-listener/job-listener.cn.md | 103 ---------------------
.../usage/job-listener/listener-interface.cn.md | 51 ++++++++++
...job-listener.en.md => listener-interface.en.md} | 2 +-
.../usage/job-listener/spring-boot-starter.cn.md | 7 ++
.../usage/job-listener/spring-boot-starter.en.md | 7 ++
.../spring-namespace.cn.md | 25 ++---
.../usage/job-listener/spring-namespace.en.md | 7 ++
12 files changed, 143 insertions(+), 128 deletions(-)
diff --git a/docs/content/user-manual/elasticjob-lite/usage/job-api/spring-namespace.cn.md b/docs/content/user-manual/elasticjob-lite/usage/job-api/spring-namespace.cn.md
index 1ebbef7..8b9ab5d 100644
--- a/docs/content/user-manual/elasticjob-lite/usage/job-api/spring-namespace.cn.md
+++ b/docs/content/user-manual/elasticjob-lite/usage/job-api/spring-namespace.cn.md
@@ -20,17 +20,17 @@ ElasticJob-Lite 提供自定义的 Spring 命名空间,可以与 Spring 容器
http://shardingsphere.apache.org/schema/elasticjob/elasticjob.xsd
">
<!--配置作业注册中心 -->
- <elasticjob:zookeeper id="regCenter" server-lists="yourhost:2181" namespace="dd-job" base-sleep-time-milliseconds="1000" max-sleep-time-milliseconds="3000" max-retries="3" />
+ <elasticjob:zookeeper id="regCenter" server-lists="yourhost:2181" namespace="my-job" base-sleep-time-milliseconds="1000" max-sleep-time-milliseconds="3000" max-retries="3" />
- <!-- 配置作业 Bean-->
+ <!-- 配置作业 Bean -->
<bean id="myJob" class="xxx.MyJob">
<property name="fooService" ref="xxx.FooService" />
</bean>
- <!-- 配置基于 class 的作业调度-->
+ <!-- 配置基于 class 的作业调度 -->
<elasticjob:job id="${myJob.id}" job-ref="myJob" registry-center-ref="regCenter" sharding-total-count="${myJob.shardingTotalCount}" cron="${myJob.cron}" />
- <!-- 配置基于 type 的作业调度-->
+ <!-- 配置基于 type 的作业调度 -->
<elasticjob:job id="${myScriptJob.id}" job-type="SCRIPT" registry-center-ref="regCenter" sharding-total-count="${myScriptJob.shardingTotalCount}" cron="${myScriptJob.cron}">
<props>
<prop key="script.command.line">${myScriptJob.scriptCommandLine}</prop>
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 68a45e4..6c9d969 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
@@ -20,7 +20,7 @@ Through the way of DI (Dependency Injection), developers can easily use data sou
http://shardingsphere.apache.org/schema/elasticjob/elasticjob.xsd
">
<!-- Configure registry center for job -->
- <elasticjob:zookeeper id="regCenter" server-lists="yourhost:2181" namespace="dd-job" base-sleep-time-milliseconds="1000" max-sleep-time-milliseconds="3000" max-retries="3" />
+ <elasticjob:zookeeper id="regCenter" server-lists="yourhost:2181" namespace="my-job" base-sleep-time-milliseconds="1000" max-sleep-time-milliseconds="3000" max-retries="3" />
<!-- Configure job java bean -->
<bean id="myJob" class="xxx.MyJob">
diff --git a/docs/content/user-manual/elasticjob-lite/usage/job-listener/_index.cn.md b/docs/content/user-manual/elasticjob-lite/usage/job-listener/_index.cn.md
index d563e63..3ed22b2 100644
--- a/docs/content/user-manual/elasticjob-lite/usage/job-listener/_index.cn.md
+++ b/docs/content/user-manual/elasticjob-lite/usage/job-listener/_index.cn.md
@@ -4,4 +4,8 @@ weight = 2
chapter = true
+++
-TODO
+ElasticJob-Lite 提供作业监听器,用于在任务执行前和执行后执行监听的方法。
+监听器分为每台作业节点均执行的常规监听器和分布式场景中仅单一节点执行的分布式监听器。
+本章节将详细介绍他们的使用方式。
+
+在作业依赖(DAG)功能开发完成之后,可能会考虑删除作业监听器功能。
diff --git a/docs/content/user-manual/elasticjob-lite/usage/job-listener/java-api.cn.md b/docs/content/user-manual/elasticjob-lite/usage/job-listener/java-api.cn.md
new file mode 100644
index 0000000..17247e8
--- /dev/null
+++ b/docs/content/user-manual/elasticjob-lite/usage/job-listener/java-api.cn.md
@@ -0,0 +1,51 @@
++++
+title = "使用 Java API"
+weight = 2
+chapter = true
++++
+
+## 常规监听器
+
+```java
+public class JobMain {
+
+ public static void main(String[] args) {
+ new ScheduleJobBootstrap(createRegistryCenter(), createJobConfiguration(), new MyElasticJobListener()).schedule();
+ }
+
+ private static CoordinatorRegistryCenter createRegistryCenter() {
+ CoordinatorRegistryCenter regCenter = new ZookeeperRegistryCenter(new ZookeeperConfiguration("zk_host:2181", "elastic-job-demo"));
+ regCenter.init();
+ return regCenter;
+ }
+
+ private static JobConfiguration createJobConfiguration() {
+ // 创建作业配置
+ ...
+ }
+}
+```
+
+## 分布式监听器
+
+```java
+public class JobMain {
+
+ public static void main(String[] args) {
+ long startTimeoutMills = 5000L;
+ long completeTimeoutMills = 10000L;
+ new ScheduleJobBootstrap(createRegistryCenter(), createJobConfiguration(), new MyDistributeOnceElasticJobListener(startTimeoutMills, completeTimeoutMills)).schedule();
+ }
+
+ private static CoordinatorRegistryCenter createRegistryCenter() {
+ CoordinatorRegistryCenter regCenter = new ZookeeperRegistryCenter(new ZookeeperConfiguration("zk_host:2181", "elastic-job-demo"));
+ regCenter.init();
+ return regCenter;
+ }
+
+ private static JobConfiguration createJobConfiguration() {
+ // 创建作业配置
+ ...
+ }
+}
+```
diff --git a/docs/content/user-manual/elasticjob-lite/usage/job-listener/_index.cn.md b/docs/content/user-manual/elasticjob-lite/usage/job-listener/java-api.en.md
similarity index 60%
copy from docs/content/user-manual/elasticjob-lite/usage/job-listener/_index.cn.md
copy to docs/content/user-manual/elasticjob-lite/usage/job-listener/java-api.en.md
index d563e63..a9876e7 100644
--- a/docs/content/user-manual/elasticjob-lite/usage/job-listener/_index.cn.md
+++ b/docs/content/user-manual/elasticjob-lite/usage/job-listener/java-api.en.md
@@ -1,5 +1,5 @@
+++
-title = "作业监听器"
+title = "Use Java API"
weight = 2
chapter = true
+++
diff --git a/docs/content/user-manual/elasticjob-lite/usage/job-listener/job-listener.cn.md b/docs/content/user-manual/elasticjob-lite/usage/job-listener/job-listener.cn.md
deleted file mode 100644
index 1f287f5..0000000
--- a/docs/content/user-manual/elasticjob-lite/usage/job-listener/job-listener.cn.md
+++ /dev/null
@@ -1,103 +0,0 @@
-+++
-title = "作业监听器"
-weight = 1
-chapter = true
-+++
-
-可通过配置多个任务监听器,在任务执行前和执行后执行监听的方法。监听器分为每台作业节点均执行和分布式场景中仅单一节点执行2种。
-
-## 1. 每台作业节点均执行的监听
-若作业处理作业服务器的文件,处理完成后删除文件,可考虑使用每个节点均执行清理任务。此类型任务实现简单,且无需考虑全局分布式任务是否完成,请尽量使用此类型监听器。
-
-步骤:
-
-* 定义监听器
-
-```java
-
-public class MyElasticJobListener implements ElasticJobListener {
-
- @Override
- public void beforeJobExecuted(ShardingContexts shardingContexts) {
- // do something ...
- }
-
- @Override
- public void afterJobExecuted(ShardingContexts shardingContexts) {
- // do something ...
- }
-}
-```
-
-* 将监听器作为参数传入JobScheduler
-
-```java
-public class JobMain {
-
- public static void main(String[] args) {
- new JobScheduler(createRegistryCenter(), createJobConfiguration(), new MyElasticJobListener()).init();
- }
-
- private static CoordinatorRegistryCenter createRegistryCenter() {
- CoordinatorRegistryCenter regCenter = new ZookeeperRegistryCenter(new ZookeeperConfiguration("zk_host:2181", "elastic-job-demo"));
- regCenter.init();
- return regCenter;
- }
-
- private static JobConfiguration createJobConfiguration() {
- // 创建作业配置
- ...
- }
-}
-```
-
-## 2. 分布式场景中仅单一节点执行的监听
-若作业处理数据库数据,处理完成后只需一个节点完成数据清理任务即可。此类型任务处理复杂,需同步分布式环境下作业的状态同步,提供了超时设置来避免作业不同步导致的死锁,请谨慎使用。
-
-步骤:
-
-* 定义监听器
-
-```java
-
-public class TestDistributeOnceElasticJobListener extends AbstractDistributeOnceElasticJobListener {
-
- public TestDistributeOnceElasticJobListener(long startTimeoutMills, long completeTimeoutMills) {
- super(startTimeoutMills, completeTimeoutMills);
- }
-
- @Override
- public void doBeforeJobExecutedAtLastStarted(ShardingContexts shardingContexts) {
- // do something ...
- }
-
- @Override
- public void doAfterJobExecutedAtLastCompleted(ShardingContexts shardingContexts) {
- // do something ...
- }
-}
-```
-
-* 将监听器作为参数传入JobScheduler
-
-```java
-public class JobMain {
-
- public static void main(String[] args) {
- long startTimeoutMills = 5000L;
- long completeTimeoutMills = 10000L;
- new JobScheduler(createRegistryCenter(), createJobConfiguration(), new MyDistributeOnceElasticJobListener(startTimeoutMills, completeTimeoutMills)).init();
- }
-
- private static CoordinatorRegistryCenter createRegistryCenter() {
- CoordinatorRegistryCenter regCenter = new ZookeeperRegistryCenter(new ZookeeperConfiguration("zk_host:2181", "elastic-job-demo"));
- regCenter.init();
- return regCenter;
- }
-
- private static JobConfiguration createJobConfiguration() {
- // 创建作业配置
- ...
- }
-}
-```
diff --git a/docs/content/user-manual/elasticjob-lite/usage/job-listener/listener-interface.cn.md b/docs/content/user-manual/elasticjob-lite/usage/job-listener/listener-interface.cn.md
new file mode 100644
index 0000000..1d423fb
--- /dev/null
+++ b/docs/content/user-manual/elasticjob-lite/usage/job-listener/listener-interface.cn.md
@@ -0,0 +1,51 @@
++++
+title = "监听器开发"
+weight = 1
+chapter = true
++++
+
+## 常规监听器
+
+若作业处理作业服务器的文件,处理完成后删除文件,可考虑使用每个节点均执行清理任务。
+此类型任务实现简单,且无需考虑全局分布式任务是否完成,应尽量使用此类型监听器。
+
+```java
+
+public class MyJobListener implements ElasticJobListener {
+
+ @Override
+ public void beforeJobExecuted(ShardingContexts shardingContexts) {
+ // do something ...
+ }
+
+ @Override
+ public void afterJobExecuted(ShardingContexts shardingContexts) {
+ // do something ...
+ }
+}
+```
+
+## 分布式监听器
+
+若作业处理数据库数据,处理完成后只需一个节点完成数据清理任务即可。
+此类型任务处理复杂,需同步分布式环境下作业的状态同步,提供了超时设置来避免作业不同步导致的死锁,应谨慎使用。
+
+```java
+
+public class MyDistributeOnceJobListener extends AbstractDistributeOnceElasticJobListener {
+
+ public TestDistributeOnceElasticJobListener(long startTimeoutMills, long completeTimeoutMills) {
+ super(startTimeoutMills, completeTimeoutMills);
+ }
+
+ @Override
+ public void doBeforeJobExecutedAtLastStarted(ShardingContexts shardingContexts) {
+ // do something ...
+ }
+
+ @Override
+ public void doAfterJobExecutedAtLastCompleted(ShardingContexts shardingContexts) {
+ // do something ...
+ }
+}
+```
diff --git a/docs/content/user-manual/elasticjob-lite/usage/job-listener/job-listener.en.md b/docs/content/user-manual/elasticjob-lite/usage/job-listener/listener-interface.en.md
similarity index 56%
rename from docs/content/user-manual/elasticjob-lite/usage/job-listener/job-listener.en.md
rename to docs/content/user-manual/elasticjob-lite/usage/job-listener/listener-interface.en.md
index ef373a9..a72ef66 100644
--- a/docs/content/user-manual/elasticjob-lite/usage/job-listener/job-listener.en.md
+++ b/docs/content/user-manual/elasticjob-lite/usage/job-listener/listener-interface.en.md
@@ -1,5 +1,5 @@
+++
-title = "Job Listener"
+title = "Listener Development"
weight = 1
chapter = true
+++
diff --git a/docs/content/user-manual/elasticjob-lite/usage/job-listener/spring-boot-starter.cn.md b/docs/content/user-manual/elasticjob-lite/usage/job-listener/spring-boot-starter.cn.md
new file mode 100644
index 0000000..1ae7bd7
--- /dev/null
+++ b/docs/content/user-manual/elasticjob-lite/usage/job-listener/spring-boot-starter.cn.md
@@ -0,0 +1,7 @@
++++
+title = "Spring Boot Starter"
+weight = 3
+chapter = true
++++
+
+TODO
diff --git a/docs/content/user-manual/elasticjob-lite/usage/job-listener/spring-boot-starter.en.md b/docs/content/user-manual/elasticjob-lite/usage/job-listener/spring-boot-starter.en.md
new file mode 100644
index 0000000..1ae7bd7
--- /dev/null
+++ b/docs/content/user-manual/elasticjob-lite/usage/job-listener/spring-boot-starter.en.md
@@ -0,0 +1,7 @@
++++
+title = "Spring Boot Starter"
+weight = 3
+chapter = true
++++
+
+TODO
diff --git a/docs/content/user-manual/elasticjob-lite/usage/job-api/spring-namespace.cn.md b/docs/content/user-manual/elasticjob-lite/usage/job-listener/spring-namespace.cn.md
similarity index 51%
copy from docs/content/user-manual/elasticjob-lite/usage/job-api/spring-namespace.cn.md
copy to docs/content/user-manual/elasticjob-lite/usage/job-listener/spring-namespace.cn.md
index 1ebbef7..a36dbde 100644
--- a/docs/content/user-manual/elasticjob-lite/usage/job-api/spring-namespace.cn.md
+++ b/docs/content/user-manual/elasticjob-lite/usage/job-listener/spring-namespace.cn.md
@@ -4,10 +4,7 @@ weight = 4
chapter = true
+++
-ElasticJob-Lite 提供自定义的 Spring 命名空间,可以与 Spring 容器配合使用。
-开发者能够便捷的在作业中通过依赖注入使用 Spring 容器管理的数据源等对象,并使用占位符从属性文件中取值。
-
-## 作业配置
+## 监听器配置
```xml
<?xml version="1.0" encoding="UTF-8"?>
@@ -20,21 +17,15 @@ ElasticJob-Lite 提供自定义的 Spring 命名空间,可以与 Spring 容器
http://shardingsphere.apache.org/schema/elasticjob/elasticjob.xsd
">
<!--配置作业注册中心 -->
- <elasticjob:zookeeper id="regCenter" server-lists="yourhost:2181" namespace="dd-job" base-sleep-time-milliseconds="1000" max-sleep-time-milliseconds="3000" max-retries="3" />
-
- <!-- 配置作业 Bean-->
- <bean id="myJob" class="xxx.MyJob">
- <property name="fooService" ref="xxx.FooService" />
- </bean>
+ <elasticjob:zookeeper id="regCenter" server-lists="yourhost:2181" namespace="my-job" base-sleep-time-milliseconds="1000" max-sleep-time-milliseconds="3000" max-retries="3" />
- <!-- 配置基于 class 的作业调度-->
- <elasticjob:job id="${myJob.id}" job-ref="myJob" registry-center-ref="regCenter" sharding-total-count="${myJob.shardingTotalCount}" cron="${myJob.cron}" />
+ <!-- 配置作业 Bean -->
+ <bean id="myJob" class="xxx.MyJob" />
- <!-- 配置基于 type 的作业调度-->
- <elasticjob:job id="${myScriptJob.id}" job-type="SCRIPT" registry-center-ref="regCenter" sharding-total-count="${myScriptJob.shardingTotalCount}" cron="${myScriptJob.cron}">
- <props>
- <prop key="script.command.line">${myScriptJob.scriptCommandLine}</prop>
- </props>
+ <elasticjob:job id="${myJob.id}" job-ref="myJob" registry-center-ref="regCenter" sharding-total-count="3" cron="0/1 * * * * ?">
+ <!-- 配置作业监听器 -->
+ <elasticjob:listener class="xxx.MyJobListener" />
+ <elasticjob:distributed-listener class="xxx.MyDistributeOnceJobListener" started-timeout-milliseconds="10000" completed-timeout-milliseconds="20000" />
</elasticjob:job>
</beans>
```
diff --git a/docs/content/user-manual/elasticjob-lite/usage/job-listener/spring-namespace.en.md b/docs/content/user-manual/elasticjob-lite/usage/job-listener/spring-namespace.en.md
new file mode 100644
index 0000000..6046e87
--- /dev/null
+++ b/docs/content/user-manual/elasticjob-lite/usage/job-listener/spring-namespace.en.md
@@ -0,0 +1,7 @@
++++
+title = "Spring Namespace"
+weight = 4
+chapter = true
++++
+
+TODO