Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/jobQueue/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/jobQueue/jobQueue.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ 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
}

// 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,
Expand Down Expand Up @@ -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).
Expand Down
4 changes: 2 additions & 2 deletions pkg/jobQueue/jobQueue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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!")
Expand Down
Loading