reset all job at start
This commit is contained in:
parent
a861828f47
commit
ff44bf48bc
23
job/queue.go
23
job/queue.go
|
@ -4,7 +4,6 @@ import (
|
|||
"database/sql"
|
||||
"errors"
|
||||
"log/slog"
|
||||
"time"
|
||||
|
||||
"code.ewintr.nl/emdb/storage"
|
||||
)
|
||||
|
@ -20,27 +19,13 @@ func NewJobQueue(db *storage.Postgres, logger *slog.Logger) *JobQueue {
|
|||
logger: logger.With("service", "jobqueue"),
|
||||
}
|
||||
|
||||
go jq.Run()
|
||||
|
||||
return jq
|
||||
}
|
||||
|
||||
func (jq *JobQueue) Run() {
|
||||
logger := jq.logger.With("method", "run")
|
||||
ticker := time.NewTicker(time.Hour)
|
||||
for {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
logger.Info("resetting stuck jobs")
|
||||
if _, err := jq.db.Exec(`
|
||||
UPDATE job_queue
|
||||
SET status = 'todo'
|
||||
WHERE status = 'doing'
|
||||
AND EXTRACT(EPOCH FROM now() - updated_at) > 2*24*60*60;`); err != nil {
|
||||
logger.Error("could not clean up job queue", "error", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
func (jq *JobQueue) ResetAll() error {
|
||||
_, err := jq.db.Exec(`UPDATE job_queue SET status='todo'`)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (jq *JobQueue) Add(movieID, action string) error {
|
||||
|
|
|
@ -13,20 +13,6 @@ import (
|
|||
"code.ewintr.nl/emdb/worker-client/worker"
|
||||
)
|
||||
|
||||
const (
|
||||
mentionsTemplate = `The following text is a user comment about the movie {{.title}}. In it, the user may have referenced other movie titles. List them if you see any.
|
||||
|
||||
----
|
||||
{{.review}}
|
||||
----
|
||||
|
||||
If you found any movie titles other than {{.title}}, list them below in a JSON array. If there are other titles, like TV shows, books or games, ignore them. The format is as follows:
|
||||
|
||||
["movie title 1", "movie title 2"]
|
||||
|
||||
Just answer with the JSON and nothing else. If you don't see any other movie titles, just answer with an empty array.`
|
||||
)
|
||||
|
||||
func main() {
|
||||
logger := slog.New(slog.NewTextHandler(os.Stdout, nil))
|
||||
dbHost := os.Getenv("EMDB_DB_HOST")
|
||||
|
|
|
@ -39,6 +39,12 @@ func (w *Worker) Run() {
|
|||
logger := w.logger.With("method", "run")
|
||||
logger.Info("starting worker")
|
||||
|
||||
logger.Info("setting al existing jobs to todo")
|
||||
if err := w.jq.ResetAll(); err != nil {
|
||||
logger.Error("could not set all jobs to todo", "error", err)
|
||||
return
|
||||
}
|
||||
|
||||
for {
|
||||
time.Sleep(interval)
|
||||
|
||||
|
|
Loading…
Reference in New Issue