Commit Graph

7051 Commits

Author SHA1 Message Date
Rebecca Law
db4b4d929d - If the task runs twice and the notification already exists ignore the primary key constraint.
- Remove prints
- Add some more tests
- Only allow the new method to run for emails
2020-03-25 12:39:15 +00:00
Rebecca Law
a13bcc6697 Reduce the pressure on the db for API post email requests.
Instead of saving the email notification to the db add it to a queue to save later.
This is an attempt to alleviate pressure on the db from the api requests.
This initial PR is to trial it see if we see improvement in the api performance an a reduction in queue pool errors. If we are happy with this we could remove the hard coding of the service id.

In a nutshell:
 - If POST /v2/notification/email is from our high volume service (hard coded for now) then create a notification to send to a queue to persist the notification to the db.
 - create a save_api_email task to persist the notification
 - return the notification
 - New worker app to process the save_api_email tasks.
2020-03-25 07:59:05 +00:00
Rebecca Law
544537791d Merge pull request #2768 from alphagov/optimise-delete-notifications-task
Refactor delete_notifications_older_than_retention_by_type
2020-03-24 15:04:48 +00:00
Rebecca Law
69102db4cb Remove the hourly loop and replace it with a while loop, which check if we still have things to delete for the day.
We are already limiting the query by a query limit.
2020-03-24 14:54:06 +00:00
Rebecca Law
3ca73a35ed Change as per code review
- fix test name
 - make query filter consistent with each other
 - add comment for clarity
 - add inner loop to continue to insert and delete notifications while the delete count is greater than 0
2020-03-24 14:17:47 +00:00
Rebecca Law
f04210ba7d Refactor delete_notifications_older_than_retention_by_type to use a new strategy.
The insert_notification_history_delete_notifications function uses a temp table to store the data to insert and delete. This will save extra queries while performing the insert and delete operations.
The function is written in such a way that if the task is stop while processing when it's started up again it will just pick up where it left off.

I've made a decision to delete all test data in one query, I don't anticipate a problem with that.

The performance of this might also be better than last nights test because we are inserting everything we need for the NotificationHistory insert, so we don't need the join to Notifications to perform the insert.
2020-03-24 12:21:28 +00:00
Rebecca Law
b243257906 Merge pull request #2767 from alphagov/optimise-delete-high-volume
Transaction to insert history and delete notifications.
2020-03-23 16:50:45 +00:00
Rebecca Law
80845e1abb Transaction to insert history and delete notifications.
Need to test the performance of this function, then we can call it from the task.
- Create a temporary table to insert ids of the desired rows, limit by 10K (might be too low).
- Insert into NotifcationHistory select from notification where id in temp table
- Delete from Notifications where id in temp table
- drop temp table

We should be able to iterate of this. The query stats for the query to create the temp table are very good, 17ms.
2020-03-23 16:33:06 +00:00
Rebecca Law
3a95fba9b0 Merge pull request #2766 from alphagov/delete-stmt-order-by-and-hour-separate
Delete stmt order by and hour separate
2020-03-20 19:25:00 +00:00
Leo Hemsted
8ea09be1ff order the insert/update by created_at
you should always order by when doing a limit/offset, to guarantee that
the second time you run that query, the order hasn't changed and you
aren't just repeating the task with an overlap of notifications.
Luckily, in this case we haven't lost any data, because:

* we have an on conflict do update statement so when we returned
  duplicate rows it would just do an update
* when we delete, we cross-reference with the notification history so if
  a row always got missed, we won't delete it.

This resulted in, for example, govuk email still having a handful of
notifications in the table from 9th despite the task running succesfully
every day until the 18th of march.

order by created_at ascending so that we start with oldest notifications
first, in case it's interrupted part way through.
2020-03-20 19:11:24 +00:00
Leo Hemsted
dc5b56ff78 Change sql to chunk by hour to remove old notifications
insert/update, and then delete notifications in hourly batches. This
means that if the task gets interrupted part-way through, we'll have at
least something to show for it. Previously we would insert and update
into the history table but might not delete from the notification table
properly.

Keeping the offsets and limits for confidence around reliability and
queries timing out.

Keeping the join to notification_history to ensure we don't delete
anything prematurely while our DB is in a bit of a weird state with lots
of these tasks failing over the last week.
2020-03-20 19:07:08 +00:00
David McDonald
3a61a84ca3 Merge pull request #2753 from alphagov/increase-pool-size
Increase the queue pool size to 30.
2020-03-19 15:51:15 +00:00
Katie Smith
3bf75fe9df Merge pull request #2757 from alphagov/sms-response-task
Add a task to handle SMS responses
2020-03-19 13:53:37 +00:00
Katie Smith
24b77726f4 Add a task to process sms callback from our providers
This runs on the new `sms-callbacks` queue. The function
`process_sms_client_response` has been replaced with a task called
`process_sms_client_response`. This involved some reorganisation of the
existing code and tests.
2020-03-19 13:41:14 +00:00
Katie Smith
3a07d1e13d Create new sms-callbacks queue
The `delivery-worker-receipts` app will listen to this new queue, which will
be used for processing the responses from Firetext and MMG.
2020-03-19 13:41:14 +00:00
Katie Smith
19bf68b567 Delete unused function 2020-03-19 13:41:14 +00:00
Pea M. Tyczynska
900664c172 Merge pull request #2748 from alphagov/format-postcode-for-csvs
Format postcode for CSV letter rows
2020-03-19 11:07:08 +00:00
Rebecca Law
67339d7fd9 Merge pull request #2760 from alphagov/add-try-catch
Add a try/except around the code to get the files.
2020-03-19 09:28:10 +00:00
Rebecca Law
7459a4f6f6 Add a try/except around the code to get the files.
The idea is to log the exception but keep going. That way the "good" files still get sent and we can investigate why a file failed.
2020-03-19 09:15:38 +00:00
Rebecca Law
4ebfce6b8d Merge pull request #2756 from alphagov/stop_checking-daily_limit
Remove the check for daily limits
2020-03-17 16:03:15 +00:00
Rebecca Law
852cf478f8 Remove the check for daily limits 2020-03-17 15:51:21 +00:00
Rebecca Law
ac07ea3e3f Merge pull request #2755 from alphagov/fix-serialization-error
Fix serialisation error
2020-03-17 10:44:47 +00:00
Chris Hill-Scott
90783c0f23 Merge pull request #2754 from alphagov/update-jobs-contact_list_id
Update jobs contact list
2020-03-17 10:23:49 +00:00
Chris Hill-Scott
6667c04cf2 Fix unused import 2020-03-17 10:07:47 +00:00
Rebecca Law
51f43563d3 Fix serialisation error when creating the create_letters_pdf in resend_created_notifications_older_than 2020-03-17 08:48:02 +00:00
Rebecca Law
95c2dabaca Add service_contact_list id to the JobSchema. 2020-03-17 08:20:01 +00:00
Rebecca Law
b30deaa989 Increase the queue pool size to 30.
This should add an extra 400 connections maximum, which will not tip us over the allowable 5000 db connections. And it may help with the queue pool connection errors.
2020-03-16 16:46:19 +00:00
Rebecca Law
8545b097f9 [WIP] 2020-03-16 16:45:34 +00:00
Rebecca Law
fa72eb651f Merge pull request #2750 from alphagov/get-single-contact-list
Endpoint to return a ServiceContactList for a given id.
2020-03-16 09:22:24 +00:00
Pea Tyczynska
bf1cab76a9 Bump utils 2020-03-13 17:35:47 +00:00
Pea Tyczynska
1fb040dc61 Format postcode for CSV letter rows
We are formatting the postcode here, because if we did it in template
preview, that could break flows like API and admin one-off, since
we are not validating postcode there yet, and format_postcode
needs a nice validated postcode.

We are not doing it in admin, as then we would have to either
rewrite the CSV file or pass data differently to API. First would
be nasty, second is a lot of overhead.

In the long run we might want to move postcode formatting to
template preview so that the postcode in letter preview looks the same
before and after user sends it, but now to get it out quickly it's better
to format the postcode here in the task.
2020-03-13 17:35:36 +00:00
Rebecca Law
3bf18d0ac3 Endpoint to return a ServiceContactList for a given id. 2020-03-13 17:21:59 +00:00
Rebecca Law
069bc1cdb6 Merge pull request #2749 from alphagov/emergency-contact-list-tbl
New table and endpoints for service contact lists
2020-03-13 12:21:32 +00:00
Rebecca Law
654e6fc657 New table and endpoints for service contact lists.
- Table to store meta data for the emergency contact list for a service.
- Endpoint for fetching contact lists for service
- Endpoint for saving contact list for service.

The list will be stored in S3. The service will then be able to send emergency announcements to staff.
2020-03-13 12:11:16 +00:00
Chris Hill-Scott
7636c4225d Merge pull request #2727 from alphagov/ship-uploads
Give existing services upload letters permission
2020-03-11 16:22:15 +00:00
Chris Hill-Scott
e12829e56e Give existing services upload letters permission
This gives the feature to all existing users.
2020-03-11 15:31:53 +00:00
David McDonald
f9751d6ebd Merge pull request #2746 from alphagov/fix-non-content-outside-errors
Undo bug for previewing precompiled letters
2020-03-11 15:29:10 +00:00
Chris Hill-Scott
87428685fb Merge pull request #2740 from alphagov/invited-by-notify
Let the Notify team invite people to an organisation
2020-03-11 14:52:05 +00:00
Chris Hill-Scott
4374ed6220 Merge pull request #2744 from alphagov/find_jobs_within_retention
Find only uploads within service data retention period
2020-03-11 14:51:56 +00:00
David McDonald
483c00b3a2 Undo bug for previewing precompiled letters
https://github.com/alphagov/notifications-api/pull/2742/files#diff-d9a6761afaff4a491e60b64f6063654fL265
introduced a change in behaviour which causes template preview to 500
for a precompiled letter that is invalid but not because the content is
outside the printable area.

The changes it back to the previous behaviour, where we b64encode and
utf-8 decode for a page that is invalid for reasons that are not content
outside the printable area, for example a non portrait a4 letter.

I didn't end up writing a unit test for this because I really can't
figure out the existing behaviour we expect for this use case. This
method is too big and complex but I'm confident by looking at the change
in the commit mentioned above that this puts behaviour back to how it
was. Manual testing also confirms the fix.

I've also taken this opportunity to improve two test names whilst I was
looking at things.
2020-03-11 14:34:12 +00:00
Pea Tyczynska
8b60e69157 Finding only jobs and letters within data retention works and tested 2020-03-10 15:53:56 +00:00
Rebecca Law
5902960516 Merge pull request #2741 from alphagov/make-sms-char-count-consistent
Update validators to use is_message_too_long()
2020-03-10 14:59:28 +00:00
David McDonald
0ba0bdca15 Merge pull request #2742 from alphagov/overlay-sometimes
Only add overlay for pages which are invalid for precompiled letters uploaded via the API
2020-03-10 13:54:22 +00:00
David McDonald
34d571405e Refactor of logic to make code more readable
Functionality remains as it was
2020-03-10 13:38:20 +00:00
Katie Smith
d0cb5db19b Merge pull request #2743 from alphagov/international-letters-permission
Add international_letters service permission
2020-03-10 10:12:54 +00:00
Rebecca Law
a994e8fb6e Update validators to use is_message_too_long()
- update check_sms_content_char_count to use the SMSTemplate.is_message_too_long function, and updated the error message to align with the message returned by the admin app.
- Update the the code used by version 1 of the api to use the validate_template method.
  - I did find a couple of services still using the old api, however, this change should not affect them as I checked the messages being sent and they are not too long.
  - We will be sending a message to them to see if they can upgrade.
- Update the log message for authenication to include the URL - makes it easier to track if a service is using version 1 of the api.
2020-03-10 09:38:16 +00:00
Katie Smith
a9abc63297 Add international_letters service permission 2020-03-09 15:42:07 +00:00
David McDonald
08ec06295a Merge pull request #2738 from alphagov/pyup-scheduled-update-2020-03-04
Scheduled weekly dependency update for week 09
2020-03-09 15:41:29 +00:00
David McDonald
a8f2aa2022 run make freeze-requirements 2020-03-09 15:29:26 +00:00
pyup-bot
6d22c8fe14 Update marshmallow-sqlalchemy from 0.22.2 to 0.22.3 2020-03-09 15:29:26 +00:00