Commit Graph

69 Commits

Author SHA1 Message Date
Richard Chapman
5f25d3162a Disable Redis for Staging added statsd for post methods
- Disable Redis as there is a current connection limit of 256 which
 could slow down the request if they are all used
 - Added statd to methods in the post to help spot any bottlenecks
2017-12-01 15:41:53 +00:00
Rebecca Law
8aa94af5d7 Stop populating the notification to sender mapping table when creating a notificaiton. 2017-11-29 16:47:23 +00:00
Rebecca Law
df2d3a95ae [WIP] 2017-11-23 14:55:49 +00:00
Rebecca Law
4eec11b633 Added an optional parameter in the form for POST /v2/notifications/sms and /service/<service_id>/send-notification to pass in the SMS sender id.
The send_sms_to_provider still needs to use the SMS sender being passed in to the POST.

As part of https://www.pivotaltracker.com/story/show/152106587
2017-10-30 13:36:49 +00:00
Chris Hill-Scott
5b3e77ba87 Make missing personalisation error consistent
In other places the text we use for this error message is "Missing personalisation: name, date, thing". See:
- 72b108b694/app/template/rest.py (L125)
- 717c0510a3/app/notifications/rest.py (L206)
- 05a179c6ef/app/v2/template/post_template.py (L38)

For some reason this part of the codebase says "Template missing personalisation: …". This is inconsistent, and also confusing because it’s the API call that’s missing the personalisation, not the template itself. 

This commit changes the error message to be consistent with the majority of the codebase, which uses the less confusing wording.
2017-10-23 14:41:49 +01:00
Richard Chapman
d2168b7985 Added the mapping between notification and reply to email to the database and persisted the mapping when the request is received by the end point. the end point also checks if the reply to email id exists and if not returns an error. Also added tests to test the functionality. 2017-10-05 16:50:17 +01:00
Leo Hemsted
f3db920c71 remove jobs from letter api calls
we now no longer create a job. At the end of the post there is no
action, as we don't have any tasks to queue immediately - if it's a
real notification it'll get picked up in the evening scheduled task.

If it's a test notification, we create it with an initial status of
sending so that we can be sure it'll never get picked up - and then we
trigger the update-letter-notifications-to-sent-to-dvla task to sent
the sent-at/by.
2017-09-26 09:57:36 +01:00
Leo Hemsted
2746bf0318 process letters from api traffic
there are three steps to this

1. Create a job
  * Starts in status 'ready to send'
  * Created by None, since it's from the API
  * original file name 'letter submitted via api'
2. Create a single notification for that job
  * job_row_number 0
  * client reference if provided
  * address line 1 as recipient
3. Trigger the build_dvla_file task
  we know that all the notifications have been created for this job
  (since we just created them ourselves synchronously), so this will
  just create the dvla-format file for the job, and upload it to s3.
2017-07-27 11:12:09 +01:00
Leo Hemsted
0ce9b94c36 Merge pull request #1075 from alphagov/letter-api-refactor
Letter api step 1 - refactor
2017-07-25 14:53:39 +01:00
Leo Hemsted
6059dcfe11 Merge pull request #1093 from alphagov/queue-split-part-2
[2/3] send to new queues
2017-07-24 15:11:37 +01:00
Leo Hemsted
614880f6d9 send to send-sms-tasks and send-email-tasks instead of send-tasks 2017-07-21 13:49:37 +01:00
Leo Hemsted
cfbf7ba2d1 Merge pull request #1092 from alphagov/old-queue-split
[1/3] add separate send-sms and send-email queues
2017-07-21 11:31:48 +01:00
Rebecca Law
d4bbca2592 Fix for simulated notifications.
When a post is made for a simulated number the id is empty in the notificaiton object that we return.
This fixes that.
2017-07-20 17:56:51 +01:00
Leo Hemsted
4d33040653 add separate send-sms and send-email queues
we're reading from those two queues as well as teh existing send queue,
however for now we don't send anything to them
2017-07-20 16:19:38 +01:00
Leo Hemsted
9caf45451e make persist_notification require kwargs
when functions get as big as that, it's confusing to try and work out what
things are what. By including a * as the first arg, we require that anyone
calling the function has to use kwargs to reference the parameters
2017-07-19 17:02:19 +01:00
Leo Hemsted
6c61a3fc2a Revert celery4
Revert the following three pull requests:
https://github.com/alphagov/notifications-api/pull/1085
https://github.com/alphagov/notifications-api/pull/1086
https://github.com/alphagov/notifications-api/pull/1088

celery 4.0.2 looked promising, however, on staging under mild load
(5/sec api calls) the performance was actually worse than 3.1.25
2017-07-19 15:17:19 +01:00
Martyn Inglis
786adb5d71 Move Queuenames in with the celery code, revamp config to allow move to celery 4.x 2017-07-12 12:01:52 +01:00
Leo Hemsted
350133e6db ensure created_by_id is being persisted correctly
(also make sure it's well tested 🎉 )
2017-06-23 15:56:47 +01:00
Leo Hemsted
ac7665bfc6 celery test cleanup
* Alter config so an error will be raised if you forget to mock out a
  celery call in one of your tests
* Remove an unneeded exception type that was masking errors
2017-06-20 12:06:49 +01:00
Leo Hemsted
a1e570dea7 persist created_by_id when using the one off notification endpoint 2017-06-20 12:06:49 +01:00
Martyn Inglis
75c5e5e5d5 Merge branch 'master' into redo-queue-visibitlity-timeout
Conflicts:
	app/notifications/process_notifications.py
	app/v2/notifications/post_notifications.py
2017-05-30 10:18:18 +01:00
Imdad Ahad
6c4377bd44 Persist normalised email 2017-05-26 10:26:07 +01:00
Imdad Ahad
cbc92a6173 Store the normalised number on the notification 2017-05-26 10:26:07 +01:00
Martyn Inglis
2591d3a1df This massive set of changes uses the new queue names object throughout the app and tests.
Lots of changes, all changing the line of code that puts things into queues, and the code that tests that.
2017-05-25 10:51:49 +01:00
Rebecca Law
751abb4b99 Update dateformat for scheduled_for to include minutes. 2017-05-22 14:15:35 +01:00
Rebecca Law
3a3161ecc4 Merge branch 'master' into schedule-api-notification
Conflicts:
	app/celery/scheduled_tasks.py
	app/v2/notifications/post_notifications.py
	tests/app/celery/test_scheduled_tasks.py
2017-05-22 14:05:57 +01:00
Rebecca Law
973cc2c4c9 Changed the scheduled_for datetime to only send and hour of a day to send.
Also expect the date being passed in is BST. The date is converted to UTC before saving. And converted to BST when returning a notification.
2017-05-17 15:06:15 +01:00
Martyn Inglis
ee5bb5f01a Fixed issues caused by single evaluation of method signature defaults 2017-05-17 13:27:05 +01:00
Martyn Inglis
09f45332eb Fixed issues caused by single evaluation of method signature defaults 2017-05-17 13:25:40 +01:00
Martyn Inglis
d2a7a7b3c9 Fixed error in code 2017-05-16 13:55:32 +01:00
Martyn Inglis
1dc3970595 Code tidy up as be @imdad comments. 2017-05-16 12:55:12 +01:00
Rebecca Law
f0e2713bef Add scheduled_for in the post notification request form.
Return scheduled for in get_notification requests.
2017-05-15 17:27:38 +01:00
Martyn Inglis
a340ed6f46 Changes to how we log to avoid unneeded DB calls. 2017-05-05 15:21:13 +01:00
Imdad Ahad
252c3235d7 Persist intl fields on notification 2017-04-27 13:24:36 +01:00
Martyn Inglis
2a0f8c8808 Validate International phone numbers
- uses new utils methods to validate phone numbers
- defaults to International=True on validation. This ensures the validator works on all numbers
- Then check if the user can send this message to the number internationally if needed.
2017-04-26 15:56:45 +01:00
Martyn Inglis
b0e5062df2 Added the random string reference to the letter
- uses the reference field on the notifications table to store a 16char random string used to cross reference DVLA letters back to the notification
- used as letter barcode does not have space for a UUID notification id

Depends on https://github.com/alphagov/notifications-utils/pull/149

Renamed the numeric_id to notification_reference in utils and changed validation rules to match this

Note also the persist_notification method set "reference" to be "client_reference" which is confusing and they are different things, so fixed this too.
2017-04-12 17:56:55 +01:00
Rebecca Law
3838fb583c The redis cache for daily limits and template usage was being updated for notifications with a test api key.
This PR corrects that.
2017-03-30 13:43:44 +01:00
Martyn Inglis
7dcd3164e2 Revert "Reinstating the 2 task model for API submitted notifications."
This reverts commit 1c154c4113.
2017-03-30 10:46:23 +01:00
Martyn Inglis
1c154c4113 Reinstating the 2 task model for API submitted notifications.
This is being done for the PaaS migration to allow us to keep traffic coming in whilst we migrate the database.

uses the same tasks as the CSV uploaded notifications. Simple changes to not persist the notification, and call into a different task.
2017-03-23 14:41:00 +00:00
Chris Hill-Scott
e507fed152 Quietly ignore extra personalisation
> If a user makes an API request with additional personalisation fields,
> we should simply discard any fields that the template doesn't have.
>
> This gives a couple of related advantages:
>
> - modifying template parameters no longer requires downtime for
>   clients - as they can pass in extra new parameters before a template
>   change, or continue passing in old unused parameters after removing
>   them from a template
>
> - services can pass in large user objects, for example, and then play
>   around with templates adding and removing fields at will
>
> we should make sure we still return an error if a user doesn't pass in
> a required parameter.

– https://www.pivotaltracker.com/story/show/140774195
2017-03-07 16:09:17 +00:00
Rebecca Law
74e29708f9 Fix bug where the increment calls set count to 1 if the cache does not exist. 2017-02-15 11:49:19 +00:00
Rebecca Law
53b7ad0961 Moved the cache key to the utils module.
Renamed the dao method.
2017-02-14 14:22:52 +00:00
Rebecca Law
458adefcb8 Added a redis cache for the template usage stats.
Cache expires every 10 minutes, but will help with the every 2 second query, especially when a job is running.
There is some clean up and qa to do for this yet
2017-02-13 18:47:29 +00:00
Rebecca Law
f66670c558 - Added logging to indicate that we created the notification and that we sent the notification to a delivery queue.
- Small updates as recommended by review comments.
2017-01-18 09:56:26 +00:00
Rebecca Law
a8cdabcecd - Refactor v2 post_notification to use a single method for sms and email.
- Added the `simulate` notification logic to version 2. We have 3 email addresses and phone numbers that are used
to simulate a successful post to /notifications. This was missed out of the version 2 endpoint.
- Added a test to template_dao to check for the default value of normal for new templates
- in v2 get_notifications, casted the path param to a uuid, if not uuid abort(404)
2017-01-17 12:08:24 +00:00
Martyn Inglis
0f37824b0c Ensure updates on a research mode service or test key don't touch the history table
- note this is an unexpectedly big change.
- When we create a service we pass the service id to the persist method. This means that we don't have the service available to check if in research mode.
- All calling methods (expecting the one where we use the notify service) have the service available. So rather than reload it I changed the method signature to pass the service, not the ID to persist.
- Touches a few places.

Note this means that the update or create methods will fall over on a null service. But this seems correct.

Goes back to the story which we need to play to make the service available as the API user so that the need to load and pass around services is minimised.
2016-12-19 16:45:18 +00:00
Rebecca Law
7a623de171 Added boby and subject to the get_notifications schema 2016-12-15 16:19:55 +00:00
Chris Hill-Scott
59af44d7ab Update utils to 12.0.0
Includes:

- [x] https://github.com/alphagov/notifications-utils/pull/94 (breaking
      changes which are responsible for all the changes to the API in
      this PR)

The test for `get_sms_fragment_count` has been removed because this
method is already tested in utils here:

ac20f7e99e/tests/test_base_template.py (L140-L159)
2016-12-13 10:57:01 +00:00
Jenny Duckett
d5d079a150 Add optional queue param to send_notification_to_queue
We want to use this function for sending internal notifications to a different
queue.
2016-12-09 16:46:49 +00:00
Chris Hill-Scott
d449475dd5 Incorporate breaking utils changes
The `.replaced…` methods on instances of `Template` were removed in
https://github.com/alphagov/notifications-utils/pull/84
2016-12-02 10:42:11 +00:00