New JobQueue worker

This commit is contained in:
Jamie Curnow
2022-07-15 08:52:38 +10:00
parent 3c0af95468
commit f51c12ed9a
10 changed files with 209 additions and 103 deletions

View File

@ -8,6 +8,7 @@ import (
"npm/internal/database"
"npm/internal/entity"
"npm/internal/errors"
"npm/internal/jobqueue"
"npm/internal/logger"
"npm/internal/model"
)
@ -172,3 +173,25 @@ func GetByStatus(status string) ([]Model, error) {
return models, err
}
// AddPendingJobs is intended to be used at startup to add
// anything pending to the JobQueue just once, based on
// the database row status
func AddPendingJobs() {
rows, err := GetByStatus(StatusReady)
if err != nil {
logger.Error("AddPendingJobsError", err)
return
}
for _, row := range rows {
logger.Debug("Adding RequestCertificate job: %+v", row)
err := jobqueue.AddJob(jobqueue.Job{
Name: "RequestCertificate",
Action: row.Request,
})
if err != nil {
logger.Error("AddPendingJobsError", err)
}
}
}