diff --git a/pkg/jobQueue/README.md b/pkg/jobQueue/README.md index 0e9ad18..6f891c8 100644 --- a/pkg/jobQueue/README.md +++ b/pkg/jobQueue/README.md @@ -26,7 +26,7 @@ import ( func main() { // Define the function that will be executed for each request - execFunc := func() error { + execFunc := func(req jobQueue.Request) error { time.Sleep(50 * time.Millisecond) return nil } diff --git a/pkg/jobQueue/jobQueue.go b/pkg/jobQueue/jobQueue.go index b58b875..1f38d53 100644 --- a/pkg/jobQueue/jobQueue.go +++ b/pkg/jobQueue/jobQueue.go @@ -19,7 +19,7 @@ type Request struct { // JobQueue is a thread-safe queue of requests to execute a predefined function. type JobQueue struct { reqChan chan Request - execFunc func() error + execFunc func(request Request) error mu sync.Mutex context context.Context } @@ -27,7 +27,7 @@ type JobQueue struct { // NewJobQueue creates a new job queue // execFunc is the function to be executed for each request that is processed // context is the context of the caller -func NewJobQueue(execFunc func() error, context context.Context) *JobQueue { +func NewJobQueue(execFunc func(request Request) error, context context.Context) *JobQueue { q := JobQueue{ reqChan: make(chan Request, 100), execFunc: execFunc, @@ -84,7 +84,7 @@ func (q *JobQueue) execute(req Request) { Str("request_id", req.ID). Msgf("executing queue request id: %s", req.ID) // Call the function - err := q.execFunc() + err := q.execFunc(req) if err != nil { log.Error().Err(err). Str("request_id", req.ID). diff --git a/pkg/jobQueue/jobQueue_test.go b/pkg/jobQueue/jobQueue_test.go index 0dd3803..37d7fbb 100644 --- a/pkg/jobQueue/jobQueue_test.go +++ b/pkg/jobQueue/jobQueue_test.go @@ -80,8 +80,8 @@ func TestExecutor(t *testing.T) { } } -func jobTestFunc(t *testing.T, mu *sync.Mutex, running *bool, count *int) func() error { - return func() error { +func jobTestFunc(t *testing.T, mu *sync.Mutex, running *bool, count *int) func(Request) error { + return func(_ Request) error { mu.Lock() if *running { t.Errorf("Job is already running!")