Merge tag 'v0.1.0' into develop

v0.1.0
This commit is contained in:
rmanach 2024-11-16 11:16:39 +01:00
commit f2a0830ca1
3 changed files with 11 additions and 7 deletions

View File

@ -1,6 +1,6 @@
# cycle-scheduler # 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... **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 ```go
import ( import (
"context" "context"
scheduler "gitea.thegux.fr/rmanach/cycle-scheduler.git"
) )
ctx := context.Background() 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( taskID := s.Delay(
func(ctx context.Context) (any, error) { func(ctx context.Context) (any, error) {
// execution // ...
return any, nil return any, nil
}, },
WithExecInterval(2*time.Millisecond) scheduler.WithExecInterval(2*time.Millisecond),
scheduler.WithMaxDuration(30*time.Second)
) )
<-ctx.Done() <-ctx.Done()

2
go.mod
View File

@ -1,4 +1,4 @@
module cycle-scheduler module gitea.thegux.fr/rmanach/cycle-scheduler.git
go 1.22.4 go 1.22.4

View File

@ -20,7 +20,7 @@ type IScheduler interface {
} }
// SchedulerCycle is a simple scheduler handling jobs and executes them at regular interval. // 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 { type SchedulerCycle struct {
wg sync.WaitGroup wg sync.WaitGroup