Skip to content

Commit

Permalink
Merge pull request #113 from zero88/schedulerx/release/2.0.0-rc.1
Browse files Browse the repository at this point in the history
Release v2.0.0-rc.1
  • Loading branch information
zero88 committed Jan 18, 2024
2 parents b86bf94 + 5abf11c commit 8d411c2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 174 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ jobs:

publish:
uses: zero88/shared-ghactions/.github/workflows/gradle-publish.yml@main
needs: [ context, test, webdocs ]
needs: [ context, test, docs ]
if: needs.context.outputs.shouldPublish == 'true'
with:
profile: 'schedulerx'
Expand All @@ -109,7 +109,7 @@ jobs:

release:
runs-on: ubuntu-latest
needs: [ context, publish ]
needs: [ context, webdocs, publish ]
if: needs.context.outputs.isRelease == 'true'
steps:
- name: Create GitHub Release
Expand Down
173 changes: 3 additions & 170 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -16,175 +16,8 @@ image:https://sonarcloud.io/api/project_badges/measure?project={sonarKey}&metric
image:https://sonarcloud.io/api/project_badges/measure?project={sonarKey}&metric=security_rating[Security Rating,link=https://sonarcloud.io/dashboard?id={sonarKey}]
image:https://sonarcloud.io/api/project_badges/measure?project={sonarKey}&metric=alert_status[Quality Gate Status,link=https://sonarcloud.io/dashboard?id={sonarKey}]

A `lightweight plugable scheduler` based on plain https://vertx.io/[Vert.x] core without any external libs for scheduling with _cron-style_ and _interval_ timers with a detail _monitor_ on both sync and async job.
A pluggable `lightweight scheduler` based on plain https://vertx.io/[Vert.x] core without any external libs for scheduling on *time-based*: _cron_ and _interval_ or on *event-based*.

* `Scheduling` with:
* `cron-style` based on http://www.quartz-scheduler.org/[Quartz] - `Unix` cron expression and `timezone` available
on `JVM`
* `interval` with given `time interval`, given `initial delay time` and `repeating` a given number of times or
repeating infinitely
* able to `cancel` schedule event
* Support `synchronize` job and `async` job
* Run on `vertx-worker-thread` or dedicated `vertx thread-pool`
* Monitor `executor event` includes `fire counting`, `fired round`, `event time`, `job result data`, `job error` on
your need such as `on schedule`, `on misfire`, `on each round`, `on completed`, etc…
* Easy customize your `job` such as `HTTP client job`, `EventBus job`, `MQTT client job`, `database job`, etc…
`Scheduler.x` follows an event-driven architecture.

== Usage

=== Maven Dependency

[source,xml]
----
<dependency>
<groupId>io.github.zero88</groupId>
<artifactId>scheduler.x</artifactId>
<version>1.0.0</version>
</dependency>
----

=== Gradle Dependency

[source,groovy]
----
api("io.github.zero88:schedulerx:1.0.0")
----

== How To

=== Creating an executor

[source,java]
----
IntervalTaskExecutor.builder()
.vertx(vertx)
.trigger(IntervalTrigger.builder().interval(1).repeat(10).build())
.job((jobData, ctx) -> {
if(ctx.round()==5) {
ctx.forceStopExecution();
}
})
.build()
.start()
----

[source,java]
----
CronTaskExecutor.builder()
.vertx(vertx)
.trigger(CronTrigger.builder().expression("0/5 * * ? * * *").build())
.job((jobData, ctx) -> {})
.build()
.start(vertx.createSharedWorkerExecutor("TEST_CRON",3));
----

=== Monitor

Please
check https://github.com/zero88/scheduler.x/blob/62d8feb265f45afad2626886c24f2899346f46b1/src/main/java/io/github/zero88/vertx/scheduler/TaskExecutorMonitor.java[TaskExecutorMonitor]
. Example:

[source,java]
----
public interface TaskExecutorLogMonitor extends TaskExecutorMonitor {
Logger LOGGER = LoggerFactory.getLogger(TaskExecutorLogMonitor.class);
TaskExecutorMonitor LOG_MONITOR = new TaskExecutorLogMonitor() {};
@Override
default void onUnableSchedule(@NotNull TaskResult result) {
LOGGER.error("Unable schedule job at [{}] due to error", result.unscheduledAt(), result.error());
}
@Override
default void onSchedule(@NotNull TaskResult result) {
if (result.isReschedule()) {
LOGGER.debug("TaskExecutor is rescheduled at [{}] round [{}]", result.rescheduledAt(), result.round());
} else {
LOGGER.debug("TaskExecutor is available at [{}]", result.availableAt());
}
}
@Override
default void onMisfire(@NotNull TaskResult result) {
LOGGER.debug("Misfire tick [{}] at [{}]", result.tick(), result.triggeredAt());
}
@Override
default void onEach(@NotNull TaskResult result) {
LOGGER.debug("Finish round [{}] - Is Error [{}] | Executed at [{}] - Finished at [{}]", result.round(),
result.isError(), result.executedAt(), result.finishedAt());
}
@Override
default void onCompleted(@NotNull TaskResult result) {
LOGGER.debug("Completed job in round [{}] at [{}]", result.round(), result.completedAt());
}
}
----

=== Custom job

Please
check https://github.com/zero88/scheduler.x/blob/62d8feb265f45afad2626886c24f2899346f46b1/src/test/java/io/github/zero88/vertx/scheduler/custom/HttpClientTask.java[HttpClientTask]
and
its https://github.com/zero88/scheduler.x/blob/62d8feb265f45afad2626886c24f2899346f46b1/src/test/java/io/github/zero88/vertx/scheduler/custom/HttpClientTaskTest.java[test]
for `async` job

[source,java]
----
public class HttpClientTask implements Task {
@Override
public boolean isAsync() {
return true;
}
@Override
public void execute(@NotNull JobData jobData, @NotNull TaskExecutionContext executionContext) {
final Vertx vertx = executionContext.vertx();
JsonObject url = (JsonObject) jobData.get();
vertx.createHttpClient().request(HttpMethod.GET, url.getString("host"), url.getString("path"), ar1 -> {
if (ar1.succeeded()) {
HttpClientRequest request = ar1.result();
request.send(ar2 -> {
if (ar2.succeeded()) {
HttpClientResponse response = ar2.result();
response.body(ar3 -> {
if (ar3.succeeded()) {
executionContext.complete(new JsonObject().put("status", response.statusCode())
.put("response", ar3.result().toJson()));
} else {
executionContext.fail(ar3.cause());
}
});
} else {
executionContext.fail(ar2.cause());
}
});
} else {
executionContext.fail(ar1.cause());
}
});
}
}
----

== TODO

* [ ] Cron job with repeating until a given time / date
* [ ] Async query job data in execution
* [ ] Optimize `CronExpression`

== Disclaim and Disclosure

This is lightweight module then I will not support for adding any rich function like `manage group of job/trigger`
, `publish monitor event` by integrate with a fantastic client such as `Vertx EventBus`, etc…

I'm planning to do it in `vertx-planner` project later. Stay a tune!!!
Please check out full documentation at https://zero88.github.io/jooqx-webdocs/schedulerx/main/index.html[web-docs]
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ title=Scheduler.x
description=A scheduler based on plain Vertx promise/future/periodic/timer
projectGroup=io.github.zero88
projectLicense=The Apache License, Version 2.0
version=2.0.0
version=2.0.0-rc.1
semanticVersion=-SNAPSHOT
buildBy=local
buildHash=
Expand All @@ -31,7 +31,7 @@ nexus.username=
nexus.password=
## --- Sonatype OSSRH
#ossrh.snapshot.url=https://oss.sonatype.org/content/repositories/snapshots/
ossrh.release.url=https://oss.sonatype.org/service/local/staging/deploy/maven2/
ossrh.release.url=https://oss.sonatype.org/service/local/
## --- GitHub Repo
github.repo=zero88/scheduler.x

Expand Down

0 comments on commit 8d411c2

Please sign in to comment.