mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-18 13:38:53 -04:00
Fixed bug in letter job schedule
This commit is contained in:
@@ -308,10 +308,10 @@ def populate_monthly_billing():
|
|||||||
@notify_celery.task(name="run-letter-jobs")
|
@notify_celery.task(name="run-letter-jobs")
|
||||||
@statsd(namespace="tasks")
|
@statsd(namespace="tasks")
|
||||||
def run_letter_jobs():
|
def run_letter_jobs():
|
||||||
ids = dao_get_letter_jobs_by_status(JOB_STATUS_READY_TO_SEND)
|
job_ids = [job.id for job in dao_get_letter_jobs_by_status(JOB_STATUS_READY_TO_SEND)]
|
||||||
notify_celery.send_task(
|
notify_celery.send_task(
|
||||||
name=QueueNames.DVLA_FILES,
|
name=QueueNames.DVLA_FILES,
|
||||||
args=(ids),
|
args=(job_ids),
|
||||||
queue=QueueNames.PROCESS_FTP
|
queue=QueueNames.PROCESS_FTP
|
||||||
)
|
)
|
||||||
current_app.logger.info("Queued {} ready letter job ids onto {}".format(len(ids), QueueNames.PROCESS_FTP))
|
current_app.logger.info("Queued {} ready letter job ids onto {}".format(len(job_ids), QueueNames.PROCESS_FTP))
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ from app.dao.provider_details_dao import (
|
|||||||
from app.models import (
|
from app.models import (
|
||||||
Service, Template,
|
Service, Template,
|
||||||
SMS_TYPE, LETTER_TYPE,
|
SMS_TYPE, LETTER_TYPE,
|
||||||
|
JOB_STATUS_READY_TO_SEND,
|
||||||
MonthlyBilling)
|
MonthlyBilling)
|
||||||
from app.utils import get_london_midnight_in_utc, convert_utc_to_bst
|
from app.utils import get_london_midnight_in_utc, convert_utc_to_bst
|
||||||
from tests.app.db import create_notification, create_service, create_template, create_job, create_rate
|
from tests.app.db import create_notification, create_service, create_template, create_job, create_rate
|
||||||
@@ -683,16 +684,17 @@ def test_populate_monthly_billing_updates_correct_month_in_bst(sample_template):
|
|||||||
assert monthly_billing[1].monthly_totals[0]['total_cost'] == 0.0123
|
assert monthly_billing[1].monthly_totals[0]['total_cost'] == 0.0123
|
||||||
|
|
||||||
|
|
||||||
def test_run_letter_jobs(client, mocker):
|
def test_run_letter_jobs(client, mocker, sample_letter_template):
|
||||||
job_ids = [str(uuid.uuid4()), str(uuid.uuid4())]
|
jobs = [create_job(template=sample_letter_template, job_status=JOB_STATUS_READY_TO_SEND),
|
||||||
|
create_job(template=sample_letter_template, job_status=JOB_STATUS_READY_TO_SEND)]
|
||||||
mocker.patch(
|
mocker.patch(
|
||||||
"app.celery.scheduled_tasks.dao_get_letter_jobs_by_status",
|
"app.celery.scheduled_tasks.dao_get_letter_jobs_by_status",
|
||||||
return_value=job_ids
|
return_value=jobs
|
||||||
)
|
)
|
||||||
mock_celery = mocker.patch("app.celery.tasks.notify_celery.send_task")
|
mock_celery = mocker.patch("app.celery.tasks.notify_celery.send_task")
|
||||||
|
|
||||||
run_letter_jobs()
|
run_letter_jobs()
|
||||||
|
|
||||||
mock_celery.assert_called_once_with(name=QueueNames.DVLA_FILES,
|
mock_celery.assert_called_once_with(name=QueueNames.DVLA_FILES,
|
||||||
args=(job_ids),
|
args=([job.id for job in jobs]),
|
||||||
queue=QueueNames.PROCESS_FTP)
|
queue=QueueNames.PROCESS_FTP)
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ from tests.app.conftest import sample_template as create_template
|
|||||||
from tests.app.db import (
|
from tests.app.db import (
|
||||||
create_user,
|
create_user,
|
||||||
create_job as create_db_job,
|
create_job as create_db_job,
|
||||||
|
create_service as create_db_service,
|
||||||
create_template as create_db_template
|
create_template as create_db_template
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -551,16 +552,34 @@ def stats_set_up(notify_db, notify_db_session, service):
|
|||||||
|
|
||||||
|
|
||||||
def test_dao_get_letter_jobs_by_status(sample_service):
|
def test_dao_get_letter_jobs_by_status(sample_service):
|
||||||
create_db_template(service=sample_service, template_type=SMS_TYPE)
|
another_service = create_db_service(service_name="another service")
|
||||||
create_db_template(service=sample_service, template_type=EMAIL_TYPE)
|
|
||||||
|
sms_template = create_db_template(service=sample_service, template_type=SMS_TYPE)
|
||||||
|
email_template = create_db_template(service=sample_service, template_type=EMAIL_TYPE)
|
||||||
letter_template = create_db_template(service=sample_service, template_type=LETTER_TYPE)
|
letter_template = create_db_template(service=sample_service, template_type=LETTER_TYPE)
|
||||||
jobs = []
|
another_letter_template = create_db_template(service=another_service, template_type=LETTER_TYPE)
|
||||||
jobs.append(create_db_job(letter_template, job_status=JOB_STATUS_READY_TO_SEND, original_file_name='1.csv'))
|
ready_letter_jobs = []
|
||||||
jobs.append(create_db_job(letter_template, job_status=JOB_STATUS_READY_TO_SEND, original_file_name='2.csv'))
|
ready_letter_jobs.append(
|
||||||
create_db_job(letter_template, job_status=JOB_STATUS_SENT_TO_DVLA, original_file_name='3.csv')
|
create_db_job(
|
||||||
create_db_job(letter_template, job_status=JOB_STATUS_FINISHED, original_file_name='4.csv')
|
letter_template,
|
||||||
create_db_job(letter_template, job_status=JOB_STATUS_PENDING, original_file_name='5.csv')
|
job_status=JOB_STATUS_READY_TO_SEND,
|
||||||
|
original_file_name='1.csv'
|
||||||
|
)
|
||||||
|
)
|
||||||
|
ready_letter_jobs.append(
|
||||||
|
create_db_job(
|
||||||
|
another_letter_template,
|
||||||
|
job_status=JOB_STATUS_READY_TO_SEND,
|
||||||
|
original_file_name='2.csv'
|
||||||
|
)
|
||||||
|
)
|
||||||
|
create_db_job(sms_template, job_status=JOB_STATUS_FINISHED)
|
||||||
|
create_db_job(email_template, job_status=JOB_STATUS_FINISHED)
|
||||||
|
create_db_job(letter_template, job_status=JOB_STATUS_SENT_TO_DVLA)
|
||||||
|
create_db_job(letter_template, job_status=JOB_STATUS_FINISHED)
|
||||||
|
create_db_job(letter_template, job_status=JOB_STATUS_PENDING)
|
||||||
|
|
||||||
result = dao_get_letter_jobs_by_status(JOB_STATUS_READY_TO_SEND)
|
result = dao_get_letter_jobs_by_status(JOB_STATUS_READY_TO_SEND)
|
||||||
|
|
||||||
assert len(result) == 2
|
assert len(result) == 2
|
||||||
assert set(result) == set(jobs)
|
assert set(result) == set(ready_letter_jobs)
|
||||||
|
|||||||
Reference in New Issue
Block a user