forked from revel/modules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.go
31 lines (25 loc) · 742 Bytes
/
plugin.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package jobs
import (
"github.com/terhitormanen/cron"
"github.com/terhitormanen/revel"
)
const DefaultJobPoolSize = 10
var (
// MainCron is the singleton instance of the underlying job scheduler.
MainCron *cron.Cron
// This limits the number of jobs allowed to run concurrently.
workPermits chan struct{}
// Is a single job allowed to run concurrently with itself?
selfConcurrent bool
)
func init() {
MainCron = cron.New()
revel.OnAppStart(func() {
if size := revel.Config.IntDefault("jobs.pool", DefaultJobPoolSize); size > 0 {
workPermits = make(chan struct{}, size)
}
selfConcurrent = revel.Config.BoolDefault("jobs.selfconcurrent", false)
MainCron.Start()
jobLog.Info("Go to /@jobs to see job status.")
})
}