limit concurrent jobs MAYBE

master
Bel LaPointe 2025-05-24 14:10:19 -06:00
parent f51a94eee1
commit 739e832222
2 changed files with 26 additions and 6 deletions

View File

@ -5,13 +5,14 @@ import (
"errors"
"fmt"
"io/ioutil"
"regexp"
"strings"
"time"
"gitea.inhome.blapointe.com/local/firestormy/config"
"gitea.inhome.blapointe.com/local/firestormy/config/ns"
"gitea.inhome.blapointe.com/local/firestormy/logger"
"gitea.inhome.blapointe.com/local/logb"
"regexp"
"strings"
"time"
cron "github.com/robfig/cron/v3"
)
@ -23,14 +24,32 @@ type Scheduler struct {
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 {
l := logger.New()
semaphore := make(chan struct{}, 2)
c := cron.New(
cron.WithLocation(time.Local),
cron.WithLogger(l),
cron.WithChain(
cron.SkipIfStillRunning(l),
cron.Recover(l),
func(j cron.Job) cron.Job {
return semaphored{
job: j,
ch: semaphore,
}
},
),
cron.WithParser(getParser()),
)

View File

@ -4,12 +4,13 @@ import (
"bytes"
"fmt"
"io/ioutil"
"gitea.inhome.blapointe.com/local/firestormy/config"
"gitea.inhome.blapointe.com/local/firestormy/config/ns"
"gitea.inhome.blapointe.com/local/storage"
"os"
"testing"
"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) {