async def post(self): """ --- summary: Schedule a list of Jobs from a list of job descriptions. description: | Given a list of jobs from /export/jobs, each will be scheduled to run on the intervals that are set in their trigger arguments. parameters: - name: jobs in: body description: The Jobs to create/schedule schema: type: array items: $ref: '#/definitions/JobImport' responses: 201: description: All new jobs have been created schema: $ref: '#/definitions/JobExport' 400: $ref: '#/definitions/400Error' 50x: $ref: '#/definitions/50xError' tags: - Jobs """ parsed_job_list = SchemaParser.parse_job(self.request_body, many=True) for job in parsed_job_list: self.verify_user_permission_for_object(JOB_CREATE, job) create_jobs_output = create_jobs(parsed_job_list) created_jobs = create_jobs_output["created"] response = {"ids": [job.id for job in created_jobs]} self.set_status(201) self.set_header("Content-Type", "application/json; charset=UTF-8") self.write(response)
async def post(self): """ --- summary: Schedules a Job to be run. description: | Given a job, it will be scheduled to run on the interval set in the trigger argument. parameters: - name: job in: body description: The Job to create/schedule schema: $ref: '#/definitions/Job' responses: 201: description: A new job has been created schema: $ref: '#/definitions/Job' 400: $ref: '#/definitions/400Error' 50x: $ref: '#/definitions/50xError' tags: - Jobs """ job = SchemaParser.parse_job(self.request.body.decode("utf-8"), from_string=True) self.verify_user_permission_for_object(JOB_CREATE, job) response = await self.client( Operation( operation_type="JOB_CREATE", args=[job], )) self.set_status(201) self.set_header("Content-Type", "application/json; charset=UTF-8") self.write(response)
async def patch(self, job_id): """ --- summary: Pause/Resume a job description: | The body of the request needs to contain a set of instructions detailing the actions to take. Currently the only operation supported is `update` with `path` of `/status`. You can pause a job with: ```JSON { "operation": "update", "path": "/status", "value": "PAUSED" } ``` And resume it with: ```JSON { "operation": "update", "path": "/status", "value": "RUNNING" } ``` parameters: - name: job_id in: path required: true description: The ID of the Job type: string - name: patch in: body required: true description: Instructions for the actions to take schema: $ref: '#/definitions/Patch' responses: 200: description: Job with the given ID schema: $ref: '#/definitions/Job' 400: $ref: '#/definitions/400Error' 404: $ref: '#/definitions/404Error' 50x: $ref: '#/definitions/50xError' tags: - Jobs """ patch = SchemaParser.parse_patch(self.request.decoded_body, from_string=True) for op in patch: if op.operation == "update": if op.path == "/status": if str(op.value).upper() == "PAUSED": response = await self.client( Operation(operation_type="JOB_PAUSE", args=[job_id])) elif str(op.value).upper() == "RUNNING": response = await self.client( Operation(operation_type="JOB_RESUME", args=[job_id])) else: raise ModelValidationError( f"Unsupported status value '{op.value}'") elif op.path == "/job": response = await self.client( Operation( operation_type="JOB_UPDATE", args=[SchemaParser.parse_job(op.value)], )) else: raise ModelValidationError( f"Unsupported path value '{op.path}'") else: raise ModelValidationError( f"Unsupported operation '{op.operation}'") self.set_header("Content-Type", "application/json; charset=UTF-8") self.write(response)