An open API service indexing awesome lists of open source software.

https://github.com/tolitius/on-demand-scheduler

Collection of Schedulable Tasks that can be scheduled on demand ( based on Spring Framework )
https://github.com/tolitius/on-demand-scheduler

Last synced: 6 months ago
JSON representation

Collection of Schedulable Tasks that can be scheduled on demand ( based on Spring Framework )

Awesome Lists containing this project

README

          

## What is "On Demand Scheduler"? ##

Is a collection of self 'schedulable' tasks that are given a Spring's TaskScheduler will get scheduled on demand / programmatically.

## Why would I need it?##

Good question. Afterall, there is Spring's "<task:scheduled>", Quartz, JDK Timer, you name it...


The idea behind "On Demand" scheduler is to achieve three things:

1. Be very simple
2. Be based on Spring
3. Be able to be schedule tasks on demand

Currently, the way to schedule a task in Spring is to use <task:scheduled> ( satisfies #1 and #2 ):



Which means that the task is going to be scheduled _automatically_ when the application context is created.

"On Demand" scheduler compliments this ability with 'Schedulable' tasks that can be scheduled exactly _when needed_.

## Can you give me an example? ##

Business requirement: Whenever certain business service is done, schedule a pickup task ( e.g. to start picking up files every 5 seconds ).







That is pretty much it.


This will create an immutable task that can be injected anywhere and can be scheduled as:

deliveryTask.schedule();

To fully satisfy the above business requirement, you would of course have an after / around advice applied to that "certain method" that needs attention ( e.g. businessService() ), and have this task injected into the aspect.
***
Another example: Start process all the shipments of Ubuntu DVDs to Apple Headquarters every 5 minutes while the store is closed e.g. from 21:00 to 08:00





Ubuntu DVD

Apple Computer Inc
1 Infinite Loop
Cupertino, CA 95014


Again, this is a simple Spring bean that can be injected anywhere, and the Spring's TaskScheduler APIs can be used. e.g. here is an example from "SchedulingRunnableTaskWithTriggerIntegrationTest":

@Before
public void shouldCreateTriggerAndScheduleTask() {

long now = Calendar.getInstance().getTime().getTime();

// Set a trigger to start in 5 second, run every 2 seconds for 15 seconds:
Date startTime = new Date( now + 5000 );
Date endTime = new Date( now + 15000 );
long period = 2000;

Trigger trigger = new DurationTrigger( startTime, endTime, period );

taskScheduler.schedule( shipOrderTask, trigger );
}

_where a "taskScheduler" is a regular Spring's "" and "org.gitpod.scheduler.trigger.DurationTrigger" is a custom trigger. You can simply grab it form sources._

## The gist of it

The main idea here is to have these simple tasks: FixDelayTask, TimeOutTask, RunnableTask, FixRateTask, CronTask, etc., some of which are suggested by Spring APIs ( e.g. take a look at Spring's ScheduledTaskRegistrar ), inject them in to components that need them as 'Schedulable's, and schedule whenever appropriate.

###### _TODO: more tasks, more tests, more love_