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