feat: cron trigger api and fix import lists

This commit is contained in:
Simon Ding
2024-09-03 09:46:23 +08:00
parent 361556228b
commit ba1be8f279
7 changed files with 81 additions and 20 deletions

View File

@@ -6,6 +6,7 @@ import (
"polaris/log"
"polaris/pkg/tmdb"
"polaris/pkg/transmission"
"polaris/pkg/utils"
"github.com/pkg/errors"
"github.com/robfig/cron"
@@ -20,11 +21,23 @@ func NewClient(db *db.Client, language string) *Client {
}
}
type scheduler struct {
cron string
f func() error
}
type Client struct {
db *db.Client
cron *cron.Cron
tasks map[int]*Task
language string
schedulers utils.Map[string, scheduler]
}
func (c *Client) registerCronJob(name string, cron string, f func() error) {
c.schedulers.Store(name, scheduler{
cron: cron,
f: f,
})
}
func (c *Client) Init() {