Skip to content

Commit

Permalink
added some fixes to job status
Browse files Browse the repository at this point in the history
  • Loading branch information
aagm committed Aug 16, 2021
1 parent f7fad03 commit d0dbb5e
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,26 +76,32 @@ export class ScenarioJobStatus {
const eventToJobStatusMapping: Record<ValuesType<ScenarioEvents>, JobStatus> = {
[API_EVENT_KINDS.scenario__costSurface__costUpdateFailed__v1_alpha1]:
JobStatus.failure,
[API_EVENT_KINDS.scenario__costSurface__finished__v1_alpha1]: JobStatus.done,
[API_EVENT_KINDS.scenario__costSurface__finished__v1_alpha1]:
JobStatus.done,
[API_EVENT_KINDS.scenario__costSurface__shapeConversionFailed__v1_alpha1]:
JobStatus.failure,
[API_EVENT_KINDS.scenario__costSurface__shapeConverted__v1_alpha1]:
JobStatus.running,
[API_EVENT_KINDS.scenario__costSurface__submitted__v1_alpha1]:
JobStatus.running,
[API_EVENT_KINDS.scenario__run__progress__v1__alpha1]: JobStatus.running,
[API_EVENT_KINDS.scenario__run__progress__v1__alpha1]:
JobStatus.running,
[API_EVENT_KINDS.scenario__planningUnitsInclusion__failed__v1__alpha1]:
JobStatus.failure,
[API_EVENT_KINDS.scenario__planningUnitsInclusion__finished__v1__alpha1]:
JobStatus.done,
[API_EVENT_KINDS.scenario__planningUnitsInclusion__submitted__v1__alpha1]:
JobStatus.running,
[API_EVENT_KINDS.scenario__run__submitted__v1__alpha1]: JobStatus.running,
[API_EVENT_KINDS.scenario__run__finished__v1__alpha1]: JobStatus.running,
[API_EVENT_KINDS.scenario__run__failed__v1__alpha1]: JobStatus.failure,
[API_EVENT_KINDS.scenario__run__submitted__v1__alpha1]:
JobStatus.running,
[API_EVENT_KINDS.scenario__run__finished__v1__alpha1]:
JobStatus.running,
[API_EVENT_KINDS.scenario__run__failed__v1__alpha1]:
JobStatus.failure,
[API_EVENT_KINDS.scenario__run__outputSaveFailed__v1__alpha1]:
JobStatus.failure,
[API_EVENT_KINDS.scenario__run__outputSaved__v1__alpha1]: JobStatus.done,
[API_EVENT_KINDS.scenario__run__outputSaved__v1__alpha1]:
JobStatus.done,
[API_EVENT_KINDS.scenario__geofeatureCopy__submitted__v1__alpha1]:
JobStatus.running,
[API_EVENT_KINDS.scenario__geofeatureCopy__failed__v1__alpha1]:
Expand All @@ -114,7 +120,7 @@ const eventToJobStatusMapping: Record<ValuesType<ScenarioEvents>, JobStatus> = {
JobStatus.failure,
[API_EVENT_KINDS.scenario__geofeatureStratification__finished__v1__alpha1]:
JobStatus.done,
[API_EVENT_KINDS.scenario__planningAreaProtectedCalculation__failed__v1__alpha1]:
[API_EVENT_KINDS.scenario__planningAreaProtectedCalculation__failed__v1__alpha1]:
JobStatus.failure,
[API_EVENT_KINDS.scenario__planningAreaProtectedCalculation__finished__v1__alpha1]:
JobStatus.done,
Expand Down
1 change: 1 addition & 0 deletions api/apps/api/src/modules/projects/job-status/jobs.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ export enum JobType {
CostSurface = 'scenario.costSurface',
Run = 'scenario.run',
PlanningUnitInclusion = 'scenario.planningUnitsInclusion',
PlanningUnitPACalculation = 'scenario.planningAreaProtectedCalculation',
}
75 changes: 45 additions & 30 deletions data/bots/demo-australia/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,38 +96,62 @@ const scenarioStart = Process.hrtime();

await sleep(5)

// get the list of protected areas in the region and use all of them
const paCategories = await botClient.get(`/protected-areas/iucn-categories?filter%5BcustomAreaId%5D=${planningAreaFile.id}`)
.then((result:{data:Array<{id:string, type:string, attributes:object}>}) => result.data)
const paCategories:{data:Array<{id:string, type:string, attributes:object}>} = await botClient.get(`/protected-areas/iucn-categories?filter%5BcustomAreaId%5D=${planningAreaFile.id}`)
.then((result) => result.data)
.catch((e) => {
console.log(e);
});

console.log(paCategories);
console.log(paCategories.map((i): string => i.id));


const scenario = await botClient
.post("/scenarios", {
name: `Kimberley ${project.data.attributes.name}`,
type: "marxan",
projectId: project.data.id,
description: "An Australia scenario",
wdpaIucnCategories: ["Not Applicable"],
wdpaThreshold: 50,
description: "An Australia scenario"
})
.then((result) => result.data)
.catch((e) => {
console.log(e);
});
await sleep(5)
// get the list of protected areas in the region and use all of them

await botClient
.patch(`/scenarios/${scenario!.data!.id}`, {
wdpaIucnCategories: paCategories!.data.map((i: {id:string, type:string, attributes:object}): string => i.id),
}).catch((e) => {
console.log(e);
});

console.log(scenario);

await sleep(20)

await botClient
.patch(`/scenarios/${scenario!.data!.id}`, {
wdpaThreshold: 50,
}).catch((e) => {
console.log(e);
});

const scenarioTook = Process.hrtime(scenarioStart);
console.log(`Scenario creation done in ${scenarioTook[0]} seconds`);

console.log(scenario);
await botClient.get(`/scenarios/${scenario!.data!.id}`)
.then((result) => console.log(result.data))
.catch((e) => {
console.log(e);
});

await sleep(5)

// Setup features in the project

const features = await botClient
.get(`/projects/${project.data.id}/features?q=demo_`)
.get(`/projects/${project.data.id}/features?q=demo`)
.then((result) => result.data)
.catch((e) => {
console.log(e);
Expand All @@ -137,28 +161,19 @@ console.log(features);

const geoFeatureSpecStart = Process.hrtime();

// const featureRecipe = features.forEach(element => element.id); { return {
// kind: "plain",
// featureId: x.id,
// marxanSettings: {
// prop: 0.3,
// fpf: 1,
// },
// }})
// console.log(featureRecipe);
const featureRecipe = features!.data.map((x: {id:string, type:string, attributes:object}) => { return {
kind: "plain",
featureId: x.id,
marxanSettings: {
prop: 0.3,
fpf: 1,
},
}})
console.log(featureRecipe);
const geoFeatureSpec = await botClient
.post(`/scenarios/${scenario.data.id}/features/specification`, {
status: "draft",
features: [
{
kind: "plain",
featureId: features.data[0].id,
marxanSettings: {
prop: 0.3,
fpf: 1,
},
},
],
status: "created",
features: featureRecipe
})
.then((result) => result.data)
.catch((e) => {
Expand All @@ -171,4 +186,4 @@ console.log(
`Processing of features for scenario done in ${geoFeatureSpecTook[0]} seconds`
);

console.log(geoFeatureSpec);
// console.log(geoFeatureSpec);
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ services:
build:
context: ./postgresql
dockerfile: Dockerfile
shm_size: 1gb
container_name: marxan-postgresql-api
ports:
- "${POSTGRES_API_SERVICE_PORT}:5432"
Expand Down

0 comments on commit d0dbb5e

Please sign in to comment.