Commit Graph

311 Commits

Author SHA1 Message Date
Rebecca Law
c8368d908b Update process_returned_letters task to insert or update the returned_letter table. 2019-12-09 16:23:09 +00:00
Rebecca Law
918975b0a6 Use sender_id from CSV metadata.
When we upload a CSV for a job, we add the sender_id as metadata to the file that is uploaded on S3.
There is more than one place where we process rows from that CSV.
 - process_job
 - scheduled_job
 - check_for_missing_rows_in_completed_jobs
 - check_job_status

All of these places need to use the sender_id, now the sender_id is always read from the file metadata.
In a subsequent PR we can remove the optional sender_id parameter from process_job task.
2019-11-15 15:42:29 +00:00
Rebecca Law
c23ae15f32 Remove insert to NotificationHistory
Fix all test failures
2019-05-31 16:52:22 +01:00
Rebecca Law
43334d63f3 Stop updating NotificationHistory
Doing my bit to remove imports of fixtures.
2019-05-15 10:58:39 +01:00
Pea Tyczynska
eec5f5490d Don't require precompiled_letter service permission
Everyone can send precompiled letters now yay
2019-05-13 13:04:29 +01:00
Pea Tyczynska
5b9e6c2086 Set postage on basis of postage argument or template postage 2019-02-06 13:23:09 +00:00
Leo Hemsted
d3d56a3224 separate nightly tasks and other scheduled tasks.
other tasks is anything that is run on a different frequency than
nightly
2019-01-18 15:36:53 +00:00
Katie Smith
d20e35d075 Get and use sender_id from S3 metadata
The `save_email` and `save_sms` jobs were updated previously to take an
optional `sender_id` and to use this if it was available. This commit
now gets the `sender_id` from the S3 metadata if it exists and passes it
through the the tasks which save the job notifications. This means SMS
and emails sent through jobs can use a specified `sender_id` instead of
the default.
2018-11-12 10:59:48 +00:00
Katie Smith
30fe41fd43 Pass sender_id argument to tasks
Started passing `sender_id` to the `save_email`, `save_sms` and
`process_job` tasks, with a default value of `None`.

If `sender_id` is provided, the `save_email` and `save_sms` tasks will
use it to determine the reply-to email address or the SMS sender for the
notifications in the job. The `process_job` task will start using the
value in another commit.
2018-11-12 10:49:39 +00:00
Katie Smith
4b23075488 Delete unused parameters from the save_email and save_sms jobs
These both had default arguments of `api_key_id` and `key_type` which
were never being passed in, so these have been removed.
2018-11-12 10:49:39 +00:00
Leo Hemsted
4dc3f829e3 give letter notifications the postage from their service 2018-09-19 17:23:17 +01:00
Alexey Bezhan
c9ca720959 Change NotificationHistory.updated_at on update
Sets the updated_at to current time when the NotificationHistory
is modified (which happens occasionally for example to set status
to returned letter).
2018-09-13 14:09:09 +01:00
Alexey Bezhan
3787e2954b Add a task to process returned letter lists
Adds an API endpoint `/letters/returned` that accepts a list of
notification references and creates a task to update their status.

Adds a new task that uses the list of references to update the status
of notifications to 'returned-letter'.

The update is currently done using a single query and logs the
number of changed records (including notification history records).
This could potentially be done within the `/letters/returned` endpoint,
but creating a job right away allows us to extend this more easily
in the future (e.g. logging missing notifications or adding callbacks).

The job is using the database tasks queue.
2018-09-06 16:39:17 +01: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
Chris Hill-Scott
7ef6af2d14 Remove anything to do with DVLA format letters 2018-03-02 14:13:12 +00:00
Rebecca Law
304f4d5c67 Remove unused methods 2018-03-02 11:05:05 +00:00
Richard Chapman
42c1040604 Updated API to get it working with Admin.
* Added missing items from template which are required
* Returned the file as a JSON string with the file as a base64 encoded
string
* Updated tests to match teh desired format
2018-03-01 15:01:46 +00:00
Ken Tsang
b6401e4858 Fix boto mocks in tests
- was getting KeyError: 'Error' test failures due to the side_effect not generating enough information to be used in the ClientError class, this PR adds missing information.
2018-02-28 10:54:52 +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
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
Rebecca Law
cc839562da Fix the template history when updating the reply_to for a template.
It seems selecting the service_letter_contact in the validation method was causing SQLAlchemy to persist the object. When the dao was called to save the object nothing was different so we didn't persist the history object.

It may be time to take another look at how we version. :(
2018-01-09 16:41:58 +00:00
Rebecca Law
a052020f84 - simplify if statement
- use the template.get_reply_to_text() in send_notification, it's already using the right thing.
2018-01-08 16:54:19 +00:00
Rebecca Law
d6683d9630 If template has a default address use that address ELSE the address is blank. 2018-01-08 15:54:58 +00:00
Alexey Bezhan
545ff7dda6 Normalize outbound SMS number for job notifications
Replaces 0 with 44 in UK SMS sender number to make it possible to
respond to the SMS from an international number.
2018-01-03 10:32:34 +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
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
aca52952d8 Add tests for letters as pdf permission
- test that `create_letters_pdf` only gets called when `letters_as_pdf` permission set
- test that `build_dvla_file` does not get called when `letters_as_pdf` permission set
- test creating the pdf call to notifications template preview service
- test uploading the data to s3 calls upload_letters_pdf function
2017-12-12 12:07:55 +00:00
Ken Tsang
bad129c5e9 Add extra logging for upload_letters_pdf 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
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
Leo Hemsted
4e741bab90 Merge pull request #1441 from alphagov/flake8-tests
Flake8 tests
2017-11-29 16:54:29 +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
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
b0d88ec08c Updates as per review comments 2017-11-28 11:05:56 +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
049daa0cb8 Save reply_to_text for one off notiications and csv notificaitons. 2017-11-25 11:31:36 +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
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
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