Commit Graph

6714 Commits

Author SHA1 Message Date
Rebecca Law
43c0122dd0 Fix db downgrade script 2019-11-06 13:54:16 +00:00
Rebecca Law
4da06f1d5d remove old db upgrade file 2019-11-06 11:17:01 +00:00
Rebecca Law
9def176e7a Fix typo in config 2019-11-06 10:56:37 +00:00
Rebecca Law
fd0c12912a Fix merge conflict with db upgrade 2019-11-06 10:54:38 +00:00
Rebecca Law
74546a265e Added cron for check_for_missing_rows_in_completed_jobs
Run the task every 10 minutes. Does that seem reasonable? Maybe that is too often.
2019-11-06 10:49:46 +00:00
Rebecca Law
db5a50c5a7 Adding a scheduled task to processing missing rows from job
Sometimes a job finishes but has missed a row in the middle. It is a mystery why this is happening, it could be that the task to save the notifications has been dropped.
So until we solve the missing let's find missing rows and process them.

A new scheduled task has been added to find any "finished" jobs that do not have enough notifications created. If there are missing notifications the job processes those rows for the job.
Adding the new task to beat schedule will be done in the next commit.

A unique key constraint has been added to Notifications to ensure that the row is not added twice. Any index or constraint can affect performance, but this unique constraint should not affect it enough for us to notice.
2019-11-06 10:49:46 +00:00
Leo Hemsted
975af113e4 Merge pull request #2639 from alphagov/remove-loadtesting-db-migration
remove loadtesting from the database
2019-11-06 10:49:46 +00:00
Leo Hemsted
59f1ce940d update tests to reflect no loadtesting provider 2019-11-05 15:01:55 +00:00
Leo Hemsted
4ed6ca1601 remove loadtesting from the database 2019-11-05 15:01:55 +00:00
Katie Smith
95ffc8bda6 Merge pull request #2651 from alphagov/tidy-fixtures
Tidy fixtures after Pytest 5 upgrade
2019-11-01 15:13:36 +00:00
Katie Smith
544a7a2311 Remove parameters from fixtures
Since Pytest 4, we can't call fixtures as if they were functions. This
change removes the parameters from the fixtures (since we can't use
them), except for when the parameter is another fixture.
2019-11-01 14:34:15 +00:00
Katie Smith
6411e10d7b Remove unused fixtures 2019-11-01 13:18:07 +00:00
Pea (Malgorzata Tyczynska)
2b1a84dd0d Merge pull request #2647 from alphagov/tell-users-why-letter-failed-validation
Grab metadata when getting pdf letter preview from S3
2019-11-01 10:19:53 +00:00
Katie Smith
51c509c0ac Merge pull request #2649 from alphagov/pytest-5-changes
Upgrade to Pytest 5 😅
2019-11-01 09:30:53 +00:00
Rebecca Law
6f9edf0c07 Merge pull request #2650 from alphagov/delay-10-before-killing
Change how the bash script is started.
2019-10-31 16:56:33 +00:00
Rebecca Law
fe18512dd2 Change how the bash script is started.
By adding `exec` to the entrypoint bash script for the application, we can trap an EXIT from the script and execute our custom `on_exit` method with checks if the application process is busy before terminating, waiting up to 10 seconds. We don't need to trap `TERM` so that's been removed again.

Written by:
@servingupaces
@tlwr
2019-10-31 16:41:16 +00:00
Katie Smith
e504410ced 🎉 Pytest 5 🎉 2019-10-31 15:50:37 +00:00
Katie Smith
8abe427cb7 Fix tests which call str() on exception messages
Since Pytest 5, `ExceptionInfo` objects (returned by `pytest.raises`) now
have the same `str` representation as `repr`. This means that `str(e)`
now needs to be changed to `str(e.value)`.

https://github.com/pytest-dev/pytest/issues/5412
2019-10-31 15:38:44 +00:00
Katie Smith
04c1c35efb Stop calling fixures as functions in the tests 2019-10-31 15:04:23 +00:00
Katie Smith
97b807a99d Add test function to create service whitelist
This will be used to stop us needing to call the `sample_service_whitelist` fixture as
a function.
2019-10-31 15:04:23 +00:00
Katie Smith
87d7ed21a2 Fix fixtures
Stopped 2 fixtures from calling other fixtures as functions and causing
errors.
2019-10-31 15:04:23 +00:00
Rebecca Law
c35aca25e0 Merge pull request #2645 from alphagov/trap-term
Catch the TERM signal in the run_app_*paas scripts
2019-10-31 10:46:41 +00:00
Katie Smith
ac1642d8db Merge pull request #2646 from alphagov/pytest-5-changes
Start making tests Pytest 4 compliant
2019-10-30 13:56:47 +00:00
Katie Smith
38243cf860 Stop calling fixtures as functions in the tests 2019-10-30 13:05:53 +00:00
Katie Smith
fb875c50c1 Stop fixtures in conftest from calling other fixtures
Stopped some the fixtures in conftest.py from calling other
fixtures as functions to make them Pytest 4 compliant.
2019-10-30 11:22:36 +00:00
Katie Smith
99c3837dc1 Fix the fixtures for templates lacking certain permissions
These fixtures were both calling other fixtures as functions and being
called as functions in the tests. Rewriting the tests to make them
Pytest 4 compatible means we are no longer using
`sample_template_without_letter_permission`, so this has been deleted.
2019-10-30 11:22:36 +00:00
David McDonald
6252dcf916 Merge pull request #2643 from alphagov/set-postage
Set postage
2019-10-30 10:22:33 +00:00
Toby Lorne
4ad2e30e52 Catch the TERM signal in the run_app_*paas scripts
When Cloud Foundry applications are to be rescheduled from one cell to
another, or they are stopped, they are sent a SIGTERM signal and 10
seconds later, a SIGKILL signal.

Currently the scripts trap the POSIX defined EXIT handler, rather than
the signal directly.

In order for the signal to properly be propagated to celery, and the
celery workers, the script should call the on_exit function when
receiving a TERM signal.

Signed-off-by: Toby Lorne <toby.lornewelch-richards@digital.cabinet-office.gov.uk>
Co-authored-by: Becca <rebecca.law@digital.cabinet.office.gov.uk>
Co-authored-by: Toby <toby.lornewelch-richards@digital.cabinet.office.gov.uk>
2019-10-29 17:21:16 +00:00
Pea Tyczynska
c2825e10b1 Grab metadata when getting pdf letter preview from S3
Also use this metadata to decide whether preview pages need
overlay or not. So far we have always added overlay when validation
has failed. Now we will only show it when validation failed due to
content being outside of printable area.
2019-10-29 16:19:50 +00:00
Leo Hemsted
ca96c5d81b Merge pull request #2638 from alphagov/remove-loadtesting
remove loadtesting from providers
2019-10-29 11:30:09 +00:00
David McDonald
bc1b67fe4d Merge pull request #2644 from alphagov/makefile-help
Improve help comments for makefile
2019-10-29 10:23:53 +00:00
Katie Smith
1a4576f67e Merge pull request #2642 from alphagov/celery-task-id
Add request_ids to some Celery tasks
2019-10-28 13:34:58 +00:00
David McDonald
bf1ba9d9df Improve help comments for makefile
- Adds help text for freeze-requirements
- moves help text into correct position for upload-paas-artifact
2019-10-28 11:26:55 +00:00
Katie Smith
ceb7cee009 Pass request_id to tasks if available
We want to pass the `request_id` to Celery tasks if the task is called
from an HTTP request, so that we can add the `request_id` to the logs.
This change overwrites `apply_async` to add the `request_id` to the
kwargs if available. When we call the task, we then add the `request_id`
to g on Flask's application context.

Tasks called from `send_task` won't have a `request_id` for now, and
this change only affects tasks called from HTTP requests (not from other
tasks or from Celery Beat).
2019-10-28 10:59:25 +00:00
Katie Smith
1d6716275a Bump utils to bring in changes to logging
Freezing the requirements changes the Werkzeug version to 0.16.0, which
requires a change in how we import an exception
(https://github.com/pallets/werkzeug/blob/master/CHANGES.rst#version-0160)
2019-10-28 10:54:19 +00:00
Rebecca Law
98c61f58b1 Merge pull request #2624 from alphagov/add-logs-for-jobs
Add more logging for process_job
2019-10-28 09:53:15 +00:00
David McDonald
714c349efd Use existing postage format for validation
Also adds explicit test for checking of postage
2019-10-25 16:13:22 +01:00
David McDonald
d1195dfd5a Use json schema to validate post request to send PDF letter
This approach was suggested as the way to do validation things on
Notify.
2019-10-25 14:36:13 +01:00
David McDonald
7f708153d2 Require 'postage' key when sending a pdf letter 2019-10-24 16:12:47 +01:00
Rebecca Law
8794f770b9 Merge pull request #2640 from alphagov/remove-gunicorn-header
remove gunicorn server header from responses
2019-10-24 13:20:50 +01:00
Leo Hemsted
acb5e9fd47 remove gunicorn server header from responses
All our requests identify the web server they were served with via the
`server` response header. This opens us up to potential attackers who
might be crawling the internet looking for specific versions with known
vulnerabilities. As our dependencies are open source, this doesn't
affect any targeted attacks as they can just look at our repos on
github, but this theoretically will marginally improve security.

Regardless, the header isn't useful [1], we're not the first people to
want to get rid of it, and gunicorn are in the process of at least
amending it to remove the version information [2].

This shouldn't have any impact on us, though an empty string will be
passed through to debug information in event of a crash. That's fine
though, as we already know what version we're running.

[1] https://www.fastly.com/blog/headers-we-dont-want
[2] https://github.com/benoitc/gunicorn/issues/825
2019-10-23 16:38:34 +01:00
Katie Smith
67a73f2054 Merge pull request #2637 from alphagov/check-trial-mode-uploaded-letters
Check service is not in trial mode for uploaded letters
2019-10-23 15:45:51 +01:00
Leo Hemsted
e094dd4bfd remove loadtesting from providers
we don't use it since we wrote our own provider stubs for performance
tests.

this removes it from the api - it's still in the DB and will be
retrieved by queries, but is set to disabled on prod
2019-10-23 11:45:07 +01:00
Leo Hemsted
496b6f4737 Merge pull request #2627 from alphagov/letter-alert-v3
Letter alert
2019-10-22 13:26:35 +01:00
Katie Smith
9b8e0ed856 Check service is not in trial mode for uploaded letters
This adds an api check that the service is not in trial mode when
someone tries to send an uploaded letter.
2019-10-22 09:17:52 +01:00
Pea (Malgorzata Tyczynska)
35602b96fc Merge pull request #2631 from alphagov/add-validation-message-to-s3-as-metadata
Put pdf letter validation failed message in S3 metadata
2019-10-18 10:29:54 +01:00
Rebecca Law
ad14f96b8d A small change to make the code just a little bit clearer. 2019-10-17 15:17:43 +01:00
Pea Tyczynska
6ee7ac6cac Refactor and harmonise metadata for invalid letters with those sent from admin app 2019-10-16 14:11:50 +01:00
Leo Hemsted
0340927a6e Merge pull request #2634 from alphagov/startup-timeout
set startup timeout to 10 minutes
2019-10-15 14:18:48 +01:00
Leo Hemsted
46b0cce17b set startup timeout to 10 minutes
5 minutes isn't long enough to scale api at load, leading to failed deploys
2019-10-15 12:09:06 +01:00