@@ -14,18 +14,25 @@ type JobWithDetails struct {
14
14
Details map [string ]interface {}
15
15
Client * ClientWithResponses
16
16
ExternalID string
17
+ ctx context.Context
17
18
}
18
19
19
20
// NewJobWithDetails creates a new JobWithDetails with the client and job data
20
21
func NewJobWithDetails (client * ClientWithResponses , job Job ) (* JobWithDetails , error ) {
22
+ return NewJobWithDetailsContext (context .Background (), client , job )
23
+ }
24
+
25
+ // NewJobWithDetailsContext creates a new JobWithDetails with a specific context
26
+ func NewJobWithDetailsContext (ctx context.Context , client * ClientWithResponses , job Job ) (* JobWithDetails , error ) {
21
27
j := & JobWithDetails {
22
28
Job : job ,
23
29
Client : client ,
30
+ ctx : ctx ,
24
31
}
25
32
26
33
// Fetch job details
27
34
var err error
28
- j .Details , err = j .GetJobDetails (context . Background () )
35
+ j .Details , err = j .GetJobDetails ()
29
36
if err != nil {
30
37
return nil , fmt .Errorf ("failed to get job details: %w" , err )
31
38
}
@@ -34,8 +41,8 @@ func NewJobWithDetails(client *ClientWithResponses, job Job) (*JobWithDetails, e
34
41
}
35
42
36
43
// GetJobDetails retrieves job details for templating
37
- func (j * JobWithDetails ) GetJobDetails (ctx context. Context ) (map [string ]interface {}, error ) {
38
- resp , err := j .Client .GetJobWithResponse (ctx , j .Id .String ())
44
+ func (j * JobWithDetails ) GetJobDetails () (map [string ]interface {}, error ) {
45
+ resp , err := j .Client .GetJobWithResponse (j . ctx , j .Id .String ())
39
46
if err != nil {
40
47
return nil , fmt .Errorf ("failed to get job details: %w" , err )
41
48
}
@@ -54,6 +61,14 @@ func (j *JobWithDetails) GetJobDetails(ctx context.Context) (map[string]interfac
54
61
return details , nil
55
62
}
56
63
64
+ // WithContext returns a copy of the job with a new context
65
+ func (j * JobWithDetails ) WithContext (ctx context.Context ) * JobWithDetails {
66
+ // Create a shallow copy with the new context
67
+ jobCopy := * j
68
+ jobCopy .ctx = ctx
69
+ return & jobCopy
70
+ }
71
+
57
72
// TemplateJobDetails applies the job details template to the script
58
73
func (j * JobWithDetails ) TemplateJobDetails () (string , error ) {
59
74
// Extract script from JobAgentConfig
@@ -89,7 +104,7 @@ func (j *JobWithDetails) UpdateStatus(status JobStatus, message string) error {
89
104
body .ExternalId = & j .ExternalID
90
105
}
91
106
92
- resp , err := j .Client .UpdateJobWithResponse (context . Background () , j .Id .String (), body )
107
+ resp , err := j .Client .UpdateJobWithResponse (j . ctx , j .Id .String (), body )
93
108
if err != nil {
94
109
return fmt .Errorf ("failed to update job status: %w" , err )
95
110
}
0 commit comments