-
Notifications
You must be signed in to change notification settings - Fork 0
/
worked.go
46 lines (38 loc) · 1.26 KB
/
worked.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package pump
import (
"sync"
"github.com/robfig/cron/v3"
)
var storageCronIDs = make(StorageCronID)
var wrkMtx sync.RWMutex
// StorageCronID is a structure of storage for all cron job ID of ran jobs.
type StorageCronID map[string]cron.EntryID
// getWorkindSourceNames returns all names of source were define in configuration yaml file and are ran now.
func getWorkindSourceNames() (names []string) {
wrkMtx.RLock()
defer wrkMtx.RUnlock()
for name := range storageCronIDs {
names = append(names, name)
}
return names
}
// getWorkedID returns an ID of cron job for updating data from source with selected name if this job is ran now.
// If source with selected name is not run now argument 'ok' will be false.
func getWorkedID(name string) (id cron.EntryID, ok bool) {
wrkMtx.Lock()
defer wrkMtx.Unlock()
id, ok = storageCronIDs[name]
return id, ok
}
// setWorkedID saves a source with selected name and id to storage for all cron job ID of ran jobs.
func setWorkedID(name string, id cron.EntryID) {
wrkMtx.Lock()
defer wrkMtx.Unlock()
storageCronIDs[name] = id
}
// delWorkindSource deletes a source with selected name from storage for all cron job ID of ran jobs.
func delWorkindSource(name string) {
wrkMtx.Lock()
defer wrkMtx.Unlock()
delete(storageCronIDs, name)
}