limit concurrent jobs MAYBE
parent
f51a94eee1
commit
739e832222
|
|
@ -5,13 +5,14 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"gitea.inhome.blapointe.com/local/firestormy/config"
|
"gitea.inhome.blapointe.com/local/firestormy/config"
|
||||||
"gitea.inhome.blapointe.com/local/firestormy/config/ns"
|
"gitea.inhome.blapointe.com/local/firestormy/config/ns"
|
||||||
"gitea.inhome.blapointe.com/local/firestormy/logger"
|
"gitea.inhome.blapointe.com/local/firestormy/logger"
|
||||||
"gitea.inhome.blapointe.com/local/logb"
|
"gitea.inhome.blapointe.com/local/logb"
|
||||||
"regexp"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
cron "github.com/robfig/cron/v3"
|
cron "github.com/robfig/cron/v3"
|
||||||
)
|
)
|
||||||
|
|
@ -23,14 +24,32 @@ type Scheduler struct {
|
||||||
running map[string]cron.EntryID
|
running map[string]cron.EntryID
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type semaphored struct {
|
||||||
|
job cron.Job
|
||||||
|
ch chan struct{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s semaphored) Run() {
|
||||||
|
s.ch <- struct{}{}
|
||||||
|
s.job.Run()
|
||||||
|
<-s.ch
|
||||||
|
}
|
||||||
|
|
||||||
func New() *Scheduler {
|
func New() *Scheduler {
|
||||||
l := logger.New()
|
l := logger.New()
|
||||||
|
semaphore := make(chan struct{}, 2)
|
||||||
c := cron.New(
|
c := cron.New(
|
||||||
cron.WithLocation(time.Local),
|
cron.WithLocation(time.Local),
|
||||||
cron.WithLogger(l),
|
cron.WithLogger(l),
|
||||||
cron.WithChain(
|
cron.WithChain(
|
||||||
cron.SkipIfStillRunning(l),
|
cron.SkipIfStillRunning(l),
|
||||||
cron.Recover(l),
|
cron.Recover(l),
|
||||||
|
func(j cron.Job) cron.Job {
|
||||||
|
return semaphored{
|
||||||
|
job: j,
|
||||||
|
ch: semaphore,
|
||||||
|
}
|
||||||
|
},
|
||||||
),
|
),
|
||||||
cron.WithParser(getParser()),
|
cron.WithParser(getParser()),
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -4,12 +4,13 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"gitea.inhome.blapointe.com/local/firestormy/config"
|
|
||||||
"gitea.inhome.blapointe.com/local/firestormy/config/ns"
|
|
||||||
"gitea.inhome.blapointe.com/local/storage"
|
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"gitea.inhome.blapointe.com/local/firestormy/config"
|
||||||
|
"gitea.inhome.blapointe.com/local/firestormy/config/ns"
|
||||||
|
"gitea.inhome.blapointe.com/local/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSchedulerAddRemove(t *testing.T) {
|
func TestSchedulerAddRemove(t *testing.T) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue