Commit Graph

5617 Commits

Author SHA1 Message Date
Leo Hemsted
f55b4ef594 Merge pull request #2142 from alphagov/revert-2131-celery4
Revert "Celery 4"
2018-10-09 14:28:07 +01:00
Leo Hemsted
2ed50e760f Revert "Celery 4" 2018-10-09 13:27:49 +01:00
Chris Hill-Scott
72358899ad Merge pull request #2136 from alphagov/bump-utils-30.5.3
Bump utils to 30.5.3
2018-10-05 16:15:25 +01:00
Leo Hemsted
ba7cf10393 Merge pull request #2131 from alphagov/celery4
Celery 4
2018-10-05 16:03:44 +01:00
Chris Hill-Scott
a1a4bad0e6 Bump utils to 30.5.3 2018-10-05 15:30:03 +01:00
Chris Hill-Scott
b4f7dca60f Merge pull request #2135 from alphagov/utils-30.5.2
Bump utils to 30.5.2
2018-10-05 14:15:46 +01:00
Chris Hill-Scott
2708515f18 Bump utils to 30.5.2 2018-10-05 13:43:17 +01:00
Leo Hemsted
2edb7f39e6 fix reqs file 2018-10-05 10:28:12 +01:00
Leo Hemsted
bfc4343b0e remove pip-accel and make sure commands work if you're in a venv
remove pip-accel - it's not been updated in two years, and pins our
version of pip to a version that is several breaking changes old.

make sure commands work if you're already in a venv - mostly by
checking for presence of $VIRTUAL_ENV, and ensuring we use the correct
pip to install packages. Also clean up the commands a bit.
2018-10-04 15:52:51 +01:00
Katie Smith
1bbcedf150 Merge pull request #2130 from alphagov/return-postage
Return postage from the monthly-usage endpoint
2018-10-04 14:03:46 +01:00
Leo Hemsted
640f00b0e8 install celery with sqs support
you need to `pip install celery[sqs]` to get the additional
dependencies that celery needs to use SQS queues - there are two libs -
boto3 and pycurl.

pycurl is a bunch of python handles around curl, so needs to be
installed from source so it can link to your curl/ssl libs. On paas and
in docker this works fine (needed to add `libcurl4-openssl-dev` to the
docker container), but on macos it can't find openssl. We need to pass
a couple of flags in:

* set the environment variable PYCURL_SSL_LIBRARY=openssl
* pass in the global options `build_ext` and `-I{openssl_headers_path}`.

As shown here:
https://github.com/pycurl/pycurl/issues/530#issuecomment-395403253

Env var is no biggie, but using any install-option flags disables
wheels for the whole pip install run. (See
https://github.com/pypa/pip/issues/2677 and
https://github.com/pypa/pip/issues/4118 for more context on the
install-options flags). A whole bunch of our dependencies don't
install nicely from source (but do from wheel), so this commit installs
pycurl separately as an initial step, with the requisite flags, and
then installs the rest of the requirements as before.

I've updated the makefile and bootstrap.sh files to reflect this, but
if you run `pip install -r requirements.txt` from scratch you will run
into issues.
2018-10-03 14:11:30 +01:00
Leo Hemsted
6ca2b8277c import exception from botocore
boto (2) is no longer a dependency
2018-10-03 14:11:30 +01:00
Leo Hemsted
e0551547d2 wait 20 seconds between long polls 2018-10-03 14:11:30 +01:00
Leo Hemsted
1786f99400 construct celery queues once in the base config
previously, we were confusing things by appending to CELERY_QUEUES in
both dev and test configs - these are executed at import time, so the
list contained all queues twice, regardless of what config you're
actually using.

Fortunately, the -Q command that we supply the workers with overrides
this config option, so other environments weren't affected. Given that,
we can tidy up this code by just declaring it in the base config every
time
2018-10-03 14:11:30 +01:00
Leo Hemsted
4b7ed9db2f upgrade celery to 4.2.0
celery 4.2.0 no longer requires boto2, so we can get rid of that
patched version.
2018-10-03 14:11:18 +01:00
Katie Smith
236bbc5f28 Return postage from the monthly-usage endpoint
We were already returning the month, notification_type, billing_units
and rate from the /monthly-usage billing endpoint. This adds in the
postage too so that we can display postage details on the usage page of
admin.
2018-10-03 13:07:46 +01:00
Leo Hemsted
0843503b7a Merge pull request #2123 from alphagov/estimate-deliv-date
letter estimated delivery now takes postage into account
2018-10-03 11:44:52 +01:00
Leo Hemsted
cffc697e7f letter estimated delivery now takes postage into account 2018-09-28 17:30:25 +01:00
Katie Smith
ebc7f3e16b Merge pull request #2122 from alphagov/update-requirements
Update requirements
2018-09-28 16:45:37 +01:00
Katie Smith
c2a6fc0439 Merge pull request #2112 from alphagov/add-postage-to-pk
Add postage to ft_billing primary key
2018-09-28 16:45:29 +01:00
Rebecca Law
d5d84eb5ee Update requirements 2018-09-28 16:37:40 +01:00
Katie Smith
71d28035dd Update ft_billing with real postage data
* Changed update_fact_billing DAO function to update the table with the
real data for postage instead of hard-coding in 'second'.
* Added a test for the create nightly billing task to test that rows
with different postage are being inserted correctly.
2018-09-28 16:32:18 +01:00
Katie Smith
f41e0f05ec Make postage column part of ft_billing primary key
Now that the postage column is populated and there are no null values,
it can be added to the composite primary key of ft_billing.
2018-09-28 16:19:49 +01:00
Katie Smith
f034c26e19 Merge pull request #2121 from alphagov/fix-failing-test
Remove test
2018-09-28 15:14:03 +01:00
Katie Smith
0aedbff750 Remove test
Removed the occasionally failing test to check how ft_billing upserts
postage data. This test will be re-added once the postage column has been
added to the primary key.
2018-09-28 15:00:29 +01:00
Katie Smith
07f152e59e Merge pull request #2111 from alphagov/add-ft-billing-postage-column
Add ft_billing postage column
2018-09-28 14:48:46 +01:00
Katie Smith
6727f0e0f5 Update ft_billing DAO functions to use postage
* Updated the 'fetch_billing_data_for_day' DAO function to take postage into
account
* Updated the 'update_fact_billing' DAO function to insert postage for
new rows. When updating rows which are identical apart from the postage, the
original row will be kept. (This behaviour will change once postage is
added to the primary key - at this point, upserting will add a new row.)
* Also changed some fixtures / test set up functions to take postage
into account
2018-09-28 13:52:17 +01:00
Katie Smith
0b5da2b8ad Update command to migrate data to ft_billing
Updated the 'migrate-data-to-ft-billing' command to populate the new
postage column of ft_billing. This will be populated with the
postage of the notification for letters, or 'none' for email or sms. We
need to ensure there are no null values in postage so that the postage
column can become part of the primary key later.

Also updated the query to get the right rate letter rate now that we are
updating rates in the letter_rates table.
2018-09-28 13:52:17 +01:00
Katie Smith
0936060f5d Add postage column to ft_billing
Added a new varchar column, postage, to ft_billing. This is nullable and
not part of the composite primary key for now, but this will change
later.
2018-09-28 13:52:10 +01:00
Katie Smith
48db3a5e11 Delete unused functions
These deleted functions were only used for the old billing endpoints
which no longer exist.
2018-09-28 13:47:20 +01:00
Katie Smith
335aeb386f Update FactBilling model to reflect current database state
The FactBilling model and the ft_billing database table have diverged
slightly - this makes some minor changes to the model columns so that
the model matches the table (which appears to be the correct version).

The ft_billing table is currently like this:

       Column       |            Type             | Modifiers | Storage  | Stats target | Description
--------------------+-----------------------------+-----------+----------+--------------+-------------
 bst_date           | date                        | not null  | plain    |              |
 template_id        | uuid                        | not null  | plain    |              |
 service_id         | uuid                        | not null  | plain    |              |
 notification_type  | text                        | not null  | extended |              |
 provider           | text                        | not null  | extended |              |
 rate_multiplier    | integer                     | not null  | plain    |              |
 international      | boolean                     | not null  | plain    |              |
 rate               | numeric                     | not null  | main     |              |
 billable_units     | integer                     |           | plain    |              |
 notifications_sent | integer                     |           | plain    |              |
 updated_at         | timestamp without time zone |           | plain    |              |
 created_at         | timestamp without time zone | not null  | plain    |              |
Indexes:
    "ft_billing_pkey" PRIMARY KEY, btree (bst_date, template_id, service_id, rate_multiplier, provider, notification_type, international, rate)
    "ix_ft_billing_bst_date" btree (bst_date)
    "ix_ft_billing_service_id" btree (service_id)
    "ix_ft_billing_template_id" btree (template_id)
2018-09-28 13:47:20 +01:00
Katie Smith
82f07de200 Merge pull request #2116 from alphagov/update-first-class-rates-dates
Update first class letter rate start dates
2018-09-28 13:45:45 +01:00
Leo Hemsted
6aa4bfa426 Merge pull request #2118 from alphagov/fix-awscli
fix awscli botocore dependency
2018-09-28 11:37:29 +01:00
Leo Hemsted
78b4231915 fix awscli botocore dependency
awscli has a requirement of a new version of botocore

moto has a requirement of an old version of boto3, which requires an
old version of botocore

We had to pin boto to an older version, because of the moto issues.
this commit pins awscli to the version currently deployed on prod, so
that it plays nice with that older version of boto/botocore
2018-09-28 11:25:55 +01:00
Rebecca Law
eeb705b68b Merge pull request #2114 from alphagov/dont-update-page-count
Do not update billable_units if page count does not match postal provider
2018-09-28 10:59:07 +01:00
Katie Smith
45e714e694 Update first class letter rate start dates
We want to bring the start dates for first class letter rates forward by
a month so that we don't see billing errors when sending first class letters now.
(The feature will still go live at the planned time - this is to let us test things
beforehand.)
2018-09-28 10:25:44 +01:00
Tom Byers
b0549f9623 Merge pull request #2110 from alphagov/bump-utils
Bump utils to 30.4.0
2018-09-28 10:22:12 +01:00
Tom Byers
78cc503a91 Bump utils to 30.4.0
Brings in changes to allow letter timings to
include 1st class letters.

https://github.com/alphagov/notifications-utils/pull/533
2018-09-28 10:02:16 +01:00
Rebecca Law
a4f357499d Sometimes the page counts from DVLA do not match our page counts. Our counts have always been right. This PR does not update notification with the DVLA page count but does still let us know the difference happened. 2018-09-27 16:13:15 +01:00
Leo Hemsted
f0f54c0dff Merge pull request #2113 from alphagov/fix-noti-migration
separate notification postage constraint into three separate commits
2018-09-27 15:48:44 +01:00
Leo Hemsted
2b354eb5df separate notification postage constraint into three separate commits
we had an issue where the notification postage constraint command ran
into a deadlock, after trying to acquire two exclusive access locks on
large frequently modified/read tables.

To avoid this happening, we've had to split the upgrade script into
three - one script to apply the not-valid constraint to notifications
table, one for notification_history, and a third to validate the two
constraints.

Note: The first two scripts acquire exclusive access locks, but the
third only needs a row by row lock.

since this involves changing the exsiting alembic upgrades, if you've
upgraded your db you'll need to run the following three commands to
revert your database to a previous good state.

```
alter table notifications drop constraint chk_notifications_postage_null;
alter table notification_history drop constraint chk_notification_history_postage_null;
update alembic_version set version_num = '0229_new_letter_rates';
```
2018-09-27 15:20:28 +01:00
Tom Byers
c126859efc Lock botocore library to <1.11.0
Using version 1.11.0 or above causes an error with
the moto library where it makes real HTTP requests
instead of mocking them:

https://github.com/spulec/moto/issues/1793

Until this is resolved, botocore needs to be
locked. This copies the approach the Digital
Marketplace team took to the same problem:

https://github.com/alphagov/digitalmarketplace-utils/pull/452
2018-09-27 14:38:29 +01:00
Leo Hemsted
f73d9ef852 Merge pull request #2108 from alphagov/postage-constraint
Postage constraint
2018-09-27 13:45:49 +01:00
Tom Byers
8b86257a8b Bump utils to 30.3.1
Brings in stripping of the line separator
character from emails.

https://github.com/alphagov/notifications-utils/pull/531
2018-09-26 10:23:14 +01:00
Leo Hemsted
69e08fa23b fix tests to create notifications properly
migrated away from calling fixtures as functions
2018-09-25 16:10:26 +01:00
Leo Hemsted
3739c573ea fix null check in constraint
There are two fun quirks of postgres/sql that we need to work around:
* any `x = y` where x or y is NULL returns NULL, rather than false.
* check constraints accept NULL or true values as good.

so, the check `postage in ('first', 'second')` returns `null` rather
than `false` when postage is null itself. This surprisingly passes the
check constraint. To get around this, we have to add an explicit not
null check as well.
2018-09-25 16:10:26 +01:00
Leo Hemsted
17612e5446 add postage constraint to notification history
A not valid constraint only checks against new rows, not existing rows.
We can call VALIDATE CONSTRAINT against this new constraint to check
the old rows (which we know are good, having run the command from
74961781). Adding a normal constraint acquires an ACCESS EXCLUSIVE
lock, but validate constraint only needs a SHARE UPDATE EXCLUSIVE lock.

see 9d4b8961 and 0a50993f for more information on marking constraints
as not valid.
2018-09-25 16:10:16 +01:00
Pea (Malgorzata Tyczynska)
d2962cdc10 Merge pull request #2096 from alphagov/new_letter_rates_from_10_2018
Introduce new letter rates, valid from 01.10.2018
2018-09-25 15:17:50 +01:00
Pea Tyczynska
ea3144c3fd Add downgrade steps to new rates migration, add end_date to old rates
and refactor migration statements for security good practice
2018-09-25 15:10:16 +01:00
Pea Tyczynska
165b65612e Change how rates are filtered by date to equal or greater 2018-09-25 15:10:16 +01:00