Skip to content

Commit

Permalink
docs: Improve Examples (#420)
Browse files Browse the repository at this point in the history
I am currently incorporating DB-Scheduler into a project I am working on
(10000 onetimetasks processed per hour in an Oracle database). Thanks
for your awesome work!!

I decided to contribute something very modest back.

## Changes

* Removed ExampleHelpers.java: method sleep was unused, method
registerShutdownHook is replaced by registerShutdownHook in
SchedulerBuilder
* Add missing main method in RecurringTaskMain.java

## Reminders
- [-] Added/ran automated tests
- [-] Update README and/or examples
- [X] Ran `mvn spotless:apply`

---
cc @kagkarlsson
  • Loading branch information
cseewald committed Sep 16, 2023
1 parent c43024e commit e098bd2
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 72 deletions.
Expand Up @@ -13,10 +13,7 @@
*/
package com.github.kagkarlsson.examples;

import static com.github.kagkarlsson.examples.helpers.ExampleHelpers.sleep;

import com.github.kagkarlsson.examples.helpers.Example;
import com.github.kagkarlsson.examples.helpers.ExampleHelpers;
import com.github.kagkarlsson.scheduler.Scheduler;
import com.github.kagkarlsson.scheduler.task.helper.OneTimeTask;
import com.github.kagkarlsson.scheduler.task.helper.Tasks;
Expand All @@ -43,10 +40,9 @@ public void run(DataSource dataSource) {
Scheduler.create(dataSource, onetimeTask)
.pollingInterval(Duration.ofSeconds(10))
.threads(2)
.registerShutdownHook()
.build();

ExampleHelpers.registerShutdownHook(scheduler);

scheduler.start();

sleep(2);
Expand Down
Expand Up @@ -14,7 +14,6 @@
package com.github.kagkarlsson.examples;

import com.github.kagkarlsson.examples.helpers.Example;
import com.github.kagkarlsson.examples.helpers.ExampleHelpers;
import com.github.kagkarlsson.scheduler.Scheduler;
import com.github.kagkarlsson.scheduler.task.helper.RecurringTask;
import com.github.kagkarlsson.scheduler.task.helper.Tasks;
Expand Down Expand Up @@ -45,10 +44,9 @@ public void run(DataSource dataSource) {
Scheduler.create(dataSource)
.startTasks(cronTask)
.pollingInterval(Duration.ofSeconds(1))
.registerShutdownHook()
.build();

ExampleHelpers.registerShutdownHook(scheduler);

scheduler.start();
}
}
Expand Up @@ -14,7 +14,6 @@
package com.github.kagkarlsson.examples;

import com.github.kagkarlsson.examples.helpers.Example;
import com.github.kagkarlsson.examples.helpers.ExampleHelpers;
import com.github.kagkarlsson.scheduler.Scheduler;
import com.github.kagkarlsson.scheduler.SchedulerClient;
import com.github.kagkarlsson.scheduler.task.helper.RecurringTask;
Expand Down Expand Up @@ -56,10 +55,9 @@ public void run(DataSource dataSource) {
.pollingInterval(Duration.ofSeconds(1))
.heartbeatInterval(Duration.ofSeconds(5))
.deleteUnresolvedAfter(Duration.ofSeconds(20))
.registerShutdownHook()
.build();

ExampleHelpers.registerShutdownHook(scheduler);

scheduler.start();

IntStream.range(0, 5)
Expand Down
Expand Up @@ -13,10 +13,7 @@
*/
package com.github.kagkarlsson.examples;

import static com.github.kagkarlsson.examples.helpers.ExampleHelpers.sleep;

import com.github.kagkarlsson.examples.helpers.Example;
import com.github.kagkarlsson.examples.helpers.ExampleHelpers;
import com.github.kagkarlsson.scheduler.Scheduler;
import com.github.kagkarlsson.scheduler.task.helper.OneTimeTask;
import com.github.kagkarlsson.scheduler.task.helper.Tasks;
Expand Down Expand Up @@ -44,10 +41,9 @@ public void run(DataSource dataSource) {
Scheduler.create(dataSource, onetimeTask)
.pollingInterval(Duration.ofSeconds(20))
.enableImmediateExecution()
.registerShutdownHook()
.build();

ExampleHelpers.registerShutdownHook(scheduler);

scheduler.start();

sleep(2000);
Expand Down
Expand Up @@ -16,7 +16,6 @@
import static java.time.Duration.*;

import com.github.kagkarlsson.examples.helpers.Example;
import com.github.kagkarlsson.examples.helpers.ExampleHelpers;
import com.github.kagkarlsson.scheduler.Scheduler;
import com.github.kagkarlsson.scheduler.task.FailureHandler;
import com.github.kagkarlsson.scheduler.task.helper.OneTimeTask;
Expand All @@ -41,12 +40,13 @@ public void run(DataSource dataSource) {
});

final Scheduler scheduler =
Scheduler.create(dataSource, failingTask).pollingInterval(ofSeconds(2)).build();
Scheduler.create(dataSource, failingTask)
.pollingInterval(ofSeconds(2))
.registerShutdownHook()
.build();

scheduler.schedule(failingTask.instance("1"), Instant.now());

ExampleHelpers.registerShutdownHook(scheduler);

scheduler.start();
}
}
Expand Up @@ -16,7 +16,6 @@
import static java.time.Duration.ofSeconds;

import com.github.kagkarlsson.examples.helpers.Example;
import com.github.kagkarlsson.examples.helpers.ExampleHelpers;
import com.github.kagkarlsson.scheduler.Scheduler;
import com.github.kagkarlsson.scheduler.task.FailureHandler;
import com.github.kagkarlsson.scheduler.task.helper.OneTimeTask;
Expand All @@ -43,12 +42,13 @@ public void run(DataSource dataSource) {
});

final Scheduler scheduler =
Scheduler.create(dataSource, failingTask).pollingInterval(ofSeconds(2)).build();
Scheduler.create(dataSource, failingTask)
.pollingInterval(ofSeconds(2))
.registerShutdownHook()
.build();

scheduler.schedule(failingTask.instance("1"), Instant.now());

ExampleHelpers.registerShutdownHook(scheduler);

scheduler.start();
}
}
Expand Up @@ -14,7 +14,6 @@
package com.github.kagkarlsson.examples;

import com.github.kagkarlsson.examples.helpers.Example;
import com.github.kagkarlsson.examples.helpers.ExampleHelpers;
import com.github.kagkarlsson.scheduler.Scheduler;
import com.github.kagkarlsson.scheduler.task.FailureHandler;
import com.github.kagkarlsson.scheduler.task.helper.OneTimeTask;
Expand Down Expand Up @@ -52,12 +51,13 @@ public void run(DataSource dataSource) {
});

final Scheduler scheduler =
Scheduler.create(dataSource, failingTask).pollingInterval(Duration.ofSeconds(2)).build();
Scheduler.create(dataSource, failingTask)
.pollingInterval(Duration.ofSeconds(2))
.registerShutdownHook()
.build();

scheduler.schedule(failingTask.instance("1"), Instant.now());

ExampleHelpers.registerShutdownHook(scheduler);

scheduler.start();
}
}
Expand Up @@ -26,6 +26,10 @@
public class RecurringTaskMain extends Example {
private static final Logger LOG = LoggerFactory.getLogger(RecurringTaskMain.class);

public static void main(String[] args) {
new RecurringTaskMain().runWithDatasource();
}

@Override
public void run(DataSource dataSource) {

Expand Down
Expand Up @@ -13,10 +13,7 @@
*/
package com.github.kagkarlsson.examples;

import static com.github.kagkarlsson.examples.helpers.ExampleHelpers.sleep;

import com.github.kagkarlsson.examples.helpers.Example;
import com.github.kagkarlsson.examples.helpers.ExampleHelpers;
import com.github.kagkarlsson.scheduler.Scheduler;
import com.github.kagkarlsson.scheduler.task.ExecutionContext;
import com.github.kagkarlsson.scheduler.task.TaskInstance;
Expand Down Expand Up @@ -118,10 +115,9 @@ public void run(DataSource dataSource) {
final Scheduler scheduler =
Scheduler.create(dataSource, onetime1, onetime2)
.startTasks(recurring1, recurring2, custom1)
.registerShutdownHook()
.build();

ExampleHelpers.registerShutdownHook(scheduler);

scheduler.start();

sleep(3000);
Expand Down

This file was deleted.

0 comments on commit e098bd2

Please sign in to comment.