Commit Graph

212 Commits

Author SHA1 Message Date
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
9ee26e0b67 Revert "update notification rest tests"
This reverts commit 11919d9810.
2017-03-30 10:38:51 +01:00
Martyn Inglis
385a73da2b Revert "ensure we're passing through api keys and key types from notifications"
This reverts commit 25d1777937.
2017-03-30 10:38:41 +01:00
Leo Hemsted
11919d9810 update notification rest tests 2017-03-28 13:51:42 +01:00
Leo Hemsted
25d1777937 ensure we're passing through api keys and key types from notifications
when we made the change to async persist notifications, we forgot to
pass through api_key_id and key_type. in send_sms/email, for legacy
reasons, they default to None/KEY_TYPE_NORMAL, so regardless of what
your api key was set up as, we would send real messages!

TODO: Once the PaaS transition is complete and the task changes are
reverted, remove the api_key_id and key_type params from the send_*
tasks entirely, as those are only called from the csv job flow, and
don't need them
2017-03-28 13:14:46 +01:00
minglis
d7adfcaf87 Merge pull request #866 from alphagov/no-downtime-hosting-migration
Reinstating the 2 task model for API submitted notifications.
2017-03-27 13:54:43 +01:00
Rebecca Law
37a5ce601a Update the version of notifications-utils.
There was a problem with the address block for the DVLATemplate.

Added a countdown to the build_dvla_file.
2017-03-24 15:25:02 +00: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
Rebecca Law
8225a57d50 reformat execption 2017-03-17 16:57:00 +00:00
Rebecca Law
d831447329 re-raise execption 2017-03-17 16:33:51 +00:00
Rebecca Law
a0ec8af7c9 Added logging for any exception thrown in build_dvla_file 2017-03-17 16:25:27 +00:00
Rebecca Law
f01760f6e6 Update statsd decorator so that it will log on error.
Added logging for the build_dvla_file task
2017-03-17 12:38:24 +00:00
Rebecca Law
4e48676607 Remove comment 2017-03-15 17:08:27 +00:00
Rebecca Law
13d1016982 Forgot to make the id unique 2017-03-15 17:07:52 +00:00
Rebecca Law
6e7482aaac Increase max_retries for the task. 2017-03-15 15:42:52 +00:00
Rebecca Law
140179b4b6 Create new task to build dvla file.
This will transform each notification in a job to a row in a file.
The file is then uploaded to S3.
The files will later be aggregated by the notifications-ftp app to send to dvla.

The method to upload the file to S3 should be pulled into notifications-utils package.
It is the same method used in notifications-admin.
2017-03-15 15:26:58 +00:00
Rebecca Law
f56824adde Cancel job if the service is inactive.
Update the PermissionsDao.get_permissions_by_user_id to only return permissions for active services,
this will make the admin app return a 403 if someone (otherthan platform admin) tries to look at an inactive service.
Removed the active flag in sample_service the dao_create_service overiddes this attribute.
2017-02-02 11:34:00 +00:00
Leo Hemsted
70cd3fb335 ensure that the celery workers know about the new db-letter queue
this fixes running locally and on paas, a separate PR is in
notifications-aws to fix work on aws
2017-01-24 12:32:20 +00:00
Leo Hemsted
4f238d241a persist_letter saves address correctly to database
the `to` field stores either the phone number or the email address
of the recipient - it's a bit more complicated for letters, since
there are address lines 1 through 6, and a postcode. In utils, they're
stored alongside the personalisation, and we have to ensure that when
we persist to the database we keep as much parity with utils to make
our work easier. Aside from sending, the `to` field is also used to
show recipients on the front end report pages - we've decided that the
best thing to store here is address_line_1 - which is probably going to
be either a person's name, company name, or PO box number

Also, a lot of tests and test cleanup - I added create_template and
create_notification functions in db.py, so if you're creating new
fixtures you can use these functions, and you won't need to pass
notify_db and notify_db_session around, huzzah!

also removed create param from sample_notification since it's not used
anywhere
2017-01-24 12:32:20 +00:00
Leo Hemsted
c904025ee9 add comprehensive tests for process_row
in the future we can probably remove some of the slower databasey
process_job tests, but that's out of scope for this
2017-01-24 12:22:31 +00:00
Leo Hemsted
542f08d0b5 refactor exception handling code in job tasks code
it's almost entirely duplicated so share it across.

also clean up retrying - `task.retry(...)` raises a
celery.exceptions.Retry object, so you do not need to `raise` its
response. additionally, cleaned up tests around that since raising
Exception and asserting Exception is raised is dangerous as it could
mask actual programming errors
2017-01-24 12:22:31 +00:00
Leo Hemsted
0324ba02ff split process_job up into process_job and process_row
makes tests a bit cleaner, and makes it much easier to test letter
functionality. haven't moved many tests around, just changed a couple of mock calls
2017-01-24 12:22:31 +00:00
minglis
0c6193e2e9 Merge pull request #775 from alphagov/do-not-write-test-data-to-the-history-table
Do not write test data to the history table
2017-01-10 13:05:06 +00:00
Leo Hemsted
3ed97151ee fix placeholders not appearing in email subject
it now switches utils.template.Template type, since the base Template
type now no longer has a subject attribute.

updated test case to use `sample_email_template_with_placeholders`
instead of `sample_email_template`
2016-12-22 14:40:33 +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
94609cef79 Fix how the exception is logged. 2016-11-28 17:22:03 +00:00
Rebecca Law
be113e031f Sometimes a message is picked up twice of the SQS queue, we need to safe gaurd ourselves for that.
In this PR the id for the notification is passed in and used to created the notification, which causes a integrity error.
Normally when we get a SQLAlchemy error here we send the message to the retry queue, but if the notification already exists
we just ignore it.
2016-11-25 17:32:01 +00:00
Martyn Inglis
9e2ba9ee81 Pushed the cache increment into the shared code that persists notifications.
Much simpler implementation, inc code removed from tasks and V1/V2 rest clients.
2016-11-22 12:53:20 +00:00
Martyn Inglis
7cfc58c994 Merge branch 'master' into caching-with-redis
Conflicts:
	app/celery/tasks.py
	tests/app/celery/test_tasks.py
2016-11-21 13:10:22 +00:00
Rebecca Law
247668202b Fix functional tests 2016-11-16 16:15:30 +00:00
Rebecca Law
d6c537cf44 Added job_id and row_number to the exception error message if the task needs to be retried. That way we have a way to tie the exception messages together 2016-11-15 11:44:48 +00:00
Martyn Inglis
ac6609e653 Couple of bugs squashed.
1) It's incr not inc on the redis client, so renamed the calls everywhere
2) Redis returns bytes/string rather than an int if the value stored is an int. Cast the result to an int before use. Not you can set up the GET to do this transparently but I've not done this as we *may * use GETS for non-int and  the callback sets up the cast for the connection not the call.
2016-11-12 15:37:57 +00:00
Martyn Inglis
4c0c30bb2e Ensure we count the tasks as well as the API calls.
After we have written to the database and placed it on a deliver queue we count it in the cache against the service.

This is the equivalent of doing it at the end of the API call.
2016-11-11 17:36:38 +00:00
Rebecca Law
4379308189 Fix test failures. 2016-11-11 17:28:15 +00:00
Rebecca Law
8f0a96c76c Merge branch 'master' into refactor-for-code-reuse 2016-11-11 16:51:18 +00:00
Rebecca Law
4f5254134b Fix logging in send_sms and send_email 2016-11-11 16:09:09 +00:00
Rebecca Law
4fe8d700ae Fix the send_sms and send_email code to send the notification id that has been persisted. 2016-11-11 16:00:31 +00:00
Rebecca Law
c45d1f63a7 Use the same method to persist a notification.
Refactored the send_sms task to use this method.
2016-11-11 14:56:33 +00:00
Rebecca Law
eafbbd9809 Refactor send_sms and send_email to use common code to persist the notificaiton. 2016-11-11 10:41:39 +00:00
Chris Hill-Scott
8474344c9a Ignore case and whitespace in personalisation keys
From a support ticket:

> it's possible to add a personalisation token with trailing whitespace
> (eg. "key " rather than "key"). Can this be trimmed in the UI to guard
> against this? (one of our devs copied and pasted it from a document
> and inadvertently included the space)

> Nothing major but caused a few hours of investigations!

Rather than trim the placeholder in the template, we should treat
placeholders in API calls the same way we do with CSV files, ie we
ignore case and spacing in the name of the placeholder. So
`(( First Name))` is equivalent to `((first_name))`, and both would be
populated with a dictionary like `{'firstName': 'Chris'}`.

Depends on:
- [x] https://github.com/alphagov/notifications-utils/pull/77
2016-11-10 11:40:00 +00:00
Martyn Inglis
15ba0a3eb1 Added job id to logger 2016-11-07 11:59:46 +00:00
Leo Hemsted
d22d055e21 only process jobs if they're pending
help prevent issues where scheduled jobs are processed twice. note this is NOT
a watertight solution - it holds no locks, and there is no guarantee that the
status won't have updated between asserting that its status is 'pending' and
updating it to be 'in progress'
2016-10-07 12:54:11 +01:00
Rebecca Law
6065ed57cf Fix for the job status
- It seems that when we changed the name of the job.status column that we didn't update the code to use job.job_status.
- Therefore none of the jobs since then have had the job status updated.
- Now that this is fix we can show the job status when there is an error like "sending exceeds limits"
  - This could happen if a job is scheduled to run at the top of the hour, so at the time of the job creation the limit was not exceed, but at the time of processing the job the limit is exceed.
2016-10-05 14:56:32 +01:00
Rebecca Law
9e7a7b1857 Merge branch 'master' into refactor-send_notifications
Conflicts:
	tests/app/notifications/rest/test_send_notification.py
2016-10-03 11:40:31 +01:00
Rebecca Law
e3d418506a Create query to sum notificaitons for the message limit check, this is a bit more efficient.
Refactored send_notifications method so that it is more readible.
Refectored the test_send_notificaitons so that it uses parametrized test to avoid duplication.
2016-10-03 10:57:10 +01:00
Martyn Inglis
ad5222442a Fixed build
- passing a single param to a celery task must be done as a list not a tuple.
2016-09-30 13:34:44 +01:00
Martyn Inglis
e3ed8fad1a Merge branch 'master' into research-mode-csv-file-queues
Conflicts:
	tests/app/celery/test_tasks.py
	tests/app/notifications/rest/test_send_notification.py
2016-09-30 11:07:32 +01:00
Imdad Ahad
db608a05d2 Refactor sending elegibility function and update across files 2016-09-28 17:00:17 +01:00
Martyn Inglis
3618a3967c Creating notification tasks should write send tasks to the research-mode queue if research mode service. 2016-09-28 15:29:10 +01:00
Martyn Inglis
c13ead77e4 Ensures that both the CSV processing and the API both use the new deliver_email and deliver_sms tasks not the old ones with the redundant parameter. 2016-09-28 15:05:50 +01:00