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

docs: Improve Examples #420

Merged
merged 1 commit into from
Sep 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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();
}
}
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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();
}
}
Original file line number Diff line number Diff line change
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();
}
}
Original file line number Diff line number Diff line change
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();
}
}
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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.