Add nginx exec

This commit is contained in:
Jamie Curnow
2022-07-15 14:26:12 +10:00
parent b8008606fd
commit 5b6dbaf43e
6 changed files with 101 additions and 14 deletions

View File

@ -11,7 +11,7 @@ var (
worker *Worker
)
// Start ...
// Start will intantiate the queue and start doing work
func Start() {
ctx, cancel = context.WithCancel(context.Background())
q := &Queue{
@ -27,6 +27,15 @@ func Start() {
go worker.doWork()
}
// Shutdown will gracefully stop the queue
func Shutdown() error {
if cancel == nil {
return errors.New("Unable to shutdown, jobqueue has not been started")
}
cancel()
return nil
}
// AddJob adds a job to the queue for processing
func AddJob(j Job) error {
if worker == nil {
@ -35,12 +44,3 @@ func AddJob(j Job) error {
worker.Queue.AddJob(j)
return nil
}
// Shutdown ...
func Shutdown() error {
if cancel == nil {
return errors.New("Unable to shutdown, jobqueue has not been started")
}
cancel()
return nil
}

View File

@ -2,7 +2,6 @@ package jobqueue
import (
"context"
"log"
"sync"
)
@ -42,13 +41,10 @@ func (q *Queue) AddJobs(jobs []Job) {
// AddJob sends job to the channel.
func (q *Queue) AddJob(job Job) {
q.jobs <- job
log.Printf("New job %s added to queue", job.Name)
}
// Run performs job execution.
func (j Job) Run() error {
log.Printf("Job running: %s", j.Name)
err := j.Action()
if err != nil {
return err