Commit Graph

321 Commits

Author SHA1 Message Date
Katie Smith
41a9f5a06e Change format of the letter response file we expect
We were previously expecting the letter response files to be in the
format of 'NOTIFY.<datetime>.RSP.TXT' but the response files we receive
use '-' in the filenames instead of '.' which was causing an error when
we tried to get the date from the filename.
2018-03-14 09:25:51 +00:00
Katie Smith
79b5a735e2 Ensure update letter notification status always handles temporary failure
In the 'update-letter-notifications-statuses' task we want to ensure
that temporary failures are always handled, regardless of whether the
response file we receive contains unknown Sorted statuses or not.
2018-03-14 09:25:51 +00:00
Leo Hemsted
ea2b0dfbc9 set processing_started in before earlier jobs are processed
process_incomplete_jobs loops through jobs processing them in a single
task. This means that if the job statuses are all 'error', and then the
process_incomplete_jobs task fails, the later jobs in the list that
never got picked up won't have their status set back to in progress, or
their processing_started time - so will be stuck in 'error' forever.

Instead, we set the job statuses to in progress and the start time to
now before we process any - so if the incomplete_jobs task fails later,
the jobs will be picked up (again) by the check_job_statuses task in
half an hour's time
2018-03-09 17:20:26 +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
f902ba476c Bring in refactored CSV processing
Shouldn’t be any functional changes here, just things being named more
clearly.
2018-03-08 13:12:00 +00:00
Katie Smith
136d89e2f1 Persist daily sorted letter counts from response file
In the update_letter_notifications_statuses task we now check whether
each row in the response file that we receive from the DVLA has the
value of 'Sorted' or 'Unsorted' in the postcode validation field. We
then calculate the number of Sorted and Unsorted rows for each day and
save each day as a row in the daily_sorted_letter table.

The data in daily_sorted_letter table should be in local time, so we
convert the datetime before saving.
2018-03-06 09:09:02 +00:00
Rebecca Law
8aea452df9 Because research mode and test keys do not create notification history, a try except block has been added. 2018-03-02 11:37:15 +00:00
Rebecca Law
c474b2312b Process responses for letters even after the notification has been deleted.
This will continue to update the notification history for letter notifications.
We currently have an issue where the responses to letters from the provider is taking a long time.
This is due to the manual nature of their process.
Updating the status of the letter will still work if the notification has been purged.

Also turned back on the purge letter notification scheduled task.
2018-03-02 11:29:22 +00:00
Rebecca Law
d6c929d127 Another unused method to delete 2018-03-02 11:05:06 +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
Rebecca Law
385653af44 Added a new exception type for DVLAException.
The Notify team needs to investigate when a notification is marked as failed.
We will process the whole file and mark the notifications with the appropriate status, if any are failed an exception is raised.
The exception will trigger a cloud watch error for the team to investigate.
2018-02-22 15:05:37 +00:00
Rebecca Law
e736c90d00 Switch to using the pdf letter flow.
When sending letters always use the pdf letter flow regardless of service permissions.
2018-02-13 18:38:32 +00:00
Rebecca Law
8aa829e93a Merge pull request #1622 from alphagov/reduce-logging
Reducing the logging for the life cycle of a notification
2018-02-08 16:57:21 +00:00
Richard Chapman
d855b4e4ec Removed statsd from the api and use the statsd in the utils library.
The statsd code was added to the utils library a while ago, uses the
statsd from the util library and therefore consolidates the code into
once place.
2018-02-06 09:52:15 +00:00
Rebecca Law
dce79832ff As Notify matures we probably need less logging, especially to report happy path events.
This PR is a proposal to reduce the average messages we see for a single notification from about 7 messages to 2.

Messaging would change to something like this:
February 2nd 2018, 15:39:05.885	Full delivery response from Firetext for notification: 8eda51d5-cd82-4569-bfc9-d5570cdf2126
{'status': ['0'], 'reference': ['8eda51d5-cd82-4569-bfc9-d5570cdf2126'], 'time': ['2018-02-02 15:39:01'], 'code': ['000']}
February 2nd 2018, 15:39:05.885	Firetext callback return status of 0 for reference: 8eda51d5-cd82-4569-bfc9-d5570cdf2126
February 2nd 2018, 15:38:57.727	SMS 8eda51d5-cd82-4569-bfc9-d5570cdf2126 sent to provider firetext at 2018-02-02 15:38:56.716814
February 2nd 2018, 15:38:56.727	Starting sending SMS 8eda51d5-cd82-4569-bfc9-d5570cdf2126 to provider at 2018-02-02 15:38:56.408181
February 2nd 2018, 15:38:56.727	Firetext request for 8eda51d5-cd82-4569-bfc9-d5570cdf2126 finished in 0.30376038211397827
February 2nd 2018, 15:38:49.449	sms 8eda51d5-cd82-4569-bfc9-d5570cdf2126 created at 2018-02-02 15:38:48.439113
February 2nd 2018, 15:38:49.449	sms 8eda51d5-cd82-4569-bfc9-d5570cdf2126 sent to the priority-tasks queue for delivery

To somthing like this:
February 2nd 2018, 15:39:05.885	Firetext callback return status of 0 for reference: 8eda51d5-cd82-4569-bfc9-d5570cdf2126
February 2nd 2018, 15:38:49.449	sms 8eda51d5-cd82-4569-bfc9-d5570cdf2126 created at 2018-02-02 15:38:48.439113
2018-02-02 15:55:25 +00:00
Ken Tsang
377afc3ed4 Update letter processing for letter pdfs in research mode
- call create fake response file task if in research mode only on preview and development environments to not impact response files on staging and live
2018-01-26 15:04:56 +00:00
Katie Smith
84e25d6b98 Compare letter page count with billable units in DVLA response file
We compare the page_count in the response file we receive from the DVLA
with the billable_units of the letter. If these don't match, we log an
error.
2018-01-23 08:59:01 +00:00
Katie Smith
f1c75c5c5d Change notification status of failed letters
- Changed the notification status of letters for letters that DVLA marks
as 'failed' from NOTIFICATION_TECHNICAL_FAILURE to
NOTIFICATION_TEMPORARY_FAILURE.
2018-01-23 08:59:01 +00:00
Katie Smith
83711a9a0d Remove the delivery receipt callback for letters
This has been removed because the services only see one status.

Pivotal story: https://www.pivotaltracker.com/story/show/153674962
2018-01-03 16:41:10 +00:00
Alexey Bezhan
87b56567b2 Set job notifications reply_to_text from the template.reply_to
When creating notification objects from the job sets the reply_to_text
from template's reply_to if it's present. Otherwise uses the service
default.
2017-12-19 10:23:24 +00:00
venusbb
cef8d6e294 use callback queue 2017-12-13 11:55:08 +00:00
Ken Tsang
3e71e9a294 Update save_letter to handle research mode 2017-12-12 12:07:55 +00:00
Ken Tsang
3464336aff Refactored tasks.py to split out letters_pdf tasks
- Added has_permission helper in models.py to check permission in service
- Moved letters pdf tasks to separate file
- Moved letters pdf tests to own file
2017-12-12 12:07:55 +00:00
Ken Tsang
9784ee438a Refactored code in tasks.py 2017-12-12 12:07:55 +00:00
Ken Tsang
16136317f9 Add letters pdf task 2017-12-12 12:07:55 +00:00
Ken Tsang
68659bab1b Fixed processing of incomplete letter jobs
- `template` argument passed in to `job_complete` should be `template.template_type` otherwise the job status is incorrectly set
2017-12-07 12:03:16 +00:00
venusbb
5482ee4fe7 - wrap apply_async parameter notification_id in a str() argument
- check if service_callback_api exist before putting tasks on queue
- create_service_callback_api in tests before asserting if send_delivery_status_to_service has been called.
2017-12-04 17:58:38 +00:00
venusbb
f5a0ca9184 Added delivery status to services for letter callbacks 2017-12-01 21:59:46 +00:00
venusbb
489f43a2c9 rename callback_tasks.py to process_ses_receipts.py
create service_callback_tasks.py for tasks to send delivery statuses to services
2017-12-01 16:15:21 +00:00
venusbb
988b22391b added send_delivery_status_to_service task worker 2017-12-01 14:06:13 +00:00
venusbb
23a40b9fd0 create method _post_status_update for the actual sending of callbacks 2017-12-01 09:54:18 +00:00
Rebecca Law
0d86738696 Merge branch 'master' into use-reply-to-in-send-to-provider 2017-11-28 13:20:26 +00:00
Rebecca Law
a7232381bf Merge pull request #1433 from alphagov/add-reply-to-notifications
Populate reply-to-text field in notifications
2017-11-28 13:19:36 +00:00
Rebecca Law
03c3ebbbe7 Update send_to_providers and create_dvla_file_contents_for_notifications to use notification.reply_to_text.
The next thing to do is to stop updating the notification to sender mapping tables.
2017-11-27 15:24:16 +00:00
Leo Hemsted
1e4a480298 only catch s3 and db errors in build-dvla-file-for-job
this reduces the amount of error messages we log (we'll no longer log
at error level when build-dvla-file-for-job retries while waiting for
the task to finish), and make sure we retry in those cases above - db
or s3 having temporary troubl
2017-11-27 15:11:58 +00:00
Leo Hemsted
b6ac7f074d celery.task.retry exc param should be a throwable.
This causes an issue when it hits the max retry limit, and tries to
throw your exception to let you deal with it - at this point it was
moaning because we pass in a string

if it's not defined, and we're inside an exception block celery uses
that instead.
2017-11-27 14:55:29 +00:00
Rebecca Law
12024e9619 Update save_letter task to save the default letter contact block when creating the notification. 2017-11-27 11:33:04 +00:00
Rebecca Law
5450af661e Merge branch 'master' into add-reply-to-notifications 2017-11-27 10:40:02 +00:00
Rebecca Law
049daa0cb8 Save reply_to_text for one off notiications and csv notificaitons. 2017-11-25 11:31:36 +00:00
Leo Hemsted
f3d129b0d8 fix 500s when inbound msgs sent from alphanumerics rather than normal phone numbers 2017-11-23 15:22:18 +00:00
Leo Hemsted
d2154451e5 update research mode email callbacks to add process-ses-response task to queue
this involved:
* moving that task to callback_tasks to prevent circular imports
* updating the dummy research mode callbacks (with actual SNS messages from the
  ses simulator emails)
* refactoring tests
2017-11-17 13:41:45 +00:00
Rebecca Law
d905099962 If the post to a url for the inbound sms message to the service throwns an unknown exception - or RequestException, the base exception for request, the error will be logged and retried. 2017-11-15 11:43:52 +00:00
Leo Hemsted
aef99a8cba always log when we send out inbound sms
also, downgrade client returning bad status codes from `exception` to
error - it's not a problem with our system so we don't want it to trip
any cloudwatch alerts or anything.
2017-11-02 11:25:11 +00:00
Rebecca Law
f01c088f2f Update utils with a fix for address formats for letters. 2017-10-31 15:03:12 +00:00
Richard Chapman
d85a71758c Retry in only certain scenarios
Instead of retrying if there are genuine errors, only retry if there are
errors which are unexpected as otherwise the retries will happen and
fail for the same reason e.g. that the message has changed format and
will require a code update.

- Updated process_ses_results to only retry if there in an unknown
exception
- Update test and assert that there is a retry there is a unknown
exception
2017-10-30 13:43:23 +00:00
Rebecca Law
76c8b15f59 Update the billable units with the page count from the response file for letter notifications. 2017-10-27 13:53:55 +01:00
Richard Chapman
d6cff97b7b Review Changes
- Updated the retry and max_retries of the process_ses_results celery
task to be the same as other retry strategies in that file
- Provided a message with the 200 to be similar to how other responses
are handled
2017-10-26 12:23:19 +01:00
Richard Chapman
c2f2d39d22 Retry process_ses_results if it fails
If the SES task fails retry every 5 mins for an hour.

- Updated the process_ses_results task to retry
- Added tests to check for retry
2017-10-26 12:23:19 +01:00