diff --git a/runtime/taskcontext.go b/runtime/taskcontext.go index 490d0f1e..039e2fea 100644 --- a/runtime/taskcontext.go +++ b/runtime/taskcontext.go @@ -101,24 +101,24 @@ func (c *TaskContextController) Dispose() error { return c.logStream.Remove() } -// GetQueueClient will return a client for the TaskCluster Queue. This client -// is useful for plugins that require interactions with the queue, such as creating -// artifacts. -func (c *TaskContext) GetQueueClient() QueueClient { - c.mu.RLock() - defer c.mu.RUnlock() - return c.queue -} - -// CreateQueueClient will create a client for the TaskCluster Queue. This client +// SetQueueClient will set a client for the TaskCluster Queue. This client // can then be used by others that have access to the task context and require // interaction with the queue. -func (c *TaskContext) SetQueueClient(client QueueClient) { +func (c *TaskContextController) SetQueueClient(client QueueClient) { c.mu.Lock() c.queue = client c.mu.Unlock() } +// Queue will return a client for the TaskCluster Queue. This client +// is useful for plugins that require interactions with the queue, such as creating +// artifacts. +func (c *TaskContext) Queue() QueueClient { + c.mu.RLock() + defer c.mu.RUnlock() + return c.queue +} + // Abort sets the status to aborted func (c *TaskContext) Abort() { // TODO (garndt): add abort/cancel channels for plugins to listen on diff --git a/worker/task.go b/worker/task.go index 797b2485..af264f7c 100644 --- a/worker/task.go +++ b/worker/task.go @@ -57,7 +57,7 @@ func NewTaskRun( queueClient.BaseURL = config.Taskcluster.Queue.URL - ctxt.SetQueueClient(queueClient) + ctxtctl.SetQueueClient(queueClient) if err != nil { return nil, err @@ -323,7 +323,7 @@ func (t *TaskRun) exceptionStage(taskError error) { return } - e := reportException(t.context.GetQueueClient(), t, reason, t.log) + e := reportException(t.context.Queue(), t, reason, t.log) if e != nil { t.log.WithField("error", e.Error()).Warn("Could not resolve task as exception.") } @@ -339,7 +339,7 @@ func (t *TaskRun) resolveTask() error { resolve = reportFailed } - err := resolve(t.context.GetQueueClient(), t, t.log) + err := resolve(t.context.Queue(), t, t.log) if err != nil { return errors.New(err.Error()) } diff --git a/worker/task_test.go b/worker/task_test.go index e05544db..1febdc3d 100644 --- a/worker/task_test.go +++ b/worker/task_test.go @@ -186,7 +186,7 @@ func TestRunTask(t *testing.T) { "1", ).Return(&queue.TaskStatusResponse{}, &tcclient.CallSummary{}, nil) - tr.context.SetQueueClient(mockedQueue) + tr.controller.SetQueueClient(mockedQueue) tr.Run() mockedQueue.AssertCalled(t, "ReportCompleted", "abc", "1") @@ -209,7 +209,7 @@ func TestRunMalformedEnginePayloadTask(t *testing.T) { &queue.TaskExceptionRequest{Reason: "malformed-payload"}, ).Return(&queue.TaskStatusResponse{}, &tcclient.CallSummary{}, nil) - tr.context.SetQueueClient(mockedQueue) + tr.controller.SetQueueClient(mockedQueue) tr.Run() mockedQueue.AssertCalled(t, "ReportException", "abc", "1", &queue.TaskExceptionRequest{Reason: "malformed-payload"})