Commit Graph

55 Commits

Author SHA1 Message Date
Leo Hemsted
0efa223fb2 rename days_ago to midnight_n_days_ago
also add some more timezone boundary tests and minor code cleanup
2018-04-30 11:50:56 +01:00
Leo Hemsted
5e702449cb move days_ago to utils and make it tz aware
it's used in a few places - it should definitely know what timezones
are and return datetimes rather than dates, which are hard to work with
in terms of figuring out how tz aware they are.
2018-04-30 11:13:21 +01:00
Katie Smith
c843e15f81 Stop populating job-statistics table when creating a job 2018-03-12 10:48:46 +00:00
Katie Smith
b582f9f077 Delete Statistics DAO and some Jobs DAO functions
* Deleted the statistics DAO
  (this was used for the job statistics tasks)
* Deleted the functions in the jobs DAO which are no longer used
  (the functions that were used for the job-stats endpoints)
2018-03-12 10:48:46 +00:00
Rebecca Law
bffc4863db Remove all methods no longer used now that we only send pdf files to DVLA. 2018-03-02 11:05:05 +00:00
Richard Chapman
d855b4e4ec Removed statsd from the api and use the statsd in the utils library.
The statsd code was added to the utils library a while ago, uses the
statsd from the util library and therefore consolidates the code into
once place.
2018-02-06 09:52:15 +00:00
Ken Tsang
1b35731fb2 Refactor code
- updated dao_get_letter_jobs_by_status to dao_get_letter_job_ids_by_status to return array of strings
2017-08-24 11:57:46 +01:00
Ken Tsang
18881cd580 Add scheduled letter jobs 2017-08-23 13:22:07 +01:00
Leo Hemsted
5d61b3644c add tests for new test-key handling 2017-08-02 11:14:05 +01:00
Leo Hemsted
13917c9c57 give test letter api notifications a different filename
so they can be distinguished on the frontend.

Also, some related cleanup:

* don't show test api letters on the frontpage
* make sure the subject is returned from the API for letters
* make sure the letter's address is returned for letters
2017-08-01 18:23:29 +01:00
Leo Hemsted
2ab105aaf4 add tests for letter api notifications 2017-07-27 16:43:55 +01:00
Imdad Ahad
a9c1338873 Remove Notification, NotificationHistory status labels:
Replace labels by adding a key kwarg in the model for status.

We still need this as sqlalchemy attmempts to look for `notification_status`
on the model (Notification/NotificationHistory). To achieve true ORM mapping
(map status -> notification_status) we need the key kwarg.

More here:
http://docs.sqlalchemy.org/en/latest/core/metadata.html#sqlalchemy.schema.Column#key
2017-07-10 14:09:30 +01:00
Rebecca Law
a83e744c68 Remove join to Template table.
Fix typo in unit test.
2017-06-13 11:55:14 +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
Rebecca Law
c7707873e4 Queries to get job statistics by job_id or by service_id. 2017-06-12 14:25:17 +01:00
Imdad Ahad
6b4597149f Add filter to get jobs to delete (sms, email, letter) 2017-06-06 16:01:27 +01:00
Chris Hill-Scott
78d071f22f Ignore one-off messages in job list on dashboard
Same as how we ignore ‘send yourself a test’ messages (see:
d8467bfc3c). The dashboard gets clogged
up with one off messages otherwise, which affects:
- performance
- users ability to find their jobs
2017-06-01 12:30:47 +01:00
Martyn Inglis
8d4ccc3003 Updated jobs_Dao to make a job stats row when making a job - saves the ambiguity later as to whether the row exists. 2017-05-12 12:17:34 +01:00
Martyn Inglis
b8cfaf02f6 Ordered the query - ambiguous orders made tests flaky 2017-04-13 12:52:30 +01:00
Rebecca Law
f7ab49246a Added an endpoint that returns all letter jobs, ordered by created_at desc. 2017-04-07 11:50:56 +01:00
Rebecca Law
4f6a66c904 Merge branch 'master' into update-job-status
Conflicts:
	app/dao/jobs_dao.py
	tests/app/dao/test_jobs_dao.py
2017-04-06 11:11:37 +01:00
Martyn Inglis
832005efef Updates to the delete CSV file job to reduce the number of eligible jobs in any run
- previously this was unbounded, so it got all jobs older then 7 days. In excess of 75,000 🔥
- this meant that the job took (a) a long time and (b) a lot memory and (c) doing the same thing every day

These changes mean that the job has a 2 day eligible window for jobs, minimising the number of eligible jobs in a run, whilst still retaining some leeway in event if it failing one night.

In principle the job runs early morning on a given day. The previous 7 days are left along, and then the previous 2 days worth of files are deleted:

so:
runs on
31st
30,29,28,27,26,25,24 are ignored
23,22 jobs here have files deleted
21 and earlier are ignored.
2017-04-05 16:23:41 +01:00
Rebecca Law
c49217b1bf Update job status to ready to send, indicating the file for the job has been uploaded to S3. 2017-04-05 11:57:56 +01:00
Rebecca Law
d090451dd8 Update code as per review comment. 2017-03-17 10:01:28 +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
ea4214c7d5 Added a jobs_dao method to answer if the all the notifications have been created in the database for the given job. 2017-03-14 10:50:09 +00:00
Leo Hemsted
d8467bfc3c filter out test jobs from the GET /service/{}/job endpoint
this is so that the filtering, which we do on the admin side, is applied
before pagination - so that the pages returned are all valid displayable
jobs. unfortunately this means that another config value has to be copied
to the server side but it's not the end of the world
2016-10-11 14:30:40 +01:00
Chris Hill-Scott
b4291684b7 Sort jobs by processed time first
Say you have a dashboard with some jobs you sent. Normally looks like:

job | sent
--- | ---
file.csv | **5pm**
file.csv | 3pm
file.csv | 1pm
file.csv | 11am

However if your 5pm job was scheduled at lunchtime, then it will look
like this:

job | sent
--- | ---
file.csv | 3pm
file.csv | 1pm
file.csv | **5pm**
file.csv | 11am

This is because the jobs are sorted by when they were created, not when
they were sent. It looks wrong.

**For jobs that have already been sent**

This commit changes the sort order to be based on `processed_at`
instead.

**For upcoming jobs**

If a job doesn’t have a `processed_at` time then it’s scheduled, but
hasn’t started yet. Only in this case should we still be sorting by
`created_at`.
2016-10-10 09:36:53 +01:00
Leo Hemsted
bdb4da4976 tests n stuff 2016-10-07 13:08:41 +01:00
Leo Hemsted
16dd16c026 move updating into the dao fn
this helps manage the transaction by keeping it inside one function in the dao,
so after the function completes you know that the transaction has been released
and concurrent processing can resume
2016-10-07 12:35:08 +01:00
Martyn Inglis
897ad6a957 prevent race conditions in run_scheduled_jobs queuing jobs multiple times
we were running into issues where multiple beats queue up the
run_scheduled_jobs task at the same time, and concurrency issues with selecting
scheduled jobs causes both tasks to trigger processing of the job.

Use with_for_update, which calls through to the postgres SELECT  ... FOR UPDATE
which locks other SELECT FOR UPDATES (ie other threads running same code) until
the rows are set to pending and the transaction completes - so the second
thread will not find any rows
2016-10-07 12:35:02 +01:00
Leo Hemsted
d3c0c48401 fix dao_get_jobs_by_service_id
statuses now defaults to correct val
2016-09-23 17:05:42 +01: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
29abd4c382 make dao_get_jobs_by_service_id paginated
it can return a pretty long list, especially when we run lots of
smoke tests, so make it accept pagination parameters, and return
a pagination object
2016-09-21 14:35:23 +01:00
Martyn Inglis
c3657839e4 New jobs dao method to get jobs that are older than a certain number of days.
Used in deleting CSV files scheduled task
2016-09-07 15:36:07 +01:00
Chris Hill-Scott
2aa8baec63 Make indentation consistent 2016-09-02 23:22:15 +01:00
Chris Hill-Scott
2c17825c12 Don’t use magic string for job status 2016-09-02 23:22:14 +01:00
Chris Hill-Scott
11a4b18451 Combine query filters when getting scheduled job
> filter_by and filter are just aliases for each other so can be
> combined together - filter is probably the better one (and then use
> == instead of keyword args)
2016-09-02 12:27:23 +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
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
9af85d9cb3 new jobs query to get all scheduled jobs 2016-08-24 16:24:30 +01:00
Martyn Inglis
09cb94081b Returns the outcome statistics for the job on the API call. 2016-08-23 16:46:58 +01:00
Rebecca Law
a67793cf8a Updated date query so that the created_at date is truncated so that we get all jobs created number of days requested. 2016-05-25 11:13:49 +01:00
Rebecca Law
2a7872cce1 Add a limit days query param for get all jobs. 2016-05-24 17:21:04 +01:00
Martyn Inglis
beb6f7ca57 Order jobs by service
- newest first
2016-03-14 16:15:39 +00: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
Martyn Inglis
b3884e2d6c Move job processing into celery
- brings boto S3 into new AWS folder
- CSV processing utils method

Rejigs the jobs rest endpoint - removes some now unused endpoints,

Calls to the task with the job, job processing in task, delegating SMS calls to the sms task
2016-02-24 17:12:30 +00:00
Martyn Inglis
635debb5a6 Moved the sending sms for a job into celery tasks 2016-02-23 17:30:50 +00:00