2024-09-24 12:29:41 +02:00
2024-09-14 10:38:14 +02:00
2024-09-14 10:38:14 +02:00
2024-09-14 10:38:14 +02:00
2024-09-14 10:38:14 +02:00
2024-09-14 10:38:14 +02:00
2024-09-14 10:38:14 +02:00
2024-09-14 10:38:14 +02:00

cycle-scheduler

cycle-scheduler is a simple scheduler handling jobs and executes them at regular interval.

Here a simple representation:

+------------------------------------------------------+
| +---+ +---+ +---+ +---+ +---+                  +---+ |
| |   | |   | |   | |   | |   |                  |   | |
| |   | |   | |   | |   | |   |                  |   | |
| |   | |   | |   | |   | |   |                  |   | |
| |   | |   | |   | |   | |   |                  |   | |
| |   | |   | |   | |   | |   |                  |   | |
| |   | |   | |   | |   | |   |                  |   | |
| |s1 | |s2 | |s3 | |s4 | |   |                  |s60| |
| +---+ +---+ +---+ +---+ +---+                  +---+ |
+---------------^--------------------------------------+

Jobs are handle in a array of job slices.

At each interval (clock), the cursor ^ moves to the next slot (s*). If there are jobs, they are sent to workers to be executed and the slot is cleaned. At the end of the slot (s60), the cursor re-starts a new cycle from s1.

If a job is not in a desire state, the job is re-scheduled in the current slot to be re-executed in the next cycle.

NOTE: This scheduler does not accept long running tasks. Job execution have a fixed timeout of 10s. Pooling tasks are more suitable for this kind of scheduler.

Run

You can run sample tests from main.go to see the scheduler in action:

make run

If all goes well, you should see this kind of output in the stdout:

# cycle-scheduler (slot: 7)
_ P _ _ _ _ _ _ _ _ _ _ _ _
- - - - - - ^ - - - - - - - 

P means pending state

You can adjust the clock interval as needed in main.go:

interval := 200 * time.Millisecond
Description
cycle-scheduler is a simple scheduler handling jobs and executes them at regular interval.
Readme 52 KiB
Languages
Go 99.7%
Makefile 0.3%