diff --git a/server/errors.py b/server/errors.py index 693609c6..b4df151a 100644 --- a/server/errors.py +++ b/server/errors.py @@ -23,7 +23,7 @@ class NotFound(HTTPException): errors = { "RecordAlreadyExistError": { - "message": "sample unique name already exists", + "message": "Record already exists", "status": 400 }, "InternalServerError": { diff --git a/server/rest/cronjob/cronjobs_controller.py b/server/rest/cronjob/cronjobs_controller.py index 5cd55eb7..86fa323f 100644 --- a/server/rest/cronjob/cronjobs_controller.py +++ b/server/rest/cronjob/cronjobs_controller.py @@ -35,19 +35,27 @@ def post(self, model): if cronjob: raise RecordAlreadyExistError cronjob = CronJob(cronjob_type=model, status= CronJobStatus.PENDING).save() - resp = cronjob.to_json() print(f'Triggering job {model}') + is_error = False + message = '' try: JOB_MAP[model]() + message = f'job {model} successfully executed' except: - print(f'Error executing job {model}') + message = f'Error executing job {model}' + is_error = True + print(message) finally: cronjob.delete() - return Response(resp, mimetype="application/json", status=201) + if is_error: + code = 400 + else: + code = 201 + return Response(message, mimetype="application/json", status=code) @jwt_required() def delete(self, model): - cron = CronJob.onjects(cronjob_type=model) + cron = CronJob.objects(cronjob_type=model) if not cron: raise NotFound cron.delete()