2024-11-16 11:23:22 +01:00
2024-09-14 10:38:14 +02:00
2024-09-14 10:38:14 +02:00
2024-11-16 11:15:30 +01:00
2024-09-14 10:38:14 +02:00
2024-11-16 11:00:46 +01:00
2024-11-16 11:23:22 +01:00
2024-11-16 11:00:46 +01:00
2024-11-16 11:15:30 +01:00
2024-11-16 11:00:46 +01:00
2024-11-16 11:00:46 +01:00

cycle-scheduler

cycle-scheduler is a simple scheduler lib, handling tasks and executes them at regular interval. If a task is not in desired state, the task is re-scheduled.

NOTE: this should be not used for long-running tasks, it's more suitable for shorts tasks like polling etc...

Examples

  • Init a new scheduler with 4 workers
package main

import (
	"context"
	"time"

	scheduler "gitea.thegux.fr/rmanach/cycle-scheduler.git"
)

func main() {
	ctx, fnCancel := context.WithCancel(context.Background())
	s := scheduler.NewSchedulerCycle(ctx, 4)

	// add a task with an execution interval of 2 ms (executed every 2 ms)
	// and a maximum duration of 30 second.
	s.Delay(
		func(ctx context.Context) (any, error) {
			// ...
			return nil, nil
		},
		scheduler.WithExecInterval(2*time.Millisecond),
		scheduler.WithMaxDuration(30*time.Second),
	)

	// stop the program after 5 seconds
	go func() {
		time.Sleep(5 * time.Second)
		fnCancel()
	}()

	<-ctx.Done()
	<-s.Done()
}

NOTE: for Delay optionals arguments, check the NewTask method documentation for more details.

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%