Skip to content

Commit

Permalink
pass IDs as args instead of internal gen
Browse files Browse the repository at this point in the history
  • Loading branch information
ungerik committed Sep 25, 2024
1 parent 026ee5b commit 59ec05c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
12 changes: 6 additions & 6 deletions job.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (j *Job) String() string {
// NewJobWithPriority creates a Job but does not add it to the queue.
// The passed payload will be marshalled to JSON or directly interpreted as JSON if possible.
// If startAt is not null then the job will not start before that time.
func NewJobWithPriority(jobType, origin string, payload any, priority int64, startAt nullable.Time) (*Job, error) {
func NewJobWithPriority(id uu.ID, jobType, origin string, payload any, priority int64, startAt nullable.Time) (*Job, error) {
if jobType == "" {
return nil, errors.New("empty jobType")
}
Expand Down Expand Up @@ -133,7 +133,7 @@ func NewJobWithPriority(jobType, origin string, payload any, priority int64, sta

now := time.Now()
job := &Job{
ID: uu.IDv4(),
ID: id,
Type: jobType,
Payload: payloadJSON,
Origin: origin,
Expand All @@ -149,8 +149,8 @@ func NewJobWithPriority(jobType, origin string, payload any, priority int64, sta
// NewJob creates a Job but does not add it to the queue.
// The passed payload will be marshalled to JSON or directly interpreted as JSON if possible.
// If startAt is not null then the job will not start before that time.
func NewJob(jobType, origin string, payload any, startAt nullable.Time) (*Job, error) {
return NewJobWithPriority(jobType, origin, payload, 0, startAt)
func NewJob(id uu.ID, jobType, origin string, payload any, startAt nullable.Time) (*Job, error) {
return NewJobWithPriority(id, jobType, origin, payload, 0, startAt)
}

// NewJobReflectType creates a Job but does not add it to the queue.
Expand All @@ -162,6 +162,6 @@ func NewJob(jobType, origin string, payload any, startAt nullable.Time) (*Job, e
// The job type string starts with the package import path of the type
// followed by a point and the type name.
// Pointer types will be dereferenced.
func NewJobReflectType(origin string, payload any, startAt nullable.Time) (*Job, error) {
return NewJob(ReflectJobTypeOfPayload(payload), origin, payload, startAt)
func NewJobReflectType(id uu.ID, origin string, payload any, startAt nullable.Time) (*Job, error) {
return NewJob(id, ReflectJobTypeOfPayload(payload), origin, payload, startAt)
}
9 changes: 5 additions & 4 deletions jobbundle.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package jobqueue

import (
"context"
"errors"
"fmt"
"time"
Expand Down Expand Up @@ -52,7 +53,7 @@ func (b *JobBundle) String() string {
// A job will be added for every JobDesc.
// If a JobDesc.Type is an empty string, then ReflectJobType(JobDesc.Payload) will be used instead.
// If startAt is not null then the job bundle will not start before that time.
func NewJobBundle(jobBundleType, jobBundleOrigin string, jobDescriptions []JobDesc, startAt nullable.Time) (*JobBundle, error) {
func NewJobBundle(ctx context.Context, jobBundleType, jobBundleOrigin string, jobDescriptions []JobDesc, startAt nullable.Time) (*JobBundle, error) {
if len(jobDescriptions) == 0 {
return nil, errors.New("no jobDescriptions")
}
Expand All @@ -64,15 +65,15 @@ func NewJobBundle(jobBundleType, jobBundleOrigin string, jobDescriptions []JobDe
if jobType == "" {
jobType = ReflectJobTypeOfPayload(desc.Payload)
}
job, err := NewJobWithPriority(jobType, desc.Origin, desc.Payload, desc.Priority, startAt)
job, err := NewJobWithPriority(uu.NewID(ctx), jobType, desc.Origin, desc.Payload, desc.Priority, startAt)
if err != nil {
return nil, err
}
jobs[i] = job
}

jobBundle := &JobBundle{
ID: uu.IDv4(),
ID: uu.NewID(ctx),
Type: jobBundleType,
Origin: jobBundleOrigin,
Jobs: jobs,
Expand Down Expand Up @@ -116,7 +117,7 @@ func NewJobBundle(jobBundleType, jobBundleOrigin string, jobDescriptions []JobDe
// }

// jobBundle := &JobBundle{
// ID: uu.IDv4(),
// ID: uu.NewID(ctx),
// Type: jobBundleType,
// Origin: jobBundleOrigin,
// Jobs: jobs,
Expand Down

0 comments on commit 59ec05c

Please sign in to comment.