MCPcopy Index your code
hub / github.com/riverqueue/river / Job_Build

Function Job_Build

rivershared/testfactory/test_factory.go:51–108  ·  view source on GitHub ↗
(tb testing.TB, opts *JobOpts)

Source from the content-addressed store, hash-verified

49}
50
51func Job_Build(tb testing.TB, opts *JobOpts) *riverdriver.JobInsertFullParams {
52 tb.Helper()
53
54 attemptedAt := opts.AttemptedAt
55 if attemptedAt == nil && (opts.State != nil && (slices.Contains([]rivertype.JobState{
56 rivertype.JobStateCompleted,
57 rivertype.JobStateDiscarded,
58 rivertype.JobStateRetryable,
59 rivertype.JobStateRunning,
60 }, *opts.State))) {
61 attemptedAt = ptrutil.Ptr(time.Now())
62 }
63
64 encodedArgs := opts.EncodedArgs
65 if opts.EncodedArgs == nil {
66 encodedArgs = []byte("{}")
67 }
68
69 finalizedAt := opts.FinalizedAt
70 if finalizedAt == nil && (opts.State != nil && (slices.Contains([]rivertype.JobState{
71 rivertype.JobStateCompleted,
72 rivertype.JobStateCancelled,
73 rivertype.JobStateDiscarded,
74 }, *opts.State))) {
75 finalizedAt = ptrutil.Ptr(time.Now())
76 }
77
78 metadata := opts.Metadata
79 if opts.Metadata == nil {
80 metadata = []byte("{}")
81 }
82
83 tags := opts.Tags
84 if tags == nil {
85 tags = []string{}
86 }
87
88 return &riverdriver.JobInsertFullParams{
89 Attempt: ptrutil.ValOrDefault(opts.Attempt, 0),
90 AttemptedAt: attemptedAt,
91 AttemptedBy: opts.AttemptedBy,
92 CreatedAt: opts.CreatedAt,
93 EncodedArgs: encodedArgs,
94 Errors: opts.Errors,
95 FinalizedAt: finalizedAt,
96 Kind: ptrutil.ValOrDefault(opts.Kind, "fake_job"),
97 MaxAttempts: ptrutil.ValOrDefault(opts.MaxAttempts, rivercommon.MaxAttemptsDefault),
98 Metadata: metadata,
99 Priority: ptrutil.ValOrDefault(opts.Priority, rivercommon.PriorityDefault),
100 Queue: ptrutil.ValOrDefault(opts.Queue, rivercommon.QueueDefault),
101 ScheduledAt: opts.ScheduledAt,
102 Schema: opts.Schema,
103 State: ptrutil.ValOrDefault(opts.State, rivertype.JobStateAvailable),
104 Tags: tags,
105 UniqueKey: opts.UniqueKey,
106 UniqueStates: opts.UniqueStates,
107 }
108}

Callers 4

BenchmarkFunction · 0.92
exerciseJobInsertFunction · 0.92
TestJobExecutor_ExecuteFunction · 0.92
JobFunction · 0.85

Calls 4

PtrFunction · 0.92
ValOrDefaultFunction · 0.92
HelperMethod · 0.65
NowMethod · 0.65

Tested by 1

TestJobExecutor_ExecuteFunction · 0.74

Used in the wild real call sites across dependent graphs

searching dependent graphs…