Skip to content

Commit 8643737

Browse files
committed
Add manual syncing on USR2
This adds the ability to trigger a manual sync with USR2. It also removes the use of HUP in favor of USR1.
1 parent 07a0385 commit 8643737

File tree

1 file changed

+33
-20
lines changed

1 file changed

+33
-20
lines changed

main.go

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -508,33 +508,43 @@ func repoWorker(wg *sync.WaitGroup, rc <-chan repo) {
508508
}
509509
}
510510

511+
func readConfig() Config {
512+
configLock.RLock()
513+
defer configLock.RUnlock()
514+
return globalConf
515+
}
516+
511517
// Feed the channel all the information that it needs
512518
func feedChannel(jobs chan repo, oneshot bool) {
513519
for {
514-
// Get the latest config that might have been updated
515-
configLock.RLock()
516-
c := globalConf
517-
configLock.RUnlock()
518-
519-
for _, v := range c.Repos {
520-
jobs <- v.toRepo(c)
521-
}
522-
523-
for _, v := range c.Github {
524-
for _, r := range v.toRepos(c) {
525-
jobs <- r
526-
}
527-
}
520+
makeJobs(jobs)
528521

529522
if oneshot == true {
530523
close(jobs)
531524
return
532525
}
533526

527+
c := readConfig()
528+
534529
time.Sleep(time.Duration(c.Interval) * time.Second)
535530
}
536531
}
537532

533+
func makeJobs(jobs chan repo) {
534+
// Get the latest config that might have been updated
535+
c := readConfig()
536+
537+
for _, v := range c.Repos {
538+
jobs <- v.toRepo(c)
539+
}
540+
541+
for _, v := range c.Github {
542+
for _, r := range v.toRepos(c) {
543+
jobs <- r
544+
}
545+
}
546+
}
547+
538548
func launchWorkers(workers int, wg *sync.WaitGroup, rc <-chan repo) {
539549
for i := 1; i <= workers; i++ {
540550
log.Trace("Worker ", i, " has been started")
@@ -585,20 +595,23 @@ func loadConfig(config string) (Config, error) {
585595
return c, nil
586596
}
587597

588-
func handleSignals(signals <-chan os.Signal, config string) {
598+
func handleSignals(signals <-chan os.Signal, config string, jobs chan repo) {
589599
for signal := range signals {
590600
switch signal {
591-
case syscall.SIGHUP:
601+
case syscall.SIGUSR1:
592602
log.Warn("Config reload requested")
593603
newConfig, err := loadConfig(config)
594604
if err != nil {
595605
log.Error("Config not reloaded :", err.Error())
596606
} else {
597-
configLock.RLock()
607+
configLock.Lock()
598608
globalConf = newConfig
599-
configLock.RUnlock()
609+
configLock.Unlock()
600610
log.Warn("Config reload finished")
601611
}
612+
case syscall.SIGUSR2:
613+
log.Warn("Manual sync job was fired off")
614+
makeJobs(jobs)
602615
}
603616
}
604617
}
@@ -667,8 +680,8 @@ func main() {
667680

668681
// Handle hot config reloads on SIGHUP
669682
signals := make(chan os.Signal, 1)
670-
signal.Notify(signals, syscall.SIGHUP)
671-
go handleSignals(signals, *conf)
683+
signal.Notify(signals, syscall.SIGUSR1, syscall.SIGUSR2)
684+
go handleSignals(signals, *conf, queue)
672685

673686
// Hang for now but later this should do some checking for
674687
// signals that may be sent to the processes as well as managing

0 commit comments

Comments
 (0)