@mcma/api
Advanced tools
Comparing version 0.13.18 to 0.13.19
@@ -7,2 +7,3 @@ import { JobAssignment } from "@mcma/core"; | ||
export declare class DefaultJobRouteCollection extends DefaultRouteCollection<JobAssignment> { | ||
private dbTableProvider; | ||
private workerInvoker; | ||
@@ -12,2 +13,3 @@ constructor(dbTableProvider: DocumentDatabaseTableProvider, workerInvoker: WorkerInvoker, root?: string); | ||
onJobAssignmentCreationCompleted(requestContext: McmaApiRequestContext, jobAssignment: JobAssignment): Promise<void>; | ||
processCancel(requestContext: McmaApiRequestContext): Promise<void>; | ||
} |
@@ -6,11 +6,16 @@ "use strict"; | ||
const core_1 = require("@mcma/core"); | ||
const data_1 = require("@mcma/data"); | ||
const worker_invoker_1 = require("@mcma/worker-invoker"); | ||
const default_route_collection_1 = require("./default-route-collection"); | ||
const config_variables_ext_1 = require("../../config-variables-ext"); | ||
const http_1 = require("../../http"); | ||
class DefaultJobRouteCollection extends default_route_collection_1.DefaultRouteCollection { | ||
constructor(dbTableProvider, workerInvoker, root) { | ||
super(dbTableProvider, core_1.JobAssignment, root); | ||
this.dbTableProvider = dbTableProvider; | ||
this.workerInvoker = workerInvoker; | ||
this.create.onStarted = reqCtx => this.onJobAssignmentCreationStarted(reqCtx); | ||
this.create.onCompleted = (reqCtx, jobAssignment) => this.onJobAssignmentCreationCompleted(reqCtx, jobAssignment); | ||
this.remove("update"); | ||
this.addRoute("POST", "/job-assignments/{id}/cancel", this.processCancel.bind(this)); | ||
} | ||
@@ -33,3 +38,26 @@ async onJobAssignmentCreationStarted(requestContext) { | ||
} | ||
async processCancel(requestContext) { | ||
const request = requestContext.request; | ||
const table = await this.dbTableProvider.get(data_1.getTableName()); | ||
const jobAssignmentDatabaseId = "/job-assignments/" + request.pathVariables.id; | ||
const jobAssignment = await table.get(jobAssignmentDatabaseId); | ||
if (!jobAssignment) { | ||
requestContext.setResponseResourceNotFound(); | ||
return; | ||
} | ||
if (jobAssignment.status === core_1.JobStatus.Completed || | ||
jobAssignment.status === core_1.JobStatus.Failed || | ||
jobAssignment.status === core_1.JobStatus.Canceled) { | ||
requestContext.setResponseStatusCode(http_1.HttpStatusCode.Conflict, "JobAssignment is already in a final state"); | ||
return; | ||
} | ||
await this.workerInvoker.invoke(worker_invoker_1.getWorkerFunctionId(), { | ||
operationName: "ProcessCancel", | ||
input: { | ||
jobAssignmentDatabaseId | ||
}, | ||
tracker: jobAssignment.tracker | ||
}); | ||
} | ||
} | ||
exports.DefaultJobRouteCollection = DefaultJobRouteCollection; |
{ | ||
"name": "@mcma/api", | ||
"version": "0.13.18", | ||
"version": "0.13.19", | ||
"description": "Node module for building APIs based on the EBU MCMA framework", | ||
@@ -40,12 +40,12 @@ "engines": { | ||
"peerDependencies": { | ||
"@mcma/client": "0.13.18", | ||
"@mcma/core": "0.13.18", | ||
"@mcma/data": "0.13.18", | ||
"@mcma/worker-invoker": "0.13.18" | ||
"@mcma/client": "0.13.19", | ||
"@mcma/core": "0.13.19", | ||
"@mcma/data": "0.13.19", | ||
"@mcma/worker-invoker": "0.13.19" | ||
}, | ||
"devDependencies": { | ||
"@mcma/client": "0.13.18", | ||
"@mcma/core": "0.13.18", | ||
"@mcma/data": "0.13.18", | ||
"@mcma/worker-invoker": "0.13.18", | ||
"@mcma/client": "0.13.19", | ||
"@mcma/core": "0.13.19", | ||
"@mcma/data": "0.13.19", | ||
"@mcma/worker-invoker": "0.13.19", | ||
"@types/node": "^13.7.4", | ||
@@ -52,0 +52,0 @@ "@types/pluralize": "0.0.29", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
59905
1244