Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[New Doc PR] - Helidon SE Scheduling documentation #4312 #4525

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 67 additions & 11 deletions docs/se/scheduling.adoc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
///////////////////////////////////////////////////////////////////////////////

Copyright (c) 2021, 2022 Oracle and/or its affiliates.
Copyright (c) 2021 Oracle and/or its affiliates.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -21,10 +21,25 @@
:toc-placement: preamble
:description: Scheduling in Helidon SE
:keywords: helidon, se, scheduling
:h1Prefix: SE
:feature-name: Scheduling
:rootdir: {docdir}/..

include::{rootdir}/includes/se.adoc[]

== ToC
dalexandrov marked this conversation as resolved.
Show resolved Hide resolved

- <<Overview, Overview>>
- <<Maven Coordinates, Maven Coordinates>>
- <<Usage, Usage>>
- <<Configuration, Configuration>>
- <<Examples, Examples>>
- <<Reference, Reference>>

== Overview

Scheduling is an essential feature for the Enterprise. Helidon has its own implementation of Scheduling functionality
based on https://github.com/jmrozanec/cron-utils[Cron-utils].

include::{rootdir}/includes/dependencies.adoc[]

[source,xml]
Expand All @@ -35,14 +50,14 @@ include::{rootdir}/includes/dependencies.adoc[]
</dependency>
----

== Scheduling
== Usage
For scheduling periodic tasks it is possible to choose fixed rate setup or Cron expression.
dalexandrov marked this conversation as resolved.
Show resolved Hide resolved

=== Fixed rate
For simple fixed rate invocation use .

[source,java]
.Example of scheduling with fixed rate use `Scheduling.fixedRateBuilder()` builder.
.Scheduling with fixed rate use `Scheduling.fixedRateBuilder()` builder.
----
Scheduling.fixedRateBuilder()
.delay(10)
Expand All @@ -56,7 +71,7 @@ Metadata like human-readable interval description or configured values are avail
FixedRateInvocation provided as task parameter.

[source,java]
.Example with invocation metadata
.Invocation metadata
----
Scheduling.fixedRateBuilder()
.delay(10)
Expand All @@ -70,24 +85,65 @@ For more complicated interval definition, cron expression can be leveraged with
`Scheduling.cronBuilder()` builder.

[source,java]
.Example of scheduling with cron expression
.Scheduling with cron expression
----
Scheduling.cronBuilder()
.expression("0 15 8 ? * *")
.task(inv -> System.out.println("Executer every day at 8:15"))
.build();
----

== Configuration

Configuration properties are added to `application.yaml` file:

.Configuration properties
[width="90%",cols="3,10",frame="topbot",options="header"]
|====
| Property | Description
| cron | String containing cron setup
| concurrent | Boolean, equivalent `concurrentExecution` property of `@Scheduled`. Default `true`.
|====

=== Cron expression

Cron expressions should be configured as follows.

include::{rootdir}/includes/cron.adoc[lines=19..]

Metadata like human-readable interval description or configured values are available through
CronInvocation provided as task parameter.

== Examples

=== Fixed rate
For simple fixed rate invocation use .
dalexandrov marked this conversation as resolved.
Show resolved Hide resolved

[source,java]
.Example of scheduling with fixed rate use `Scheduling.fixedRateBuilder()` builder.
----
Scheduling.fixedRateBuilder()
.delay(10)
.initialDelay(5)
.timeUnit(TimeUnit.MINUTES)
.task(inv -> System.out.println("Every 10 minutes, first invocation 5 minutes after start"))
.build();
----

Metadata like human-readable interval description or configured values are available through
FixedRateInvocation provided as task parameter.
dalexandrov marked this conversation as resolved.
Show resolved Hide resolved


[source,java]
.Example with invocation metadata
----
Scheduling.cronBuilder()
.expression("0 15 8 ? * *")
.task(inv -> System.out.println("Method invoked " + inv.description()))
.build();
----
Scheduling.fixedRateBuilder()
.delay(10)
.task(inv -> System.out.println("Method invoked " + inv.description()))
.build();
----

== Reference

* https://github.com/jmrozanec/cron-utils[Cron-utils GitHub page]
* link:{scheduling-javadoc-base-url}/io/helidon/microprofile/scheduling/package-summary.html[Helidon Scheduling JavaDoc]