Commit Graph

66 Commits

Author SHA1 Message Date
Rebecca Law
7fc7d99dac Update the new endpoint to return a 404 if the job or service id are not found.
All our endpoint should perform a check that the params are valid - this is an easy whay to check that and is standard for our endpoints.
I reverted the query to just filter by job id.
2019-10-03 14:58:49 +01:00
Pea Tyczynska
c48aa77dd5 Use service_id in the query to make it safer, also use named parameters 2019-09-25 16:32:27 +01:00
Pea Tyczynska
8cf8d24e37 Return count of notifications in the database for a job
When we cancel a job, we need to check if all notifications are
already in the database. So far, we were querying for all
notification objects in the database and counting them in
admin app, which runs into pagination problems for large jobs,
and could time out for very large jobs.
2019-09-24 16:56:03 +01:00
Pea Tyczynska
2c79801c96 Return tuple from can_cancel_letter_job for clarity 2019-07-02 18:12:48 +01:00
Pea Tyczynska
da65ba0c91 Return specific error messages if job cannot be cancelled
Also move checking if job can be cancelled to the endpoint
2019-07-01 15:44:39 +01:00
Rebecca Law
663b260777 Adding a cancel-letter-job endpoint to cancel a letter job. 2019-06-28 15:57:39 +01:00
Rebecca Law
6565c19a9b Adding new method to cancel a letter job. 2019-06-28 15:57:39 +01:00
Leo Hemsted
251aecab1b base job start of processing_started rather than created_at
otherwise scheduled jobs will be viewed as old, and we'll pull stats
from the statistics tables, even if they might have not even started
yet
2018-12-17 15:47:16 +00:00
Leo Hemsted
b80beab76c use ft_notification_status and notifications for job statistics
we previously always read from NotificationHistory to get the
notification status stats for a job. Now, if the job is more than three
days old read from ft_notification_status table, otherwise read from
the notifications table (to keep live updates).
2018-12-12 13:27:19 +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
Chris Hill-Scott
84024a9efc Refuse to process invalid files
Since the admin app won’t be checking the metadata when it starts a job
now it’s possible that someone could make a post request which attempts
to start a job for an invalid file. This commit adds a check to make
sure that can’t happen.

This is more of an extra safety thing, rather than something that the
admin app or a user will see.
2018-04-30 11:47:27 +01:00
Chris Hill-Scott
a4857c08ab Read job metadata from S3 metadata
All of our uploads now have the metadata about the job set on them in
S3. So this commit moves to using that metadata, if it’s there, instead
of the data in the body of the post request.

The aim of this is to stop the admin app having to post this data, which
means that it won’t have to keep this data in the session for the
while doing the file upload flow.
2018-04-30 11:47:13 +01:00
Katie Smith
44c4026df2 Delete job-stats endpoints
Deleted these endpoints:
* /service/<uuid:service_id>/job-stats/<job_id>
* /service/<uuid:service_id>/job-stats
2018-03-12 10:48:46 +00:00
Leo Hemsted
28d5f9b87f flake8 - remove unused imports and ensure they're always at the top of the file 2017-11-28 14:28:01 +00:00
Ken Tsang
ff860ec242 403 when creating a letter job in trial mode 2017-08-30 16:04:10 +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
Rebecca Law
4fefec6aa3 New endpoints to return job stats.
Next step is to use the new endpoints in admin.
2017-06-13 10:56:03 +01:00
Rebecca Law
cc04b5eb1d Added new endpoint for job statistics.
The structure has been flattened, so I need to create a new endpoint, start using that endpoint, then change the name back.
Added template_id and version to the get job stats by id.
2017-06-12 17:15:32 +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
Imdad Ahad
49fb4823e3 Refactor tests 2017-04-21 11:07:45 +01:00
Imdad Ahad
4dfd5448ad Make get all notications return in csv format too:
* This adds functionality (via an extra req param) to the
* existing get all notifications method allowing us to specify
* when we want the API to return in csv/non-csv format
2017-04-20 12:31:49 +01:00
Rebecca Law
78242812ef Register a before_request event for all blueprints, that defines the authentication requirement.
There are three authentication methods:
 - requires_no_auth - public endpoint that does not require an Authorisation header
 - requires_auth - public endpoints that need an API key in the Authorisation header
 - requires_admin_auth - private endpoint that requires an Authorisation header which contains the API key for the defined as the client admin user
2017-03-16 18:15:49 +00:00
Imdad Ahad
f213e08a4f Add temporary logging where page size is above the config 2017-03-14 11:29:12 +00:00
imdadahad
907862be2f Revert "Add temporary logging for job notifications' retrieval" 2017-03-13 15:53:17 +00:00
Imdad Ahad
db97ff5b28 Log key pagination attrs and next download query params 2017-03-13 14:50:56 +00:00
Rebecca Law
fde3216f9e Check the service is active before sending the notification to the provider. 2017-01-31 13:53:13 +00:00
Rebecca Law
fe64b565a0 Create job now checks that the service is active before creating job.
Need to check what message and status code we should use for this case. Probably will create a InactiveServiceRequest exception.
2017-01-31 11:11:33 +00:00
Leo Hemsted
fb6cb5f236 add statuses filter to GET /service/{}/job
can now pass in a query string `?statuses=x,y,z` to filter jobs based on
`Job.job_status`. Not passing in a status or passing in an empty string is
equivalent to selecting every filter type at once.
2016-09-23 16:34:13 +01:00
Leo Hemsted
24903a19ef add pagination to GET /service/{}/job
accepts a page parameter to control what page of data

returns additional pagination fields in the response dict
* page_size: will always be 50. defined by Config.PAGE_SIZE
* total: the total amount of unpaginated records
* links: dict containing optionally prev, next, and last, links to
  other relevant pagination pages

also cleaned up some test imports
2016-09-21 16:54:02 +01:00
Chris Hill-Scott
4a7267be8b Add an endpoint to cancel a job
If you schedule a job you might change your mind or circumstances might
change. So you need to be able to cancel it. This commit adds a `POST`
endpoint for individual jobs which sets their status to `cancelled`.

This also means adding a new status of `cancelled`, so there’s a
migration…
2016-09-02 12:27:02 +01:00
Martyn Inglis
57267a36f2 Return empty stats list for job creation 2016-08-31 12:12:09 +01:00
minglis
4a078e3c61 Merge pull request #635 from alphagov/scheduled-delivery-of-jobs
Scheduled delivery of jobs
2016-08-30 12:48:48 +01:00
Martyn Inglis
b923392c49 Using UTC dates on API validation for scheduled jobs. 2016-08-30 12:47:33 +01:00
Martyn Inglis
dd7850b235 Bug fix:
- Get all jobs for service doesn't return the statistics.
- Dashboard therefore is incorrect

This is the API fix for this, returns the data.
2016-08-26 15:07:59 +01:00
Martyn Inglis
8b9319ac7a Merge branch 'master' into scheduled-delivery-of-jobs
Conflicts:
	app/dao/jobs_dao.py
	tests/app/dao/test_jobs_dao.py
	tests/app/job/test_rest.py
2016-08-25 14:53:00 +01:00
Martyn Inglis
10f499805c Updates to create job to handle scheduling
- If the job JSON contains a scheduling date then the new 'job_status" column is set to "scheduled"
- the date is persisted on the JOB row in the database
- Also the job WILL NOT be placed onto the queue of jobs. This is deferred to a later celery beat task.
2016-08-24 16:00:21 +01:00
Martyn Inglis
09cb94081b Returns the outcome statistics for the job on the API call. 2016-08-23 16:46:58 +01:00
Leo Hemsted
c81b30dba1 separated schemas once more into "with template" and "with personalisation"
"with personalisation" should only be used by the public notification api
"with template" should be used when we want template name, etc details.

also added an xfail test for correctly constructing notification
personalisation
2016-07-26 14:34:59 +01:00
Leo Hemsted
b28e7efd14 dont load template contents for job page
rename the notification_status_schema to make it apparent that it
involves the template, and then don't use it on the job page - the
job page doesn't do anything with the data. won't somebody think of
the cpu cycles! (also means it ignores problems with template
versions)
2016-07-26 14:34:59 +01:00
Leo Hemsted
2b645f490a move get_all_notifications_for_service and get_all_notifications_for_job
moved from notifications/rest -> service/rest and job/rest respectively
endpoint routes not affected
removed requires_admin decorator - that should be set by nginx config
as opposed to python code
2016-06-30 10:44:21 +01:00
Adam Shimali
c268401554 Updated for pr comments 2016-06-15 16:19:28 +01:00
Adam Shimali
b33312b855 Change endpoint responses where there are marshalling, unmarshalling
or param errors to raise invalid data exception. That will cause
those responses to be handled in by errors.py, which will log
the errors.

Set most of schemas to strict mode so that marshmallow will raise
exception rather than checking for errors in return tuple from load.

Added handler to errors.py for marshmallow validation errors.
2016-06-15 14:37:51 +01:00
Rebecca Law
2a7872cce1 Add a limit days query param for get all jobs. 2016-05-24 17:21:04 +01:00
Leo Hemsted
7801efd5ca don't create job if template has been archived 2016-05-24 13:08:02 +01:00
Rebecca Law
f72f5aba05 [WIP]
Start to add template_version to jobs and notification
2016-05-11 17:04:51 +01:00
Rebecca Law
3f7bae3428 Removed update_job endpoint because it is not being used 2016-04-27 09:46:45 +01:00
Adam Shimali
0d06be05e1 [WIP] Added dao method and rest endpoint for getting template
statistics by service.

Some cosmetic changes to imports.

Added fix for job rest not correctly returning errors.
2016-04-04 14:38:54 +01:00
Rebecca Law
123b0ead3a Replaced first queries with one queries, which throws a NoResultFound.
Able to remove many of the None checks as a result of this.
Fixed the tests were needed.
2016-03-11 15:34:20 +00:00
Rebecca Law
e055590b07 Changed db queries to use one, which throws NoResultFound exception, this exception is dealt with in our error handlers.
Now a lot of the if none checks can be removed.
2016-03-11 12:39:55 +00:00