mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 09:51:11 -05:00
Archive job after corresponding file deleted from s3
This commit is contained in:
committed by
Alexey Bezhan
parent
641cb6ec36
commit
50811c3b8e
@@ -23,7 +23,8 @@ from app.dao.invited_org_user_dao import delete_org_invitations_created_more_tha
|
|||||||
from app.dao.invited_user_dao import delete_invitations_created_more_than_two_days_ago
|
from app.dao.invited_user_dao import delete_invitations_created_more_than_two_days_ago
|
||||||
from app.dao.jobs_dao import (
|
from app.dao.jobs_dao import (
|
||||||
dao_set_scheduled_jobs_to_pending,
|
dao_set_scheduled_jobs_to_pending,
|
||||||
dao_get_jobs_older_than_data_retention
|
dao_get_jobs_older_than_data_retention,
|
||||||
|
dao_archive_job
|
||||||
)
|
)
|
||||||
from app.dao.jobs_dao import dao_update_job
|
from app.dao.jobs_dao import dao_update_job
|
||||||
from app.dao.notifications_dao import (
|
from app.dao.notifications_dao import (
|
||||||
@@ -67,7 +68,7 @@ def remove_csv_files(job_types):
|
|||||||
jobs = dao_get_jobs_older_than_data_retention(notification_types=job_types)
|
jobs = dao_get_jobs_older_than_data_retention(notification_types=job_types)
|
||||||
for job in jobs:
|
for job in jobs:
|
||||||
s3.remove_job_from_s3(job.service_id, job.id)
|
s3.remove_job_from_s3(job.service_id, job.id)
|
||||||
# job.archived = true; commit;
|
dao_archive_job(job)
|
||||||
current_app.logger.info("Job ID {} has been removed from s3.".format(job.id))
|
current_app.logger.info("Job ID {} has been removed from s3.".format(job.id))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -66,6 +66,11 @@ def dao_get_jobs_by_service_id(service_id, limit_days=None, page=1, page_size=50
|
|||||||
def dao_get_job_by_id(job_id):
|
def dao_get_job_by_id(job_id):
|
||||||
return Job.query.filter_by(id=job_id).one()
|
return Job.query.filter_by(id=job_id).one()
|
||||||
|
|
||||||
|
def dao_archive_job(job):
|
||||||
|
job.archived = True
|
||||||
|
db.session.add(job)
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
|
||||||
def dao_set_scheduled_jobs_to_pending():
|
def dao_set_scheduled_jobs_to_pending():
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -295,7 +295,7 @@ def test_will_remove_csv_files_for_jobs_older_than_seven_days(
|
|||||||
job3_to_delete = create_sample_job(notify_db, notify_db_session, created_at=nine_days_one_second_ago)
|
job3_to_delete = create_sample_job(notify_db, notify_db_session, created_at=nine_days_one_second_ago)
|
||||||
job1_to_delete = create_sample_job(notify_db, notify_db_session, created_at=eight_days_ago)
|
job1_to_delete = create_sample_job(notify_db, notify_db_session, created_at=eight_days_ago)
|
||||||
job2_to_delete = create_sample_job(notify_db, notify_db_session, created_at=just_under_nine_days)
|
job2_to_delete = create_sample_job(notify_db, notify_db_session, created_at=just_under_nine_days)
|
||||||
create_sample_job(notify_db, notify_db_session, created_at=seven_days_ago)
|
dont_delete_me_1 = create_sample_job(notify_db, notify_db_session, created_at=seven_days_ago)
|
||||||
create_sample_job(notify_db, notify_db_session, created_at=just_under_seven_days)
|
create_sample_job(notify_db, notify_db_session, created_at=just_under_seven_days)
|
||||||
|
|
||||||
remove_csv_files(job_types=[sample_template.template_type])
|
remove_csv_files(job_types=[sample_template.template_type])
|
||||||
@@ -305,6 +305,8 @@ def test_will_remove_csv_files_for_jobs_older_than_seven_days(
|
|||||||
call(job2_to_delete.service_id, job2_to_delete.id),
|
call(job2_to_delete.service_id, job2_to_delete.id),
|
||||||
call(job3_to_delete.service_id, job3_to_delete.id)
|
call(job3_to_delete.service_id, job3_to_delete.id)
|
||||||
]
|
]
|
||||||
|
assert job1_to_delete.archived == True
|
||||||
|
assert dont_delete_me_1.archived == False
|
||||||
|
|
||||||
|
|
||||||
@freeze_time('2016-10-18T10:00:00')
|
@freeze_time('2016-10-18T10:00:00')
|
||||||
|
|||||||
Reference in New Issue
Block a user