periodicator/internal/tasks/config.go

44 lines
1023 B
Go
Raw Normal View History

2021-09-26 10:30:51 +05:00
package tasks
import "time"
// Config is a task's configuration as should be defined in configuration file.
// nolint:tagliatelle
type Config struct {
2021-11-21 17:38:31 +05:00
ExecutionStart TaskStartTime `yaml:"execution_start"`
2021-09-26 10:30:51 +05:00
Title string `yaml:"title"`
Body string `yaml:"body"`
Cron string `yaml:"cron"`
2021-11-21 17:38:31 +05:00
Tags []string `yaml:"tags"`
ProjectID int `yaml:"project_id"`
2021-09-26 10:30:51 +05:00
DueIn time.Duration `yaml:"due_in"`
}
// TaskStartTime holds task's start time for next creation timestamp calculation.
type TaskStartTime struct {
ts time.Time
}
func (tts *TaskStartTime) GetTimestamp() time.Time {
return tts.ts
}
func (tts *TaskStartTime) UnmarshalYAML(unmarshal func(interface{}) error) error {
var timeData string
if err := unmarshal(&timeData); err != nil {
return err
}
2021-11-21 17:38:31 +05:00
timeField, err := time.Parse("2006-01-02 15:04:05", timeData)
2021-09-26 10:30:51 +05:00
if err != nil {
// ToDo: fix it!
// nolint:wrapcheck
return err
}
2021-11-21 17:38:31 +05:00
tts.ts = timeField
2021-09-26 10:30:51 +05:00
return nil
}