-
Notifications
You must be signed in to change notification settings - Fork 2
/
enqueuer.go
49 lines (43 loc) · 1.19 KB
/
enqueuer.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
47
48
49
package main
import (
"github.com/rs/zerolog/log"
"go.riyazali.net/bhav/pipeline"
"sync"
"time"
)
var day = time.Hour * 24
var holidays = [][2]int{
{1, 1}, // new year
{1, 26}, // republic day
{1, 30}, // gandhi memory day
{4, 14}, // regional new year
{5, 1}, // may day
{8, 15}, // independence day
{10, 2}, // gandhi jayanthi
{12, 25}, // christmas
}
func Holiday(d time.Time) bool {
if w := d.Weekday(); w == time.Saturday || w == time.Sunday { // is a weekend?
return true
} else { // falls on a national holiday?
for _, h := range holidays {
_, month, day := d.Date()
if day == h[0] && int(month) == h[1] {
return true
}
}
}
return false
}
// EnqueueEquity enqueues job for processing equity data
func EnqueueEquity(from, to time.Time, wg *sync.WaitGroup, exc string, gen func(on time.Time) pipeline.Resource, in chan<- pipeline.Resource) {
defer wg.Done()
for d := from; d.Before(to) || d.Equal(to); d = d.Add(day) {
if Holiday(d) {
log.Info().Str("exchange", exc).Msgf("skipping job for %s", d.Format("Mon 02 Jan, 2006"))
continue
}
log.Debug().Str("exchange", exc).Msgf("enqueuing job for %s", d.Format("Mon 02 Jan, 2006"))
in <- gen(d)
}
}