Missing handlers but there we goddamn GO
Former-commit-id: 2505146a54acaf18eadfdebf1dd2720889aef795
This commit is contained in:
52
handlers/handler.go
Normal file
52
handlers/handler.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"local/rssmon3/config"
|
||||
"local/rssmon3/monitor"
|
||||
"local/rssmon3/rss"
|
||||
"log"
|
||||
)
|
||||
|
||||
type Handler struct {
|
||||
Jobs <-chan *monitor.Item
|
||||
config.Stoppable
|
||||
}
|
||||
|
||||
func New(jobs <-chan *monitor.Item) *Handler {
|
||||
return &Handler{
|
||||
Jobs: jobs,
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Handler) Run() error {
|
||||
for {
|
||||
select {
|
||||
case <-h.Stopped():
|
||||
return nil
|
||||
case j := <-h.Jobs:
|
||||
go func(key string) {
|
||||
if err := h.Job(key); err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
}(j.Key)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Handler) Job(key string) error {
|
||||
f := &rss.Feed{Key: key}
|
||||
if err := f.Load(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := f.Pull(); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, tag := range f.Tags {
|
||||
if foo := ByTag(tag); foo != nil {
|
||||
if err := foo(key); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user