Commit Graph

5935 Commits

Author SHA1 Message Date
Rebecca Law
f11aa55e0b Adding new data models for letter branding. 2019-01-22 17:27:00 +00:00
Rebecca Law
52a1b534ee Add a new data model LETTER_BRANDING to store the letters. Add a new data model SERVICE_LETTER_BRANDING to map the service to the letter brand.
This will replace services.dvla_organisation_id and dvla_organisation.
2019-01-21 13:59:27 +00:00
Leo Hemsted
f316c1d02b Merge pull request #2312 from alphagov/cronitor
create cronitor decorator that alerts if tasks fail
2019-01-21 12:50:28 +00:00
Sakis
be1dd57a6a Merge pull request #2307 from alphagov/reliable-celery-multi-pids
Handle celery PIDs more reliably
2019-01-21 10:49:42 +00:00
Leo Hemsted
e1760adcd3 suppress cronitor request errors 2019-01-18 15:36:53 +00:00
Leo Hemsted
754c65a6a2 create cronitor decorator that alerts if tasks fail
make a decorator that pings cronitor before and after each task run.
Designed for use with nightly tasks, so we have visibility if they
fail. We have a bunch of cronitor monitors set up - 5 character keys
that go into a URL that we then make a GET to with a self-explanatory
url path (run/fail/complete).

the cronitor URLs are defined in the credentials repo as a dictionary
of celery task names to URL slugs. If the name passed in to the
decorator  isn't in that dict, it won't run.

to use it, all you need to do is call `@cronitor(my_task_name)`
instead of `@notify_celery.task`, and make sure that the task name and
the matching slug are included in the credentials repo (or locally,
json dumped and stored in the CRONITOR_KEYS environment variable)
2019-01-18 15:36:53 +00:00
Leo Hemsted
d783e2b236 move tests from test_scheduled_tasks to test_nightly_tasks 2019-01-18 15:36:53 +00:00
Leo Hemsted
d3d56a3224 separate nightly tasks and other scheduled tasks.
other tasks is anything that is run on a different frequency than
nightly
2019-01-18 15:36:53 +00:00
Rebecca Law
ef4b2c0564 Merge pull request #2309 from alphagov/5-letter-logos
Add 5 new letter logos
2019-01-18 10:48:08 +00:00
Rebecca Law
39c9b86c35 Merge pull request #2310 from alphagov/remove-used-query
Remove unused query
2019-01-18 10:47:45 +00:00
Pea (Malgorzata Tyczynska)
64191a93c2 Merge pull request #2308 from alphagov/precompiled_postage_response
Return notification postage in response for .post_precompiled_letter_notification
2019-01-18 10:19:46 +00:00
Rebecca Law
6ac1f39fd0 Remove dao_fetch_monthly_historical_stats_by_template, a query using NotificationHistory that is no longer used. 2019-01-17 17:20:21 +00:00
Chris Hill-Scott
b238512260 Add 5 new letter logos 2019-01-17 17:06:35 +00:00
Athanasios Voutsadakis
4427827b2f Handle celery PIDs more reliably
This addresses some problems that existed in the previous approach:

1. There was a race condition that could occur between the time we were
looking for the existence of the .pid files and actually reading them.

2. If for some reason the .pid file was left behind after a process had
died, the script would never know because we do:

    kill -s ${1} ${APP_PID} || true
2019-01-17 16:55:44 +00:00
Rebecca Law
8d36d72494 Merge pull request #2306 from alphagov/drop-stats_template_usage_by_month
Drop stats_template_usage_by_month table as it is no longer needed.
2019-01-17 15:39:35 +00:00
Alexey Bezhan
90dc69b6bc Merge pull request #2303 from alphagov/ft-status-template-statistics
Change template statistics endpoint to use fact_notification_status_dao
2019-01-17 15:04:20 +00:00
Pea Tyczynska
9ab97d3481 Return notification postage in response for .post_precompiled_letter_notification 2019-01-16 16:57:57 +00:00
Pea (Malgorzata Tyczynska)
276a9a3828 Merge pull request #2293 from alphagov/choose_postage_for_precompiled
Choose postage on POST request for precompiled letters
2019-01-16 14:13:26 +00:00
Rebecca Law
e148eca6ff Drop stats_template_usage_by_month table as it is no longer needed. 2019-01-15 16:55:56 +00:00
Rebecca Law
ac9186f95a Merge pull request #2305 from alphagov/fix-template-usage-query
Add missing filter for template usage query
2019-01-15 16:25:23 +00:00
Rebecca Law
3dca36ecfc Actually test the right thing :) 2019-01-15 16:16:19 +00:00
Rebecca Law
a4d89359c5 Adding a filter to exclude test keys for the template monthly usage query.
Added a test.
2019-01-15 16:13:38 +00:00
Pea Tyczynska
ac3832a918 Remove old redis template cache 2019-01-15 14:46:40 +00:00
Pea Tyczynska
d36c4d8a78 Remove now unused methods that populated template usage redis cache 2019-01-15 14:38:45 +00:00
Pea Tyczynska
3ce0024eec Remove unused functions for getting template statistics 2019-01-15 12:15:20 +00:00
Pea Tyczynska
52831813d8 Change template statistics endpoint to use fact_notification_status_dao 2019-01-15 11:55:45 +00:00
Rebecca Law
3fdf0c7822 Merge pull request #2302 from alphagov/clean-up-template-stats-table
Clean up template stats task and queries
2019-01-15 11:03:58 +00:00
Pea Tyczynska
5ebeb9937a Avoid call to database to get template in persist_notifications 2019-01-14 17:53:06 +00:00
Alexey Bezhan
876346f469 Add an option to group notification stats for 7 days by template
Currently, admin app requests service statistics (with notification
counts grouped by status) and template statistics (with counts by
template) in order to display the service dashboard.

Service statistics are gathered from FactNotificationStatus table
(counts for the last 7 days) combined with Notification (counts for
today).

Template statistics are currently gathered from redis cache, which
contains a separate counter per template per day. It's hard for us
to maintain consistency between redis and DB counts. Currently it
doesn't update the count for cancelled letters, counter resets in
the middle of the day might produce a wrong result for the rest of
the week and cleared redis cache can't be repopulated for services
with low data retention periods).

Since FactNotificationStatus already contains separate counts for
each template_id we can use the existing logic with some additional
filters to get separate counts for each template and status combination,
which would allow us to populate the service dashboard page from one
query response.
2019-01-14 16:58:57 +00:00
Rebecca Law
efad58edd8 There is no need to have a separate table to store template monthly statistics. It's easy enough to aggregate the stats from ft_notification_status.
This removes the nightly task, and all the dao methods.
The next PR will remove the table.
2019-01-14 16:30:36 +00:00
Rebecca Law
79f49ebdc2 Merge pull request #2298 from alphagov/use-ft-notification-statu-for-monthly-template-usage
Use ft_notification_status for monthly template usage
2019-01-14 15:43:41 +00:00
Rebecca Law
b5a3ef9576 Added order by.
Added more unit tests.
Remove comments.
2019-01-14 15:28:26 +00:00
Katie Smith
4f917067a5 Merge pull request #2295 from alphagov/move-unopenable-precompiled-letters
Move letters which can't be opened to invalid PDF bucket
2019-01-14 12:56:45 +00:00
Alexey Bezhan
5336a72d0f Merge pull request #2291 from alphagov/set-db-statement-timeout
Set statement timeout on all DB connections
2019-01-14 10:24:07 +00:00
Rebecca Law
92460fbd38 Merge branch 'master' into use-ft-notification-statu-for-monthly-template-usage 2019-01-11 17:11:23 +00:00
Rebecca Law
c3c9d1eac9 Add unit tests.
Fix data types in result set.
2019-01-11 17:09:42 +00:00
Katie Smith
a9b755b08c Move letters which can't be opened to invalid PDF bucket
If a precompiled letter can't be opened (e.g. because it isn't a valid
PDF) we were setting its billable units to 0, but not moving it to the
invalid PDF bucket. If a precompiled letter failed sanitisation, we were
moving it to the invalid PDF bucket but not setting its billable units
to 0.

This commit makes sure that we always set the billable units to 0
and move the PDF to the right bucket if it fails sanitisation or can't be
opened.
2019-01-11 16:59:07 +00:00
Chris Hill-Scott
04610716f3 Merge pull request #2296 from alphagov/north-somerset-letter-logo
Add letter logo for North Somerset council
2019-01-11 16:09:53 +00:00
Pea (Malgorzata Tyczynska)
cfb55daa12 Merge pull request #2292 from alphagov/exclude_cancelled_from_requested
Remove cancelled from requested statuses in service statistics
2019-01-11 15:01:20 +00:00
Chris Hill-Scott
3559063b91 Add letter logo for North Somerset council 2019-01-11 14:44:23 +00:00
Pea Tyczynska
bd5126481c Remove cancelled from requested statuses in service statistics 2019-01-11 14:27:54 +00:00
Leo Hemsted
5e7bff08aa Merge pull request #2287 from alphagov/redis-bump
bump utils (inc redis bump)
2019-01-11 10:59:46 +00:00
Leo Hemsted
a970318586 Merge pull request #2294 from alphagov/remove-unused-functions
remove unused usage functions
2019-01-11 10:59:17 +00:00
Pea Tyczynska
685bff40d1 Stop validate function from being too complex by moving subfunctions out of it 2019-01-10 17:31:32 +00:00
Rebecca Law
507138cc94 Create a new query for template monthly stats. 2019-01-10 16:24:51 +00:00
Leo Hemsted
20fe055ac9 remove unused usage functions 2019-01-10 16:08:15 +00:00
Pea Tyczynska
5a1094b6fd Throw error if postage parameter for precompiled POST request incorrect 2019-01-10 16:04:06 +00:00
Pea (Malgorzata Tyczynska)
c5e5c86982 Merge pull request #2290 from alphagov/its_not_a_failure_to_cancel
Cancelled notifications don't show as failures in statistics
2019-01-10 15:09:30 +00:00
Pea Tyczynska
56bae2b077 Allow users to set postage per precompiled letter 2019-01-09 17:49:19 +00:00
Alexey Bezhan
4a26ee1813 Set statement timeout on all DB connections
A recent issue with a long-running query (#2288) highlighted the
fact that even though the original HTTP connection might be closed
(for example after gorouter timeout of 15 minutes, which returns a
504 response to the client), the request worker will not be stopped.

This means that the worker is spending time and potentially DB
resources generating a response that will never be delivered.

Gunicorn's timeout setting only applies to sync workers and there
doesn't seem to be an option to interrupt individual requests in
gevent/eventlet deployments.

Since the most likely (and potentially most dangerous) scenario for
this is a long-running DB query, we can set a statement timeout on
our DB connections. This will raise a sqlalchemy.exc.OperationalError
(wrapping psycopg2.extensions.QueryCanceledError), interrupting the
request after the given timeout has been reached.

This is a Postgres client setting, so the database itself will abort
the transaction when it reaches the set timeout.

Since this will also apply to our celery tasks (including potentially
long-running nightly tasks) we set a timeout of 20 minutes to begin
with.

This can potentially be split in the future to set a different value
for each app, so that we could limit API requests even more.
2019-01-09 14:36:50 +00:00