Closed ghost closed 8 years ago
@serge-nikitin if you only have a few functions creating @every 1s
instances then it's fairly manageable. However, if you have too many of them then it's best to batch process them. @every 1s
is too frequent and can easily become the bottleneck of your system.
Having said that, JobRunner instances join a pool so it's easy to get a count of current active jobs, outstanding jobs and etc.
The following methods are exported by the package so you can reference them inside your own program.
instances := jobrunner.StatusPage() //returns array of current active jobs
var count int
for k, _ := range instances {
job := instances[k].JobRunner
// Get the name of the job and count the instances of it
if job.Name == "JobX" {
count++
}
}
if count >= 100 {
// .... either sleep for 10sec or wait until "job instances" are reduced to 0
// you logic goes here
}
For example I have "@every 1s" job. But sometimes this job can take time longer than 1 sec. But I don't want more then N running instance of this job one time. Is it possible to do with this library?