Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: API changes to support cancelling tasks #3112

Merged
merged 5 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions node-packages/commons/src/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1302,6 +1302,10 @@ export const createMiscTask = async function(taskData: any) {
}
miscTaskData.advancedTask = taskData.data.advancedTask
break;
case 'kubernetes:task:cancel':
// task cancellation is just a standard unmodified message
miscTaskData.misc = taskData.data.task
break;
case 'kubernetes:build:cancel':
// build cancellation is just a standard unmodified message
miscTaskData.misc = taskData.data.build
Expand Down
14 changes: 10 additions & 4 deletions services/actions-handler/handler/controller_tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,16 @@ func (m *Messenger) handleTask(ctx context.Context, messageQueue *mq.MessageQueu
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
1 change: 1 addition & 0 deletions services/api/src/mocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,7 @@ mocks.Mutation = () => ({
taskDrushRsyncFiles: () => mocks.Task(),
deleteTask: () => 'success',
updateTask: () => mocks.Task(),
cancelTask: () => faker.random.arrayElement(['success', 'Task not cancelled, reason: Too slow.']),
setEnvironmentServices: () => [ mocks.EnvironmentService() ],
uploadFilesForTask: () => mocks.Task(),
deleteFilesForTask: () => 'success',
Expand Down
2 changes: 2 additions & 0 deletions services/api/src/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const {
addTask,
deleteTask,
updateTask,
cancelTask,
taskDrushArchiveDump,
taskDrushSqlDump,
taskDrushCacheClear,
Expand Down Expand Up @@ -601,6 +602,7 @@ const resolvers = {
taskDrushUserLogin,
deleteTask,
updateTask,
cancelTask,
setEnvironmentServices,
uploadFilesForTask,
deleteFilesForTask,
Expand Down
Loading