stuff
This commit is contained in:
parent
9df58730a6
commit
55320df622
4
TODO.md
4
TODO.md
@ -13,6 +13,8 @@
|
|||||||
* Folder creation
|
* Folder creation
|
||||||
* Change flags to os.Args[1] for config path
|
* Change flags to os.Args[1] for config path
|
||||||
* Cleanup
|
* Cleanup
|
||||||
|
* Make Rhash optional
|
||||||
|
* Wrap content inside item
|
||||||
|
|
||||||
## Issues
|
## Issues
|
||||||
* ✓ Last record is not written fully to csv: *Fixed*. Had to Flush writer
|
* ✓ Last record is not written fully to csv: *Fixed*. Had to Flush writer
|
||||||
@ -44,6 +46,8 @@
|
|||||||
* Always running
|
* Always running
|
||||||
* Handle telegram reaction?
|
* Handle telegram reaction?
|
||||||
* Filter from app based on keyword
|
* Filter from app based on keyword
|
||||||
|
* Move telegram auth token to credential file
|
||||||
|
* Check if context is used correctly
|
||||||
|
|
||||||
### Log
|
### Log
|
||||||
* Log to file
|
* Log to file
|
||||||
|
@ -41,7 +41,7 @@ func Run(configPath string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ProcessFeed(feed FeedCfg, scheduler *Scheduler, dbDir string, tgram telegram.TelegramSender) {
|
func ProcessFeed(feed FeedCfg, scheduler Scheduler, dbDir string, tgram telegram.TelegramSender) {
|
||||||
sd, err := scheduler.ShouldDownload(feed.Name, feed.Cron)
|
sd, err := scheduler.ShouldDownload(feed.Name, feed.Cron)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("shouldDownload failed", "feed", feed.Name, "err", err)
|
log.Error("shouldDownload failed", "feed", feed.Name, "err", err)
|
||||||
|
@ -11,13 +11,19 @@ import (
|
|||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Scheduler struct {
|
type Scheduler interface {
|
||||||
|
ShouldDownload(name string, scheduleSpec string) (bool, error)
|
||||||
|
Save() error
|
||||||
|
Good(name string)
|
||||||
|
}
|
||||||
|
|
||||||
|
type scheduler struct {
|
||||||
filePath string
|
filePath string
|
||||||
lastSuccessTime map[string]time.Time
|
lastSuccessTime map[string]time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewScheduler(filePath string) (*Scheduler, error) {
|
func NewScheduler(filePath string) (Scheduler, error) {
|
||||||
s := Scheduler{filePath: filePath}
|
s := scheduler{filePath: filePath}
|
||||||
data, err := os.ReadFile(filePath)
|
data, err := os.ReadFile(filePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !errors.Is(err, os.ErrNotExist) {
|
if !errors.Is(err, os.ErrNotExist) {
|
||||||
@ -38,7 +44,7 @@ func NewScheduler(filePath string) (*Scheduler, error) {
|
|||||||
return &s, nil
|
return &s, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Scheduler) Save() error {
|
func (s *scheduler) Save() error {
|
||||||
data, err := yaml.Marshal(&s.lastSuccessTime)
|
data, err := yaml.Marshal(&s.lastSuccessTime)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -46,11 +52,11 @@ func (s *Scheduler) Save() error {
|
|||||||
return os.WriteFile(s.filePath, data, 0644)
|
return os.WriteFile(s.filePath, data, 0644)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Scheduler) Good(name string) {
|
func (s *scheduler) Good(name string) {
|
||||||
s.lastSuccessTime[name] = time.Now()
|
s.lastSuccessTime[name] = time.Now()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Scheduler) ShouldDownload(name string, scheduleSpec string) (bool, error) {
|
func (s *scheduler) ShouldDownload(name string, scheduleSpec string) (bool, error) {
|
||||||
lastSuccess, ok := s.lastSuccessTime[name]
|
lastSuccess, ok := s.lastSuccessTime[name]
|
||||||
if !ok {
|
if !ok {
|
||||||
return true, nil
|
return true, nil
|
||||||
|
Loading…
Reference in New Issue
Block a user