Skip to content

Commit

Permalink
refactor: make sure the payload is what the remote-controller is expe…
Browse files Browse the repository at this point in the history
…cting
  • Loading branch information
shreddedbacon committed Jul 5, 2023
1 parent 2c59e9c commit e4acd0f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
3 changes: 1 addition & 2 deletions node-packages/commons/src/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1304,8 +1304,7 @@ export const createMiscTask = async function(taskData: any) {
break;
case 'kubernetes:task:cancel':
// task cancellation is just a standard unmodified message
miscTaskData.misc = taskData.data.build
miscTaskData.misc.command = "" // the command isn't required and just bloats the message
miscTaskData.misc = taskData.data.task
break;
case 'kubernetes:build:cancel':
// build cancellation is just a standard unmodified message
Expand Down
22 changes: 17 additions & 5 deletions services/actions-handler/handler/controller_tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ import (
)

func (m *Messenger) handleTask(ctx context.Context, messageQueue mq.MQ, message *schema.LagoonMessage, messageID string) {
prefix := fmt.Sprintf("(messageid:%s) %s/%s: ", messageID, message.Namespace, message.Meta.Task.Name)

// use the preferred TaskName value
prefix := fmt.Sprintf("(messageid:%s) %s/%s: ", messageID, message.Namespace, message.Meta.Task.TaskName)
if message.Meta.Task.TaskName == "" {
// or fall back to the older task name (the full name could be "my custom task" which isn't great)
prefix = fmt.Sprintf("(messageid:%s) %s/%s: ", messageID, message.Namespace, message.Meta.Task.Name)
}
log.Println(fmt.Sprintf("%sreceived task status update: %s", prefix, message.Meta.JobStatus))
// generate a lagoon token with a expiry of 60 seconds from now
token, err := jwt.GenerateAdminToken(m.LagoonAPI.TokenSigningKey, m.LagoonAPI.JWTAudience, m.LagoonAPI.JWTSubject, m.LagoonAPI.JWTIssuer, time.Now().Unix(), 60)
Expand Down Expand Up @@ -86,10 +92,16 @@ func (m *Messenger) handleTask(ctx context.Context, messageQueue mq.MQ, message
taskId, _ := strconv.Atoi(message.Meta.Task.ID)
// prepare the task patch for later step
updateTaskPatch := schema.UpdateTaskPatchInput{
RemoteID: message.Meta.RemoteID,
Status: schema.StatusTypes(strings.ToUpper(message.Meta.JobStatus)),
Started: message.Meta.StartTime,
Completed: message.Meta.EndTime,
Status: schema.StatusTypes(strings.ToUpper(message.Meta.JobStatus)),
}
if message.Meta.RemoteID != "" {
updateTaskPatch.RemoteID = message.Meta.RemoteID
}
if message.Meta.StartTime != "" {
updateTaskPatch.Started = message.Meta.StartTime
}
if message.Meta.EndTime != "" {
updateTaskPatch.Completed = message.Meta.EndTime
}
updatedTask, err := lagoon.UpdateTask(ctx, taskId, updateTaskPatch, l)
if err != nil {
Expand Down
9 changes: 7 additions & 2 deletions services/api/src/resources/task/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,12 @@ export const cancelTask: ResolverFn = async (


const data = {
build: task,
task: {
id: task.id.toString(),
name: task.name,
taskName: task.taskName,
service: task.service,
},
environment,
project
};
Expand All @@ -370,7 +375,7 @@ export const cancelTask: ResolverFn = async (
event: 'api:cancelDeployment',
payload: {
taskInput,
data: data.build
data: data.task
}
}
);
Expand Down

0 comments on commit e4acd0f

Please sign in to comment.