-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(project): include project-related jobs in status
- Loading branch information
Showing
12 changed files
with
195 additions
and
45 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
api/apps/api/src/migrations/api/1631254563649-ProjectJobsStatus.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,28 @@ | ||
import { QueryRunner } from 'typeorm'; | ||
|
||
export class ProjectJobsStatus1631254563649 { | ||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(` | ||
CREATE VIEW "project_job_status" as | ||
SELECT DISTINCT ON (job_type, topic) job_type, | ||
api_events.topic AS project_id, | ||
api_events.kind, | ||
api_events.data | ||
FROM api_events | ||
CROSS JOIN LATERAL SUBSTRING( | ||
api_events.kind | ||
FROM | ||
'project.#"[^.]*#"%' FOR '#' | ||
) AS job_type | ||
ORDER BY job_type, | ||
api_events.topic, | ||
api_events.timestamp DESC; | ||
`); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(` | ||
DROP VIEW "project_job_status"; | ||
`); | ||
} | ||
} |
7 changes: 4 additions & 3 deletions
7
api/apps/api/src/modules/projects/dto/job-status.serializer.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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,8 @@ | ||
export { JobType } from './jobs.enum'; | ||
export { Job, Scenario, Status, JobStatusService } from './job-status.service'; | ||
export { | ||
Job, | ||
Scenario, | ||
Status, | ||
JobStatusService, | ||
ProjectWithScenarios, | ||
} from './job-status.service'; |
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
57 changes: 57 additions & 0 deletions
57
api/apps/api/src/modules/projects/job-status/project-status.view.api.entity.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,57 @@ | ||
import { ViewColumn, ViewEntity } from 'typeorm'; | ||
import { JobType } from '@marxan-api/modules/projects/job-status/jobs.enum'; | ||
import { JobStatus } from '@marxan-api/modules/scenarios/scenario.api.entity'; | ||
import { ApiEvent } from '@marxan-api/modules/api-events/api-event.api.entity'; | ||
import { API_EVENT_KINDS, ProjectEvents } from '@marxan/api-events'; | ||
import { ValuesType } from 'utility-types'; | ||
|
||
@ViewEntity({ | ||
expression: ` | ||
SELECT DISTINCT ON (job_type, topic) job_type, | ||
api_events.topic AS project_id, | ||
api_events.kind, | ||
api_events.data | ||
FROM api_events | ||
CROSS JOIN LATERAL SUBSTRING( | ||
api_events.kind | ||
FROM | ||
'project.#"[^.]*#"%' FOR '#' | ||
) AS job_type | ||
ORDER BY job_type, | ||
api_events.topic, | ||
api_events.timestamp DESC | ||
`, | ||
}) | ||
export class ProjectJobStatus { | ||
@ViewColumn({ | ||
name: 'job_type', | ||
}) | ||
jobType!: JobType; | ||
|
||
@ViewColumn() | ||
kind!: Extract<API_EVENT_KINDS, `project.${string}`>; | ||
|
||
get jobStatus(): JobStatus | undefined { | ||
return eventToJobStatusMapping[this.kind]; | ||
} | ||
|
||
@ViewColumn({ | ||
name: 'project_id', | ||
}) | ||
projectId!: string; | ||
|
||
@ViewColumn() | ||
data!: ApiEvent['data']; | ||
} | ||
|
||
const eventToJobStatusMapping: Record<ValuesType<ProjectEvents>, JobStatus> = { | ||
[API_EVENT_KINDS.project__grid__failed__v1__alpha]: JobStatus.failure, | ||
[API_EVENT_KINDS.project__grid__finished__v1__alpha]: JobStatus.done, | ||
[API_EVENT_KINDS.project__grid__submitted__v1__alpha]: JobStatus.running, | ||
[API_EVENT_KINDS.project__protectedAreas__failed__v1__alpha]: | ||
JobStatus.failure, | ||
[API_EVENT_KINDS.project__protectedAreas__finished__v1__alpha]: | ||
JobStatus.done, | ||
[API_EVENT_KINDS.project__protectedAreas__submitted__v1__alpha]: | ||
JobStatus.running, | ||
}; |
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