mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-20 15:31:15 -05:00
merge from main
This commit is contained in:
@@ -25,8 +25,8 @@ from app.dao.notifications_dao import (
|
||||
)
|
||||
from app.dao.services_dao import dao_fetch_service_by_id
|
||||
from app.dao.templates_dao import dao_get_template_by_id
|
||||
from app.enums import JobStatus
|
||||
from app.errors import InvalidRequest, register_errors
|
||||
from app.models import JOB_STATUS_CANCELLED, JOB_STATUS_PENDING, JOB_STATUS_SCHEDULED
|
||||
from app.schemas import (
|
||||
job_schema,
|
||||
notification_with_template_schema,
|
||||
@@ -57,7 +57,7 @@ def get_job_by_service_and_job_id(service_id, job_id):
|
||||
@job_blueprint.route("/<job_id>/cancel", methods=["POST"])
|
||||
def cancel_job(service_id, job_id):
|
||||
job = dao_get_future_scheduled_job_by_id_and_service_id(job_id, service_id)
|
||||
job.job_status = JOB_STATUS_CANCELLED
|
||||
job.job_status = JobStatus.CANCELLED
|
||||
dao_update_job(job)
|
||||
|
||||
return get_job_by_service_and_job_id(service_id, job_id)
|
||||
@@ -137,20 +137,28 @@ def get_jobs_by_service(service_id):
|
||||
try:
|
||||
limit_days = int(request.args["limit_days"])
|
||||
except ValueError:
|
||||
errors = {
|
||||
"limit_days": [
|
||||
"{} is not an integer".format(request.args["limit_days"])
|
||||
]
|
||||
}
|
||||
errors = {"limit_days": [f"{request.args['limit_days']} is not an integer"]}
|
||||
raise InvalidRequest(errors, status_code=400)
|
||||
else:
|
||||
limit_days = None
|
||||
|
||||
valid_statuses = set(JobStatus)
|
||||
statuses_arg = request.args.get("statuses", "")
|
||||
if statuses_arg == "":
|
||||
statuses = None
|
||||
else:
|
||||
statuses = []
|
||||
for x in statuses_arg.split(","):
|
||||
status = x.strip()
|
||||
if status in valid_statuses:
|
||||
statuses.append(status)
|
||||
else:
|
||||
statuses.append(None)
|
||||
return jsonify(
|
||||
**get_paginated_jobs(
|
||||
service_id,
|
||||
limit_days=limit_days,
|
||||
statuses=[x.strip() for x in request.args.get("statuses", "").split(",")],
|
||||
statuses=statuses,
|
||||
page=int(request.args.get("page", 1)),
|
||||
)
|
||||
)
|
||||
@@ -187,13 +195,13 @@ def create_job(service_id):
|
||||
job = job_schema.load(data)
|
||||
|
||||
if job.scheduled_for:
|
||||
job.job_status = JOB_STATUS_SCHEDULED
|
||||
job.job_status = JobStatus.SCHEDULED
|
||||
|
||||
dao_create_job(job)
|
||||
|
||||
sender_id = data.get("sender_id")
|
||||
|
||||
if job.job_status == JOB_STATUS_PENDING:
|
||||
if job.job_status == JobStatus.PENDING:
|
||||
process_job.apply_async(
|
||||
[str(job.id)], {"sender_id": sender_id}, queue=QueueNames.JOBS
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user