Skip to content

Commit

Permalink
fix: task status after next merge
Browse files Browse the repository at this point in the history
  • Loading branch information
brunozoric committed Dec 27, 2023
1 parent 19e5e5f commit 8216b3b
Show file tree
Hide file tree
Showing 18 changed files with 49 additions and 42 deletions.
8 changes: 4 additions & 4 deletions packages/api-elasticsearch-tasks/__tests__/mocks/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ export const createTaskMock = (task?: Partial<ITaskData>): ITaskData => {
values: {},
name: "A custom task defined via method",
log: [],
createdOn: new Date(),
savedOn: new Date(),
status: TaskDataStatus.PENDING,
createdOn: new Date().toISOString(),
savedOn: new Date().toISOString(),
taskStatus: TaskDataStatus.PENDING,
createdBy: createMockIdentity(),
eventResponse: {},
eventResponse: undefined,
...task
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe("reindexing", () => {
savedOn: expect.stringMatching(/^20/),
startedOn: expect.stringMatching(/^20/),
finishedOn: expect.stringMatching(/^20/),
status: TaskDataStatus.SUCCESS,
taskStatus: TaskDataStatus.SUCCESS,
log: [
{
message: "Task started.",
Expand Down Expand Up @@ -92,7 +92,7 @@ describe("reindexing", () => {
savedOn: expect.stringMatching(/^20/),
startedOn: expect.stringMatching(/^20/),
finishedOn: undefined,
status: TaskDataStatus.RUNNING,
taskStatus: TaskDataStatus.RUNNING,
log: [
{
message: "Task started.",
Expand Down Expand Up @@ -126,7 +126,7 @@ describe("reindexing", () => {
savedOn: expect.stringMatching(/^20/),
startedOn: expect.stringMatching(/^20/),
finishedOn: expect.stringMatching(/^20/),
status: TaskDataStatus.SUCCESS,
taskStatus: TaskDataStatus.SUCCESS,
log: [
{
message: "Task started.",
Expand Down
12 changes: 7 additions & 5 deletions packages/tasks/__tests__/crud/store.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useHandler } from "~tests/helpers/useHandler";
import { createTaskDefinition } from "~/task";
import { TaskDataStatus } from "~/types";
import { ITaskData, TaskDataStatus } from "~/types";
import { NotFoundError } from "@webiny/handler-graphql";
import WebinyError from "@webiny/error";
import { createMockIdentity } from "~tests/mocks/identity";
Expand Down Expand Up @@ -91,7 +91,7 @@ describe("store crud", () => {
someOtherValue: 123
}
});
const expectedCreatedTask = {
const expectedCreatedTask: ITaskData = {
id: expect.any(String),
createdOn: expect.stringMatching(/^20/),
savedOn: expect.stringMatching(/^20/),
Expand All @@ -105,7 +105,8 @@ describe("store crud", () => {
log: [],
startedOn: undefined,
finishedOn: undefined,
status: TaskDataStatus.PENDING
eventResponse: undefined,
taskStatus: TaskDataStatus.PENDING
};
expect(task).toEqual(expectedCreatedTask);

Expand All @@ -129,7 +130,7 @@ describe("store crud", () => {
addedNewValue: "yes!"
}
});
const expectedUpdatedTask = {
const expectedUpdatedTask: ITaskData = {
id: expect.any(String),
createdOn: expect.stringMatching(/^20/),
savedOn: expect.stringMatching(/^20/),
Expand All @@ -144,7 +145,8 @@ describe("store crud", () => {
log: [],
startedOn: undefined,
finishedOn: undefined,
status: TaskDataStatus.PENDING
eventResponse: undefined,
taskStatus: TaskDataStatus.PENDING
};
expect(updatedTask).toEqual(expectedUpdatedTask);

Expand Down
2 changes: 1 addition & 1 deletion packages/tasks/__tests__/crud/trigger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe("trigger crud", () => {
myAnotherCustomValue: "myAnotherCustomValue",
myCustomValue: "myCustomValue"
},
status: TaskDataStatus.PENDING,
taskStatus: TaskDataStatus.PENDING,
createdBy: createMockIdentity(),
createdOn: expect.stringMatching(/^20/),
savedOn: expect.stringMatching(/^20/),
Expand Down
6 changes: 3 additions & 3 deletions packages/tasks/__tests__/graphql/tasks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe("graphql - tasks", () => {
someOtherValue: 12345678
},
id: expect.any(String),
status: TaskDataStatus.PENDING,
taskStatus: TaskDataStatus.PENDING,
startedOn: null,
finishedOn: null,
createdBy: createMockIdentity(),
Expand All @@ -73,7 +73,7 @@ describe("graphql - tasks", () => {
someOtherValue: 4321
},
id: expect.any(String),
status: TaskDataStatus.PENDING,
taskStatus: TaskDataStatus.PENDING,
startedOn: null,
finishedOn: null,
createdBy: createMockIdentity(),
Expand All @@ -89,7 +89,7 @@ describe("graphql - tasks", () => {
someOtherValue: 123
},
id: expect.any(String),
status: TaskDataStatus.PENDING,
taskStatus: TaskDataStatus.PENDING,
startedOn: null,
finishedOn: null,
createdBy: createMockIdentity(),
Expand Down
2 changes: 1 addition & 1 deletion packages/tasks/__tests__/helpers/graphql/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const createListTasksQuery = () => {
id
definitionId
name
status
taskStatus
createdOn
savedOn
eventResponse
Expand Down
2 changes: 1 addition & 1 deletion packages/tasks/__tests__/mocks/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const createMockTask = (task?: Partial<ITaskData>): ITaskData => {
log: [],
createdOn: new Date().toISOString(),
savedOn: new Date().toISOString(),
status: TaskDataStatus.PENDING,
taskStatus: TaskDataStatus.PENDING,
createdBy: createMockIdentity(),
eventResponse: createMockTaskEventResponse(),
...task
Expand Down
2 changes: 1 addition & 1 deletion packages/tasks/__tests__/runner/taskManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ describe("task manager", () => {
id: "myCustomTaskDataId",
data: {
...task,
status: "running",
taskStatus: "running",
log: [
{
message: "Task started.",
Expand Down
4 changes: 2 additions & 2 deletions packages/tasks/src/crud/crud.tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const convertToTask = (entry: CmsEntry<ITaskData>): ITaskData => {
name: entry.values.name,
definitionId: entry.values.definitionId,
values: entry.values.values,
status: entry.values.status,
taskStatus: entry.values.taskStatus,
eventResponse: entry.values.eventResponse,
startedOn: entry.values.startedOn,
finishedOn: entry.values.finishedOn,
Expand Down Expand Up @@ -89,7 +89,7 @@ export const createTaskCrud = (context: Context): ITasksContextCrudObject => {
return await context.cms.createEntry(model, {
...values,
log: [],
status: TaskDataStatus.PENDING
taskStatus: TaskDataStatus.PENDING
});
});
return convertToTask(entry as unknown as CmsEntry<ITaskData>);
Expand Down
6 changes: 3 additions & 3 deletions packages/tasks/src/crud/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ const modelPlugin = createCmsModel({
label: "Values"
},
{
id: "status",
fieldId: "status",
storageId: "text@status",
id: "taskStatus",
fieldId: "taskStatus",
storageId: "text@taskStatus",
type: "text",
label: "Status",
predefinedValues: {
Expand Down
4 changes: 2 additions & 2 deletions packages/tasks/src/crud/trigger.tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ export const createTriggerTasksCrud = (
}
try {
return await context.tasks.updateTask(task.id, {
status: TaskDataStatus.ABORTED,
log: (task.log || []).concat([
taskStatus: TaskDataStatus.ABORTED,
log: task.log.concat([
{
message: params.message || "Task aborted.",
createdOn: new Date().toISOString()
Expand Down
2 changes: 1 addition & 1 deletion packages/tasks/src/graphql/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const createGraphQL = () => {
fields: model.fields,
type: "manage",
fieldTypePlugins,
excludeFields: ["entryId", "status"]
excludeFields: ["entryId"]
});

const sortEnumRender = renderSortEnum({
Expand Down
12 changes: 6 additions & 6 deletions packages/tasks/src/response/DatabaseResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ export class DatabaseResponse implements IResponseAsync {
try {
const task = this.store.getTask();
await this.store.updateTask({
status: TaskDataStatus.SUCCESS,
taskStatus: TaskDataStatus.SUCCESS,
finishedOn: new Date().toISOString(),
log: (task.log || []).concat([
log: task.log.concat([
{
message: message || "Task done.",
createdOn: new Date().toISOString()
Expand Down Expand Up @@ -76,8 +76,8 @@ export class DatabaseResponse implements IResponseAsync {
...task.values,
...params.values
},
status: TaskDataStatus.RUNNING,
log: (task.log || []).concat([
taskStatus: TaskDataStatus.RUNNING,
log: task.log.concat([
{
message: "Task continuing.",
createdOn: new Date().toISOString(),
Expand Down Expand Up @@ -121,9 +121,9 @@ export class DatabaseResponse implements IResponseAsync {
try {
const task = this.store.getTask();
await this.store.updateTask({
status: TaskDataStatus.FAILED,
taskStatus: TaskDataStatus.FAILED,
finishedOn: new Date().toISOString(),
log: (task.log || []).concat([
log: task.log.concat([
{
message: params.error.message,
createdOn: new Date().toISOString(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { ITaskDataValues, TaskResponseStatus } from "~/types";
import { IResponseBaseResult } from "./ResponseBaseResult";

/**
* Wait can be used to pause next iteration of the Lambda execution.
* For example, if the task is hammering the Elasticsearch cluster too much, you can use this to pause the execution for some time.
*/

export interface IResponseContinueParams<T = ITaskDataValues> {
tenant?: string;
locale?: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/tasks/src/runner/TaskControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class TaskControl implements ITaskControl {
* Make sure that task does not run if it is aborted.
* This will effectively end the Step Function execution with a "success" status.
*/
if (task.status === TaskDataStatus.ABORTED) {
if (task.taskStatus === TaskDataStatus.ABORTED) {
return this.response.aborted();
}

Expand Down
4 changes: 2 additions & 2 deletions packages/tasks/src/runner/TaskManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ export class TaskManager<T = ITaskDataValues> implements ITaskManager<T> {
try {
await this.store.updateTask(task => {
return {
status: TaskDataStatus.RUNNING,
taskStatus: TaskDataStatus.RUNNING,
startedOn: new Date().toISOString(),
log: (task.log || []).concat([
log: task.log.concat([
{
message: "Task started.",
createdOn: new Date().toISOString()
Expand Down
4 changes: 2 additions & 2 deletions packages/tasks/src/runner/TaskManagerStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class TaskManagerStore implements ITaskManagerStore {
}

public getStatus(): TaskDataStatus {
return this.task.status;
return this.task.taskStatus;
}

public setTask(task: ITaskData): void {
Expand Down Expand Up @@ -89,7 +89,7 @@ export class TaskManagerStore implements ITaskManagerStore {

public async addLog(log: ITaskDataLog): Promise<void> {
this.task = await this.context.tasks.updateTask(this.task.id, {
log: (this.task.log || []).concat([log])
log: this.task.log.concat([log])
});
}
}
8 changes: 4 additions & 4 deletions packages/tasks/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@ export interface ITaskIdentity {
export interface ITaskData<T = any> {
id: string;
name: string;
status: TaskDataStatus;
taskStatus: TaskDataStatus;
definitionId: string;
values: T;
createdOn: string;
savedOn: string;
createdBy: ITaskIdentity;
startedOn?: string;
finishedOn?: string;
eventResponse: EventBridgeClientSendResponse;
log?: ITaskDataLog[];
eventResponse: EventBridgeClientSendResponse | undefined;
log: ITaskDataLog[];
}

export type IGetTaskResponse<T = any> = ITaskData<T> | null;
Expand All @@ -77,7 +77,7 @@ export interface ITaskCreateData<T = ITaskDataValues> {
export interface ITaskUpdateData<T = ITaskDataValues> {
name?: string;
values?: T;
status?: TaskDataStatus;
taskStatus?: TaskDataStatus;
log?: ITaskDataLog[];
startedOn?: string;
finishedOn?: string;
Expand Down

0 comments on commit 8216b3b

Please sign in to comment.