Commit Graph

6765 Commits

Author SHA1 Message Date
Leo Hemsted
860670f221 Merge pull request #2664 from alphagov/welsh-characters
update utils to bring in full welsh diacritics range
2019-11-29 10:53:45 +00:00
Leo Hemsted
b2e3a9d80f Merge pull request #2665 from alphagov/log-line-fix
fix log line for provider switch
2019-11-28 17:30:24 +00:00
Leo Hemsted
78edc3a8b3 fix log line for provider switch 2019-11-28 17:20:12 +00:00
Leo Hemsted
6b9afa358f update utils to bring in full welsh diacritics range
note: this includes updating the MMG api url to their v2a api. Their
previous API doesn't include support for capital o with grave accent
(Ò)
2019-11-28 15:12:52 +00:00
Leo Hemsted
b6320182be Merge pull request #2660 from alphagov/distribute-sms-between-providers
Distribute sms between providers
2019-11-28 13:44:57 +00:00
Leo Hemsted
f7fbd6de5b make 500s change priorities quicker
it's not acceptable for a constantly failing provider to take 50 minutes
to drain (5x reducing priority by 10). But similarly, we need _some_
delay, or a handful of concurrent failures will completely turn off a
provider, rendering the whole excercise kinda pointless. Setting the
delay before it tries to reduce priority again to one minute is nice
because it means that if one request times out and returns 502, then any
other requests that are in flight at that time will time out before the
one minute is up and not switch, but any requests made after the switch
that take sixty seconds to time out will affect it.
2019-11-28 13:29:39 +00:00
Leo Hemsted
2d7bf664f5 set updated_at manually to avoid ORM overwriting my changes
when ORM level changes are made (eg `my_model.my_column = my_value`),
the ORM will read the column definition to see if it should apply any
defaults.The updated_at columns that we use all define
`onupdate=datetime.datetime.utcnow`. We can't patch this out as the
function pointer to the original function has already been grabbed by
this at import time - so freezegun or `mocker.patch` won't work.

So we have to use the query syntax to set the `updated_at` timestamp in
the DB without going through the ORM layer.
2019-11-28 13:29:39 +00:00
Leo Hemsted
cfe82f8f4a make 500 error provider switches also check for recent changes
moving the logic and the test from switch provider on slow delivery to
dao reduce sms provider priority
2019-11-28 13:29:39 +00:00
Leo Hemsted
2a392e7137 update switch provider scheduled task
it now looks at both providers and works out whether to deprioritise
one, rather than binary switching from one to the other. If anything
has altered the priorities in the last ten minutes it won't take any
action. If both providers are slow it also won't take any action.
2019-11-28 13:29:38 +00:00
Leo Hemsted
3d87096353 add tests for send to providers 2019-11-28 13:29:02 +00:00
Leo Hemsted
992e211a8d update history and created_by when adjusting provider priorities
making sure that we don't close the transaction early, because we need
to keep the transaction open as it has the with_for_update clause on the
select to lock the table.

also make sure the tests clean up after themselves as they're adding
history rows etc
2019-11-28 13:29:02 +00:00
Leo Hemsted
4a6a228cc2 clear up where we use restore_provider_details
it now only needs to be used when you're:
* updating providers in ways that will create history (eg through
  regular api calls)
* altering more than just priority in test setup (eg setting inactive,
  deleting, or adding a provider)
2019-11-28 13:29:02 +00:00
Leo Hemsted
3c63ccb159 move from dao_toggle_sms_provider to dao_reduce_sms_provider_priority 2019-11-28 13:29:02 +00:00
Leo Hemsted
52a33f220b make tests use mmg 100% of the time by default
we randomly choose between sms providers now - this means that tests may
sometimes send firetext and sometimes mmg, so we'd need to patch out
different HTTP calls, expect different values in sent_by, etc etc.

To ensure tests are consistent, add a new fixture that is always used by
notify_db_session, which sets the priorities of the sms providers to
100% mmg 0% firetext. if you need to test other values, then you should
set the values manually in the test file
2019-11-28 13:29:02 +00:00
Leo Hemsted
e29546cb65 flake8 2019-11-28 13:29:02 +00:00
Leo Hemsted
28da190a1c remove get_current_provider
the function no longer makes sense now that we send through both at
the same time. mostly just used in old tests that we'll end up rewriting
shortly anyway
2019-11-28 13:29:02 +00:00
Leo Hemsted
8524bdb4bf clean up provider details rest test
we don't actually care what order the providers are returned in, so
no point making a flaky test that asserts the order. This is just seen
by platform admin and we do processing of the list on the admin side
anyway.
2019-11-28 13:29:02 +00:00
Leo Hemsted
8fa7cde593 remove unused provider dao functions 2019-11-28 13:29:01 +00:00
Leo Hemsted
fa7e0a1e84 add dao_reduce_sms_provider_priority function
retrive the sms providers from the DB, and decrease the chosen
provider's priority by 10, while increasing the other by 10.

add a check in to ensure we never decrease below 0 or increase above 100
- this is per provider, we don't check that the two add up to 100 or
  anything. If the values are outside of this range (eg: set via the UI)
then they'll probably* fix themselves at some point - we've added tests
to document these cases.

Use with_for_update to ensure that the method can only run once at a
time - other invocations of the function will be held on that line until
the currently running one ends and commits the transaction. This doesn't
affect anyone doing things from the UI.
2019-11-28 13:29:01 +00:00
Leo Hemsted
6f38cbbcf1 randomly choose from providers based on priority
todo: make sure if they don't add up to 100 we do something sensible,
especially if they're both 0.
2019-11-28 13:29:01 +00:00
Rebecca Law
4fd6f33af2 Merge pull request #2658 from alphagov/fix-letters-in-created-status
Alert if a letter doesn't make it past created status
2019-11-27 13:38:51 +00:00
Rebecca Law
853df6fbfb Fix reference to old time frame for task. 2019-11-27 13:26:53 +00:00
Pea M. Tyczynska
4f2a8352f2 Merge pull request #2657 from alphagov/validate-against-empty-messages
Validate against messages with no content
2019-11-26 11:41:02 +00:00
Pea Tyczynska
c17100af37 Bump utils version and improve error message content 2019-11-26 11:19:01 +00:00
Pea Tyczynska
f4ba82225b Use new Template method .is_message_empty()
This method has been now added to Template subclasses
used by sms, emails and letters, so we can use it to valdiate if
message is not empty.

Use new template method .is_message_empty()

Refactor function name and add a test
2019-11-26 11:18:00 +00:00
Pea Tyczynska
9c804f701b Validate against messages with no content 2019-11-26 11:17:59 +00:00
Tom Byers
28ae7705c2 Merge pull request #2663 from alphagov/update-readme-about-python-3.6
Update README about python to use
2019-11-22 14:35:17 +00:00
Tom Byers
62b606af17 Update README about python to use
We now run python 3.6 in production and there are issues with marshmallow-sqlalchemy using 3.5.
2019-11-22 14:15:34 +00:00
Rebecca Law
d8c4733a5a Merge pull request #2654 from alphagov/validate-content-header-for-post-requests
Add validation for missing content-type header
2019-11-22 11:31:56 +00:00
Rebecca Law
6b09075779 Fix poorly written sentence 2019-11-22 11:02:22 +00:00
Rebecca Law
e0b4b258aa Shortened the length of time to check for messages with the wrong state.
There is a chance that the there is an outstanding retry task that has yet to run but the task that are replayed here protect against the task running twice. So this just means it might get sent sooner than later.
2019-11-21 15:51:27 +00:00
Rebecca Law
5d6886242b Check that the request payload data is valid json.
By adding `force=True` to request.get_json() the mime type is ignore. If the data is not valid json the method will return a `BadRequestError` we catch that and throw our own error with a clear error message "Invalid JSON supplied in POST data".
If the json is valid return the json data or an empty dict if None is passed in.

This PR improves the error messages if the json is invalid, previously, the error message was "None object type" message which is not very helpful.
2019-11-21 15:23:11 +00:00
Leo Hemsted
c78a5d8536 Merge pull request #2662 from alphagov/utils-bump
Utils bump
2019-11-21 15:23:11 +00:00
Rebecca Law
ac4f0e8027 After a comment from @idavidmcdonald, I asked myself why are not creating the task to upload the pdf and update the notification.
The assumption was that S3 would throw an exception if the object was uploaded twice. That's not the case the default behaviour is that if a file already exists it will be overwritten. So it is completely safe to run the task from the alert.

It can also mean that we don't need to wait 4hours 15 minutes. Shall I decease the amount of time before restarting the task?
2019-11-19 16:04:21 +00:00
Leo Hemsted
6e21c56327 Merge pull request #2662 from alphagov/utils-bump
Utils bump
2019-11-19 10:55:07 +00:00
Leo Hemsted
8f7f99234b use Template.is_message_too_long rather than content_count directly
this function returns false for emails and letters so we can clean up
the code and reduce duplication a little bit
2019-11-18 17:00:32 +00:00
Leo Hemsted
5e9a21f5d0 bump requirements 2019-11-18 15:48:38 +00:00
Rebecca Law
cd03f905c0 Merge pull request #2659 from alphagov/get-sender-id-from-metadata
Get sender id from metadata
2019-11-18 10:57:59 +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
6155f7666e Testing with latest 2019-11-15 15:42:24 +00:00
Rebecca Law
516190262a [WIP] 2019-11-15 15:41:27 +00:00
Rebecca Law
d25fcc8748 Merge pull request #2661 from alphagov/fix-billing-query
Fix query to populate ft_billing table.
2019-11-15 10:58:48 +00:00
Rebecca Law
db0d45966f Fix query to populate ft_billing table.
The group by for the query was wrong which would result in 2 rows with different totals but the same unique key, so the second row would update the first row. Meaning we had incorrect numbers for the billing data.
Because some of the data had null for the sent_by column, the select would turn the Null --> dvla, but that same function was not used in the group by. So any time we had missing sent_by data we would end up with 2 rows where one would overwrite the other.
2019-11-15 10:23:48 +00:00
Rebecca Law
c42420c329 Add an alert when a letter is created but doesn't have a file in S3 for sending. We can tell this is the case because there is no updated_at and billable units are still 0.
At this point we are just creating a zendesk ticket - perhaps we can just call the create_letter_pdf task.
2019-11-13 16:39:59 +00:00
Rebecca Law
0979b41562 Merge pull request #2656 from alphagov/exclude-old-jobs-from-check
Added a filter to restrict jobs older than a day from coming back.
2019-11-08 11:56:26 +00:00
Rebecca Law
8d042c36f4 Added a filter to restrict jobs older than a day from coming back.
This is only necessary because there is currently a job that is old, but had 1 row created a couple days later. So now there is 1 notifications for the job where the rest have been purged.
2019-11-08 10:37:37 +00:00
Rebecca Law
8276ecaa24 Merge pull request #2655 from alphagov/fix-error-message
Add the missing format for the log message
2019-11-07 15:27:37 +00:00
Rebecca Law
5aaf5cd588 Add the missing format for the log message when a missing row is processed. 2019-11-07 15:01:23 +00:00
Rebecca Law
5a11e10cbf Merge pull request #2653 from alphagov/check-for-missing-rows
Check for missing rows
2019-11-07 13:52:15 +00:00
Rebecca Law
559faf3034 Fix the query.
Missing the where clause to join the two tables.... OOPS
2019-11-07 10:57:31 +00:00