Skip to content

Commit

Permalink
fix cronjob api
Browse files Browse the repository at this point in the history
  • Loading branch information
emiliorighi committed Dec 12, 2023
1 parent 46100ae commit 862aa15
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion server/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class NotFound(HTTPException):

errors = {
"RecordAlreadyExistError": {
"message": "sample unique name already exists",
"message": "Record already exists",
"status": 400
},
"InternalServerError": {
Expand Down
16 changes: 12 additions & 4 deletions server/rest/cronjob/cronjobs_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 862aa15

Please sign in to comment.