-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
139 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 0 additions & 104 deletions
104
packages/twenty-server/src/modules/workflow/workflow-status/workflow-status.service.ts
This file was deleted.
Oops, something went wrong.
92 changes: 92 additions & 0 deletions
92
...s/twenty-server/src/modules/workflow/workflow-status/workflow-status.workspace-service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
|
||
import { ActorMetadata } from 'src/engine/metadata-modules/field-metadata/composite-types/actor.composite-type'; | ||
import { TwentyORMManager } from 'src/engine/twenty-orm/twenty-orm.manager'; | ||
import { | ||
WorkflowRunStatus, | ||
WorkflowRunWorkspaceEntity, | ||
} from 'src/modules/workflow/common/standard-objects/workflow-run.workspace-entity'; | ||
import { | ||
WorkflowStatusException, | ||
WorkflowStatusExceptionCode, | ||
} from 'src/modules/workflow/workflow-status/workflow-status.exception'; | ||
|
||
@Injectable() | ||
export class WorkflowStatusWorkspaceService { | ||
constructor(private readonly twentyORMManager: TwentyORMManager) {} | ||
|
||
async createWorkflowRun(workflowVersionId: string, createdBy: ActorMetadata) { | ||
const workflowRunRepository = | ||
await this.twentyORMManager.getRepository<WorkflowRunWorkspaceEntity>( | ||
'workflowRun', | ||
); | ||
|
||
return ( | ||
await workflowRunRepository.save({ | ||
workflowVersionId, | ||
createdBy, | ||
status: WorkflowRunStatus.NOT_STARTED, | ||
}) | ||
).id; | ||
} | ||
|
||
async startWorkflowRun(workflowRunId: string) { | ||
const workflowRunRepository = | ||
await this.twentyORMManager.getRepository<WorkflowRunWorkspaceEntity>( | ||
'workflowRun', | ||
); | ||
|
||
const workflowRunToUpdate = await workflowRunRepository.findOneBy({ | ||
id: workflowRunId, | ||
}); | ||
|
||
if (!workflowRunToUpdate) { | ||
throw new WorkflowStatusException( | ||
'No workflow run to start', | ||
WorkflowStatusExceptionCode.WORKFLOW_RUN_NOT_FOUND, | ||
); | ||
} | ||
|
||
if (workflowRunToUpdate.status !== WorkflowRunStatus.NOT_STARTED) { | ||
throw new WorkflowStatusException( | ||
'Workflow run already started', | ||
WorkflowStatusExceptionCode.INVALID_OPERATION, | ||
); | ||
} | ||
|
||
return workflowRunRepository.update(workflowRunToUpdate.id, { | ||
status: WorkflowRunStatus.RUNNING, | ||
startedAt: new Date().toISOString(), | ||
}); | ||
} | ||
|
||
async endWorkflowRun(workflowRunId: string, status: WorkflowRunStatus) { | ||
const workflowRunRepository = | ||
await this.twentyORMManager.getRepository<WorkflowRunWorkspaceEntity>( | ||
'workflowRun', | ||
); | ||
|
||
const workflowRunToUpdate = await workflowRunRepository.findOneBy({ | ||
id: workflowRunId, | ||
}); | ||
|
||
if (!workflowRunToUpdate) { | ||
throw new WorkflowStatusException( | ||
'No workflow run to end', | ||
WorkflowStatusExceptionCode.WORKFLOW_RUN_NOT_FOUND, | ||
); | ||
} | ||
|
||
if (workflowRunToUpdate.status !== WorkflowRunStatus.RUNNING) { | ||
throw new WorkflowStatusException( | ||
'Workflow cannot be ended as it is not running', | ||
WorkflowStatusExceptionCode.INVALID_OPERATION, | ||
); | ||
} | ||
|
||
return workflowRunRepository.update(workflowRunToUpdate.id, { | ||
status, | ||
endedAt: new Date().toISOString(), | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters