Commit Graph

208 Commits

Author SHA1 Message Date
Rebecca Law
c9477a7400 When a notification is timed out in the scheduled task that may happen because the notification has not been sent.
Which means the sent_at date for the notification could be empty causing the service callback to fail.

- Allow code to work if notification.sent_at or updated_at is None
- Update calls to send_delivery_status_to_service to send the data encrypted so that the task does not need to use the db.
2018-03-16 14:47:56 +00:00
Rebecca Law
68d658086b Merge pull request #1759 from alphagov/fix-bug-timeout-notifications
Fix the bug in timeout notifications.
2018-03-13 09:34:33 +00:00
Rebecca Law
144356f096 Fix the bug in timeout notifications.
When the notification is timedout by the scheduled task if the service is expecting a status update, that update to the service would fail.
A test has been added.
2018-03-12 12:15:03 +00:00
Katie Smith
4f7dd1d258 Delete job statistics tasks
The tasks are no longer being used, so can be deleted safely:
* record_initial_job_statistics
* record_outcome_job_statistics
* timeout-job-statistics

The test file for the statistics tasks was deleted in a previous commit.
2018-03-12 10:48:46 +00:00
Leo Hemsted
64bb94af9e set job status to error in the check_job_status scheduled task
the process_incomplete_jobs task runs through all incomplete jobs in
a loop, so it might not get a chance to update the processing_started
time of the last job before check_job_status runs again (every minute).
So before we even trigger the process_incomplete_jobs task, lets set
the status of the jobs to error, so that we don't identify them for
re-processing again.
2018-03-09 16:42:58 +00:00
Leo Hemsted
f0ca3d40de reset job processing time when re-processing incomplete jobs
we might stop processing jobs mid-way through if, for example, a
deploy or downscale kills the box working on it. We have a scheduled
task that identifies any job that we started processing more than half
an hour ago that is still processing.

However, we encountered a bug where we triggered the
process_incomplete_job multiple times, because the processing_started
of the job was still set to half an hour ago. If we reset the
processing_started to the current time, then it won't get picked up by
future runs of the check_job_status scheduled task.
2018-03-09 16:30:50 +00:00
Chris Hill-Scott
ca167206d5 Add command to backfill Performance Platform totals
We don’t have any way of playing back the totals we send to performance
platform.

This commit copies the command used to backfill the processing time and
adapts it to backfill the totals instead. Under the hood it uses the
same code that we use in the scheduled tasks to update performance
platform on a daily basis. I had to modify this code to take a `day`
argument because it was hardcoded to only work for ‘yesterday’.
2018-03-05 17:02:33 +00:00
Rebecca Law
bffc4863db Remove all methods no longer used now that we only send pdf files to DVLA. 2018-03-02 11:05:05 +00:00
Rebecca Law
304f4d5c67 Remove unused methods 2018-03-02 11:05:05 +00:00
Ken Tsang
04beff7d05 Return sorted ACK files
- also fixes unit test failure due to random order of filenames
2018-01-26 14:45:36 +00:00
venusbb
8cb8de8664 changed tests 2018-01-23 10:13:56 +00:00
venusbb
2edb0c0883 Grammar change to despro ticket
Grammar change to despro ticket
Strip sets of empty elements
Strip subfolder in returned zip file list
ar change to despro ticket
2018-01-22 14:51:06 +00:00
venusbb
cf30e69e8c Processing ack files only send alerts in production environment.
Processing ack files only send alerts in production environment.
Deskpro alerts include bucket names for debugging purpose.
2018-01-22 12:44:03 +00:00
venusbb
4ffb84de36 Comparison of date needs to use AWS S3 format 2018-01-19 09:24:03 +00:00
venusbb
6a790b59aa Merge branch 'master' of https://github.com/alphagov/notifications-api into letter-S3zipchange-deskpro 2018-01-18 14:45:04 +00:00
venusbb
99dda99890 Use set rather than list to compare ack file and zip files difference 2018-01-18 14:44:23 +00:00
venusbb
357ec3a7d5 Call Deskpro ticket when there is an error 2018-01-18 11:06:07 +00:00
venusbb
8f5a5f8105 Parse acknowledgement files against .ZIP.TXT created by ftp app.
- Also convert the files info to upper() for comparison rather than lower
because original file names are in upper case. The unit tests contain examples of the returned lists.
2018-01-18 10:44:36 +00:00
Alexey Bezhan
70e3b07308 Disable Deskpro letters still sending alert in preview and staging
Since preview and staging environments don't have a full DVLA
integration they're likely to contain letter notifications in
a 'sending' state. To avoid spamming Deskpro we skip the check
unless we're in a production or test environment.
2018-01-17 17:14:20 +00:00
Alexey Bezhan
29777c3123 Add a celery scheduled task to alert if letters are still sending
We should receive a response file from DVLA by 4pm the next working
day (next Monday for letters created on Friday, Saturday or Sunday).

Response file triggers a task to update the letters status from
'sending' to either 'failed' or 'delivered', at which point there
should be no letter notifications in the 'sending' state for that day.

To catch any errors in the process (eg a missing response file from
DVLA) we add a scheduled task that checks letter notifications for
previous day (or Friday when run on Monday) and raises a Deskpro
ticket if it finds any in a 'sending' state. We're checking letter
notifications based on the `sent_at` date, which is set when the
letter PDF is sent to DVLA (so for letters created after 5:30pm it
will be the next day).

The task runs at 4:30pm, which should give the response file processing
task enough time to finish if the file was uploaded at 4pm.
2018-01-17 15:35:16 +00:00
venusbb
7d84b4629a Using key query rather than try catch
Added a unit test for empty content
2018-01-17 14:45:34 +00:00
venusbb
9179802717 Fix a typo error on task argument
Modify unit test to be more robust
2018-01-17 12:21:56 +00:00
venusbb
f273b23c25 Get ack files only from day before the ack file is received.
Take care of upper and lower case of file names and contents
Add a test for s3 get_list_of_files_by_suffix
2018-01-16 09:34:09 +00:00
venusbb
96b3c6c2ed Add tests for checking not updating database when ack file is received.
Moved S3 test scripts
Modified scheduled_task test
2018-01-12 19:24:36 +00:00
venusbb
24b785e7e0 Added process for dvla acknowledgement file
Daily schedule task to check ack file against zip file lists
if we haven't receive ack for a zip file, raise a 500 exception
2018-01-12 15:44:00 +00:00
Rebecca Law
a559338fe9 Merge branch 'master' into populate-monthly-letter-usages 2017-12-19 14:25:43 +00:00
Ken Tsang
8103540261 Renamed run-letter-pdfs to trigger-letter-pdfs-for-day
- also set optional date_to_process argument for dao_get_count_of_letters_to_process_for_date to None, so it's set in the code instead
2017-12-19 13:23:55 +00:00
Ken Tsang
88f3c17463 Trigger collate-letter-pdfs-for-day task if notis to process 2017-12-19 13:23:55 +00:00
Rebecca Law
4ea79d9eb1 Monthly billing has been updated to populate for letters. 2017-12-12 15:54:59 +00:00
Leo Hemsted
08494ef206 more flake8. lots of unused imports and variables that didn't get used. i tried to preserve old variable names as comments when it looked like they were useful (eg when they were describing timestamps) 2017-11-28 17:23:09 +00:00
Alexey Bezhan
c62f2a3f7c Update create_custom_template test helper to create history object
`create_custom_template` is not using `dao_create_template` since
it explicitly sets a template id. Notifications.template relationship
now refers to a TemplateHistory objects, so we need to make sure that
`create_custom_template` creates a matching TemplateHistory record
when it creates a Template.
2017-11-10 15:13:55 +00:00
Richard Chapman
28287abbd8 Added test to handle Null template_id
There are some Null template_ids in the production database which was
causing a failure as the stats_template_usage_by_month has a constraint
that it should not be null. This update only adds populated template_ids

- Updated Celery task
- Add a new test to test for null template_ids and not try to add them
to the stats
2017-11-10 13:49:58 +00:00
Richard Chapman
b78d989d4e Updates after review
- Modified the services_dao to return an int instead of a datetime to
make usage easier and removed the BST function on year as it is not
relevant for year
- Improved tests do there is less logic by ordering the result so there
is less reliance on the template id
- Renamed variable in stats_template_usage_by_month_dao.py to make it
consistent with the method
2017-11-09 14:13:42 +00:00
Richard Chapman
59df6bdbb6 Fixed imports which were producing broken tests
- Some tests for failing because of an import which was overriding the
one above it in test_scheduled_tasks.py
- Import error fixed in test_services_dao.py after a rename of a method
2017-11-09 11:33:56 +00:00
Richard Chapman
ff911c30d6 Added Scheduled task to get stats for template usage
Currently some pages are timing out due to the time it takes to perform
database queries. This is an attempt to improve the performance by
performing the query against the notification history table once a day
and use the notification table for a delta between midnight and the when
the page is run and combine the results.

- Added Celery task for doing the work
- Added a dao to handle the insert and update of the stats table
- Updated tests to test the new functionality
2017-11-09 10:34:49 +00:00
Rebecca Law
f52ec2c406 Added an order by to the check_job_status query. The test was failing intermittently 2017-10-18 09:50:39 +01:00
Richard Chapman
0ff80bcb76 Process Incomplete Jobs Refactor
- Moved the process_incomplete_jobs to tasks.py
- Moved the process_incomplete_jobs test to test_tasks.py
- Cleaned up imports and other code style issues.

As the new tasks is not a scheduled one, moved the the tasks.py file.
This makes it more consisted with other tasks. Updated a few code style
issues to make it more consistent with other coe and hence more
maintainable in future.
2017-10-16 12:33:39 +01:00
Richard Chapman
22b933b8f1 Merge branch 'master' of https://github.com/alphagov/notifications-api 2017-10-13 16:47:05 +01:00
Richard Chapman
0509669969 Process Incomplete Jobs
- Added a new task to process incomplete jobs
- Added tests to test the new method
- Updated the check for incomplete jobs method to start the new task

This will effectively resume tasks which for some reason were interrupted
whilst they were being processed. In some cases only some of the csv
was processed, this will find the place in the csv and continue processing
from that point.
2017-10-13 16:46:17 +01:00
kentsanggds
c110ca3f57 Merge pull request #1303 from alphagov/ken-purge-noti-to-email_reply_to
Purge notifications to email reply to rows older than 7 days
2017-10-13 15:23:58 +01:00
Rebecca Law
e08690cad2 Added a new scheduled task that runs every minute, may want to run it every 3 minutes.
The tasks checks that a job is not still in progress 30 minutes after the job started processing.
2017-10-12 16:21:08 +01:00
Ken Tsang
1eaf6e089b Refactor code to make it clearer
- Added code in `delete_notifications_created_more_than_a_week_ago_by_type` to remove notifications to email_reply_to older than 7 days
- Added transactional to `delete_notifications_created_more_than_a_week_ago_by_type`
2017-10-11 12:26:58 +01:00
Ken Tsang
2c46f201b5 Purge noti to email reply to older than 7 days 2017-10-09 14:51:27 +01:00
Leo Hemsted
c97b130540 test dvla callback update tasks 2017-09-26 12:36:42 +01:00
Leo Hemsted
aaadf09562 add tests for new sched task 2017-09-26 12:03:06 +01:00
Leo Hemsted
2c758cbccd use new send-jobs-to-dvla task instead of send-files-to-dvla
the tasks (on the ftp app) do the same thing, but to improve clarity
i've renamed it to jobs, because we'll be adding a notifications one
soon
2017-09-12 17:28:07 +01:00
Rebecca Law
e32abb0ada Merge pull request #1221 from alphagov/ken-no-letters-when-trial
Stop letters when service is in trial
2017-09-05 15:33:50 +01:00
Rebecca Law
19f964a90b Added a check that the call is not using a test api key.
Removed the tests for trial mode service for the scheduled tasks and the process job.
Having the validation in the POST notification and create job endpoint is enough.
Updated the test_service_whitelist test because the order of the array is not gaurenteed.
2017-09-04 17:24:41 +01:00
Ken Tsang
d391919677 Refactored to check trial when running scheduled job 2017-08-30 22:30:05 +01:00
Ken Tsang
41a71c703b Refactor test 2017-08-30 16:04:10 +01:00