Merge tag 'v0.1.0' into develop
v0.1.0
This commit is contained in:
commit
f2a0830ca1
14
README.md
14
README.md
@ -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
2
go.mod
@ -1,4 +1,4 @@
|
|||||||
module cycle-scheduler
|
module gitea.thegux.fr/rmanach/cycle-scheduler.git
|
||||||
|
|
||||||
go 1.22.4
|
go 1.22.4
|
||||||
|
|
||||||
|
|||||||
@ -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
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user