diff --git a/README.md b/README.md index 9d5fef4..55461b2 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # 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 with a backoff. +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... @@ -9,18 +9,22 @@ cycle-scheduler is a simple scheduler lib, handling tasks and executes them at r ```go import ( "context" + + scheduler "gitea.thegux.fr/rmanach/cycle-scheduler.git" ) ctx := context.Background() -s := NewSchedulerCycle(ctx, 4) +s := scheduler.NewSchedulerCycle(ctx, 4) -// add a task +// add a task with an execution interval of 2 ms (executed every 2 ms) +// and a maximum duration of 30 second. taskID := s.Delay( func(ctx context.Context) (any, error) { - // execution + // ... return any, nil }, - WithExecInterval(2*time.Millisecond) + scheduler.WithExecInterval(2*time.Millisecond), + scheduler.WithMaxDuration(30*time.Second) ) <-ctx.Done() diff --git a/go.mod b/go.mod index be15dc4..7b05801 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module cycle-scheduler +module gitea.thegux.fr/rmanach/cycle-scheduler.git go 1.22.4 diff --git a/scheduler.go b/scheduler.go index 353d075..51c6171 100644 --- a/scheduler.go +++ b/scheduler.go @@ -20,7 +20,7 @@ type IScheduler interface { } // SchedulerCycle is a simple scheduler handling jobs and executes them at regular interval. -// If a task is not in desired state, the task is re-scheduled with a backoff. +// If a task is not in desired state, the task is re-scheduled. type SchedulerCycle struct { wg sync.WaitGroup