Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

02/04/2025 Production Deploy #1551

Open
wants to merge 237 commits into
base: production
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
237 commits
Select commit Hold shift + click to select a range
faf7062
start trying to get to 95% coverage
Nov 11, 2024
fe2a5a3
start trying to get to 95% coverage
Nov 11, 2024
5d902dc
fix
Nov 11, 2024
c091262
Fix
Nov 11, 2024
85b98cd
revert
Nov 11, 2024
e8edf33
back to s3
Nov 11, 2024
694b631
add no such key test
Nov 11, 2024
f564b3a
billing dao test
Nov 11, 2024
d27b234
billing dao test
Nov 11, 2024
4bcb94c
billing dao test
Nov 11, 2024
266a5b1
billing dao test
Nov 11, 2024
2f9dcc5
fix
Nov 11, 2024
323c9f0
fix
Nov 11, 2024
78f010f
fix
Nov 11, 2024
194df02
receive notifications
Nov 11, 2024
959e3ff
receive notifications
Nov 11, 2024
b875259
receive notifications
Nov 11, 2024
58d383e
receive notifications
Nov 11, 2024
ca3dcfc
receive notifications
Nov 11, 2024
233fd59
fix
Nov 11, 2024
be0422b
fix
Nov 11, 2024
0107e01
fix
Nov 11, 2024
6d8fdab
fix more sqlalchemy
Nov 14, 2024
7b83ea3
fix more
Nov 14, 2024
310386a
hmmm
Nov 14, 2024
5276ba4
hmmm
Nov 14, 2024
441b75d
hmmm
Nov 14, 2024
b708498
hmmm
Nov 14, 2024
f16c814
revert one test
Nov 14, 2024
0177fdc
hmmm
Nov 14, 2024
8c7cb44
more tests
Nov 15, 2024
b0bf042
more
Nov 15, 2024
704fff7
more
Nov 15, 2024
8f211cc
more
Nov 15, 2024
d1ebcba
more
Nov 15, 2024
1311598
more
Nov 15, 2024
3673a92
fix more
Nov 15, 2024
ee00100
fix tests
Nov 15, 2024
5c6a5f9
fix tests
Nov 15, 2024
5f4da49
more
Nov 15, 2024
98ee86f
more
Nov 15, 2024
703a29f
more
Nov 15, 2024
1f0a64d
more
Nov 15, 2024
555cf5d
more
Nov 15, 2024
3eadfb2
fix style
Nov 15, 2024
bc4d4c9
more
Nov 15, 2024
5b667a1
more
Nov 18, 2024
6c44f81
more
Nov 18, 2024
2eb692a
more
Nov 18, 2024
4ef1847
fix permission_dao
Nov 18, 2024
3168f28
more
Nov 18, 2024
4f3b99b
more
Nov 18, 2024
c77382c
more
Nov 18, 2024
da57887
fix
Nov 18, 2024
2c3c107
revert bad changes
Nov 18, 2024
ce42803
fix
Nov 18, 2024
92bf9c5
more
Nov 18, 2024
25d2901
try fixing pagination
Nov 18, 2024
4539e5c
try fixing pagination
Nov 18, 2024
71e4794
try fixing pagination
Nov 18, 2024
552d464
try fixing pagination
Nov 18, 2024
e7abb06
try fixing pagination
Nov 18, 2024
83a7df6
try fixing pagination
Nov 18, 2024
c3de127
try fixing pagination
Nov 18, 2024
d513c5e
debug
Nov 18, 2024
14bfcd3
debug
Nov 18, 2024
d2d5fa7
fix
Nov 18, 2024
c92a760
fix
Nov 18, 2024
4078a7e
fix
Nov 18, 2024
53f3948
fix
Nov 18, 2024
ce5b9cf
fix
Nov 18, 2024
38e7672
fix
Nov 18, 2024
43a1969
fix
Nov 18, 2024
2abb14d
fix
Nov 18, 2024
84ebf11
fix
Nov 18, 2024
27c9885
fix
Nov 18, 2024
f9cf3f3
fix scheduled tasks
Nov 19, 2024
b33e2ca
fix scheduled tasks
Nov 19, 2024
9d257eb
fix scheduled tasks
Nov 19, 2024
c45a5a3
fix
Nov 19, 2024
8945f84
fix
Nov 19, 2024
4d544ef
fix
Nov 19, 2024
bfcc8ac
fix
Nov 19, 2024
67aa1e6
fix
Nov 19, 2024
0d44f29
fix
Nov 19, 2024
32e73f6
revert
Nov 19, 2024
63ff83b
fix
Nov 19, 2024
a53c067
uploads
Nov 19, 2024
0c9995d
uploads
Nov 19, 2024
b388d9f
fix notifications
Nov 19, 2024
76dc06c
fix notifications
Nov 19, 2024
8b74448
fix notifications
Nov 19, 2024
331f0eb
fix notifications
Nov 19, 2024
fd7b3b9
fix notifications
Nov 19, 2024
a3658ce
fix notifications
Nov 19, 2024
4a03f5b
remove print statements
Nov 19, 2024
1a1de39
change querie to stmt
Nov 21, 2024
d283613
code review feedback and merge from main
Nov 21, 2024
6e23d0b
merge from main
Nov 22, 2024
9e5b21e
merge from main
Nov 26, 2024
8cd0bd8
code review feedback
Dec 19, 2024
096ec68
code review feedback
Dec 19, 2024
e4782e4
code review feedback
Dec 19, 2024
f4ce3d1
code review feedback
Dec 19, 2024
6591693
code review feedback
Dec 19, 2024
3388371
fix filter_bys
Dec 19, 2024
83193c2
fix fragile filter approach
Dec 19, 2024
db16f94
noqa the x == False for sqlalchemy
Dec 19, 2024
772f78d
noqa the x == False for sqlalchemy
Dec 19, 2024
5f9b4bc
noqa the x == False for sqlalchemy
Dec 19, 2024
67d8974
noqa the x == False for sqlalchemy
Dec 19, 2024
440bf85
noqa the x == False for sqlalchemy
Dec 19, 2024
c29fb78
noqa the x == False for sqlalchemy
Dec 19, 2024
9954ac4
noqa the x == False for sqlalchemy
Dec 19, 2024
605782c
noqa the x == False for sqlalchemy
Dec 19, 2024
bb1d81b
noqa the x == False for sqlalchemy
Dec 19, 2024
5a94229
noqa the x == False for sqlalchemy
Dec 19, 2024
8f572bb
noqa the x == False for sqlalchemy
Dec 19, 2024
f809a06
noqa the x == False for sqlalchemy
Dec 19, 2024
a77343e
noqa the x == False for sqlalchemy
Dec 19, 2024
f4e68d7
add pending stats
heyitsmebev Dec 20, 2024
3c0621f
more code review feedback
Dec 20, 2024
a520e02
Merge branch 'main' into 2199-add-pending-message-data-to-daily-and-u…
heyitsmebev Dec 20, 2024
d8b7b06
merge from main
Dec 23, 2024
4ac7c74
merge from main
Dec 30, 2024
942b4a3
fix
Dec 30, 2024
82aebcd
fix
Dec 30, 2024
16286eb
fix
Dec 30, 2024
feeef72
fix
Dec 30, 2024
2878fb0
fix enum
Dec 30, 2024
bf497d8
try again
Dec 30, 2024
3da4755
try again
Dec 30, 2024
4e3f899
try again
Dec 30, 2024
71f682a
try again
Dec 30, 2024
c7cb377
try again
Dec 30, 2024
67a5662
update pending count
heyitsmebev Dec 31, 2024
8cc6b07
merge from main
Jan 7, 2025
99d9db2
fix native enum
Jan 7, 2025
1f62b99
Merge branch 'main' into 2199-add-pending-message-data-to-daily-and-u…
heyitsmebev Jan 7, 2025
05055aa
Updated query
xlorepdarkhelm Jan 8, 2025
37fa118
Adding group by clause to outer query for function.
xlorepdarkhelm Jan 9, 2025
5cedd64
use singletons for s3 client
Jan 9, 2025
a527218
fix tests
Jan 9, 2025
fbd8643
fix tests
Jan 9, 2025
8656c44
Make sure join is correct table.
xlorepdarkhelm Jan 9, 2025
16bba7e
cleanup
Jan 9, 2025
b6337ad
updating pending count
heyitsmebev Jan 10, 2025
f1cc6aa
estructuring how to get total_notifications.
xlorepdarkhelm Jan 10, 2025
ef61069
black cleanup.
xlorepdarkhelm Jan 10, 2025
bc80841
Changing the queries again.
xlorepdarkhelm Jan 10, 2025
162823e
Query fixing.
xlorepdarkhelm Jan 10, 2025
9219049
Cleaning up function a bit.
xlorepdarkhelm Jan 10, 2025
b543db4
Moving where the pending calculation is done.
xlorepdarkhelm Jan 10, 2025
467357c
Getting total notifications per day made.
xlorepdarkhelm Jan 10, 2025
3f8c49d
Removing total_notification calculations.
xlorepdarkhelm Jan 10, 2025
7ef8081
pending count
heyitsmebev Jan 11, 2025
30dfc6a
pending count
heyitsmebev Jan 11, 2025
af46a67
cleaningu up pending
heyitsmebev Jan 11, 2025
50a183f
flake
heyitsmebev Jan 11, 2025
2eef7ab
remove comments
heyitsmebev Jan 11, 2025
fa00bd1
isort
heyitsmebev Jan 11, 2025
dd3c277
fix testing
heyitsmebev Jan 11, 2025
b224065
fix testing
heyitsmebev Jan 13, 2025
88c3da5
add testing
heyitsmebev Jan 13, 2025
fdf6158
merge from main
Jan 14, 2025
880237f
fix tuples
heyitsmebev Jan 15, 2025
9846c19
merge from main
Jan 15, 2025
981feda
code review feedback
Jan 15, 2025
025a10a
merge from main
Jan 16, 2025
687819a
Merge pull request #1528 from GSA/notify-api-1526
terrazoon Jan 17, 2025
87b8a1d
fix imports
Jan 17, 2025
5d82af7
merge from main
Jan 21, 2025
f94650c
fix time schedule for missing rows
Jan 21, 2025
e6899ef
Merge pull request #1417 from GSA/clean_up_sqlalchemy
terrazoon Jan 21, 2025
1fc78d8
Merge branch 'main' into 2199-add-pending-message-data-to-daily-and-u…
heyitsmebev Jan 22, 2025
669f4e9
bulk_update_mappings adr
Jan 22, 2025
d051955
change total message limit to 100000
Jan 23, 2025
3002dbf
change total message limit to 100000
Jan 23, 2025
2d2a54b
change the redis limit tracker to annual
Jan 23, 2025
a5a9522
automate formatting and import sorting
Jan 23, 2025
7e91398
ugh fix flake 8
Jan 23, 2025
0d87482
fix total message limit so it works
Jan 23, 2025
49f4129
add tada to makefile
Jan 23, 2025
2ac436f
add tada to makefile
Jan 23, 2025
78ab6ea
Merge pull request #1539 from GSA/fix_adr
ccostino Jan 28, 2025
a413ec0
merge from main
Jan 28, 2025
481f27d
remove check_rate_limiting
Jan 28, 2025
6b318b8
add api for message limit, messages_sent
Jan 28, 2025
c7553b1
add test
Jan 28, 2025
c52cbe8
add test
Jan 28, 2025
efe9024
add tests
Jan 28, 2025
ae499fd
add tests
Jan 28, 2025
8863400
add tests
Jan 28, 2025
c1c7e7b
add tests
Jan 28, 2025
d17a4ed
add tests
Jan 28, 2025
0381768
add tests
Jan 28, 2025
8f471cf
Merge pull request #1493 from GSA/2199-add-pending-message-data-to-da…
heyitsmebev Jan 28, 2025
91585a8
cleanup
Jan 29, 2025
88e623c
cleanup
Jan 29, 2025
aaf2685
Merge pull request #1541 from GSA/notify-api-1540
terrazoon Jan 29, 2025
798cfbc
make command to see sms sender phones
Jan 29, 2025
69c0abd
merge from main
Jan 29, 2025
b119457
Update zaproxy-api-scan reference
ccostino Jan 31, 2025
0e3e305
Update daily checks reference as well.
ccostino Jan 31, 2025
10b0ce7
Merge pull request #1549 from GSA/update-zaproxy-baseline-action
terrazoon Jan 31, 2025
50d8bef
Merge pull request #1545 from GSA/notify-api-1544
ccostino Feb 3, 2025
ec02da9
try to fix dynamic scan warnings
Feb 3, 2025
8a70e72
try to fix dynamic scan warnings
Feb 3, 2025
073c747
try to fix dynamic scan warnings
Feb 3, 2025
53c7121
revert to last good
Feb 3, 2025
d935e4a
revert to last good
Feb 3, 2025
9933db8
revert to last good
Feb 3, 2025
0226c07
revert to last good
Feb 3, 2025
3d6f112
fix minor startup error
Feb 3, 2025
973506a
fix minor startup error
Feb 3, 2025
7743bc4
fix minor startup error
Feb 3, 2025
0de1dd1
fix minor startup error
Feb 3, 2025
d61f96d
fix content-type conditionally
Feb 3, 2025
e65a9d8
ugh
Feb 3, 2025
fa0d308
fix werkzeug server header
Feb 3, 2025
1657025
fix werkzeug server header
Feb 4, 2025
8a9d1b8
fix werkzeug server header
Feb 4, 2025
dea1ef5
fix werkzeug server header
Feb 4, 2025
f3d7d56
fix werkzeug server header
Feb 4, 2025
1cbd40f
Merge pull request #1550 from GSA/notify-api-1548
ccostino Feb 7, 2025
1e77491
merge from main
Feb 10, 2025
dda96bb
Bump aiohttp from 3.10.10 to 3.10.11
dependabot[bot] Feb 10, 2025
18397f6
Merge pull request #1423 from GSA/dependabot/pip/aiohttp-3.10.11
A-Shumway42 Feb 10, 2025
89b620f
Bump setuptools from 72.2.0 to 75.8.0
dependabot[bot] Feb 10, 2025
acfdc24
Merge pull request #1527 from GSA/dependabot/pip/setuptools-75.8.0
ccostino Feb 10, 2025
5c3b065
Bump blinker from 1.8.2 to 1.9.0
dependabot[bot] Feb 10, 2025
970d2f9
Merge pull request #1555 from GSA/dependabot/pip/blinker-1.9.0
A-Shumway42 Feb 10, 2025
414cbe3
Merge pull request #1408 from GSA/notify-api-1351
terrazoon Feb 10, 2025
ea07e84
Bump cryptography from 43.0.3 to 44.0.1
dependabot[bot] Feb 11, 2025
c9b7978
Merge pull request #1557 from GSA/dependabot/pip/cryptography-44.0.1
A-Shumway42 Feb 12, 2025
7a509fe
Bump geojson from 3.1.0 to 3.2.0
dependabot[bot] Feb 13, 2025
9b37823
Merge pull request #1560 from GSA/dependabot/pip/geojson-3.2.0
ccostino Feb 13, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .ds.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -277,15 +277,15 @@
"filename": "tests/app/notifications/test_receive_notification.py",
"hashed_secret": "913a73b565c8e2c8ed94497580f619397709b8b6",
"is_verified": false,
"line_number": 26,
"line_number": 27,
"is_secret": false
},
{
"type": "Base64 High Entropy String",
"filename": "tests/app/notifications/test_receive_notification.py",
"hashed_secret": "d70eab08607a4d05faa2d0d6647206599e9abc65",
"is_verified": false,
"line_number": 56,
"line_number": 57,
"is_secret": false
}
],
Expand All @@ -295,7 +295,7 @@
"filename": "tests/app/notifications/test_validators.py",
"hashed_secret": "6c1a8443963d02d13ffe575a71abe19ea731fb66",
"is_verified": false,
"line_number": 768,
"line_number": 672,
"is_secret": false
}
],
Expand All @@ -305,7 +305,7 @@
"filename": "tests/app/service/test_rest.py",
"hashed_secret": "5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8",
"is_verified": false,
"line_number": 1284,
"line_number": 1285,
"is_secret": false
}
],
Expand Down Expand Up @@ -341,15 +341,15 @@
"filename": "tests/app/user/test_rest.py",
"hashed_secret": "5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8",
"is_verified": false,
"line_number": 108,
"line_number": 110,
"is_secret": false
},
{
"type": "Secret Keyword",
"filename": "tests/app/user/test_rest.py",
"hashed_secret": "0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33",
"is_verified": false,
"line_number": 826,
"line_number": 864,
"is_secret": false
}
],
Expand Down Expand Up @@ -384,5 +384,5 @@
}
]
},
"generated_at": "2024-10-31T21:25:32Z"
"generated_at": "2025-02-10T16:57:15Z"
}
7 changes: 4 additions & 3 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ jobs:
NOTIFY_E2E_TEST_HTTP_AUTH_PASSWORD: ${{ secrets.NOTIFY_E2E_TEST_HTTP_AUTH_PASSWORD }}
NOTIFY_E2E_TEST_HTTP_AUTH_USER: ${{ secrets.NOTIFY_E2E_TEST_HTTP_AUTH_USER }}
NOTIFY_E2E_TEST_PASSWORD: ${{ secrets.NOTIFY_E2E_TEST_PASSWORD }}
- name: Run style checks
run: poetry run flake8 .

- name: Check imports alphabetized
run: poetry run isort --check-only ./app ./tests
- name: Run style checks
run: poetry run flake8 .
- name: Check for dead code
run: make dead-code
- name: Run tests with coverage
Expand Down Expand Up @@ -136,7 +137,7 @@ jobs:
env:
SQLALCHEMY_DATABASE_TEST_URI: postgresql://user:password@localhost:5432/test_notification_api
- name: Run OWASP API Scan
uses: zaproxy/action-api-scan@v0.5.0
uses: zaproxy/action-api-scan@v0.9.0
with:
docker_name: 'ghcr.io/zaproxy/zaproxy:weekly'
target: 'http://localhost:6011/docs/openapi.yml'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/daily_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ jobs:
env:
SQLALCHEMY_DATABASE_TEST_URI: postgresql://user:password@localhost:5432/test_notification_api
- name: Run OWASP API Scan
uses: zaproxy/action-api-scan@v0.5.0
uses: zaproxy/action-api-scan@v0.9.0
with:
docker_name: 'ghcr.io/zaproxy/zaproxy:weekly'
target: 'http://localhost:6011/docs/openapi.yml'
Expand Down
10 changes: 9 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ bootstrap-with-docker: ## Build the image to run the app in Docker
run-procfile:
poetry run honcho start -f Procfile.dev



.PHONY: tada
tada:
poetry run isort .
poetry run black .
poetry run flake8 .

.PHONY: avg-complexity
avg-complexity:
echo "*** Shows average complexity in radon of all code ***"
Expand Down Expand Up @@ -83,7 +91,7 @@ test: export NEW_RELIC_ENVIRONMENT=test
test: ## Run tests and create coverage report
poetry run black .
poetry run flake8 .
poetry run isort --check-only ./app ./tests
poetry run isort ./app ./tests
poetry run coverage run --omit=*/migrations/*,*/tests/* -m pytest --maxfail=10

## TODO set this back to 95 asap
Expand Down
7 changes: 7 additions & 0 deletions app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,13 @@ def record_request_details():
@app.after_request
def after_request(response):
response.headers.add("X-Content-Type-Options", "nosniff")

# Some dynamic scan findings
response.headers.add("Cross-Origin-Opener-Policy", "same-origin")
response.headers.add("Cross-Origin-Embedder-Policy", "require-corp")
response.headers.add("Cross-Origin-Resource-Policy", "same-origin")
response.headers.add("Cross-Origin-Opener-Policy", "same-origin")

return response

@app.errorhandler(Exception)
Expand Down
3 changes: 2 additions & 1 deletion app/billing/rest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from flask import Blueprint, jsonify, request

from app import db
from app.billing.billing_schemas import (
create_or_update_free_sms_fragment_limit_schema,
serialize_ft_billing_remove_emails,
Expand Down Expand Up @@ -60,7 +61,7 @@ def get_free_sms_fragment_limit(service_id):
)

if annual_billing is None:
service = Service.query.get(service_id)
service = db.session.get(Service, service_id)
# An entry does not exist in annual_billing table for that service and year.
# Set the annual billing to the default free allowance based on the organization type of the service.

Expand Down
3 changes: 2 additions & 1 deletion app/celery/nightly_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ def cleanup_unfinished_jobs():
# The query already checks that the processing_finished time is null, so here we are saying
# if it started more than 4 hours ago, that's too long
try:
acceptable_finish_time = job.processing_started + timedelta(minutes=5)
if job.processing_started is not None:
acceptable_finish_time = job.processing_started + timedelta(minutes=5)
except TypeError:
current_app.logger.exception(
f"Job ID {job.id} processing_started is {job.processing_started}.",
Expand Down
4 changes: 4 additions & 0 deletions app/celery/provider_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from app.delivery import send_to_providers
from app.enums import NotificationStatus
from app.exceptions import NotificationTechnicalFailureException
from notifications_utils.clients.redis import total_limit_cache_key


@notify_celery.task(
Expand Down Expand Up @@ -41,6 +42,9 @@ def deliver_sms(self, notification_id):
# Code branches off to send_to_providers.py
send_to_providers.send_sms_to_provider(notification)

cache_key = total_limit_cache_key(notification.service_id)
redis_store.incr(cache_key)

except Exception as e:
update_notification_status_by_id(
notification_id,
Expand Down
31 changes: 18 additions & 13 deletions app/celery/scheduled_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
from datetime import datetime, timedelta

from flask import current_app
from sqlalchemy import between
from sqlalchemy import between, select, union
from sqlalchemy.exc import SQLAlchemyError

from app import notify_celery, redis_store, zendesk_client
from app import db, notify_celery, redis_store, zendesk_client
from app.celery.tasks import (
get_recipient_csv_and_template_and_sender_id,
process_incomplete_jobs,
Expand All @@ -20,7 +20,7 @@
from app.dao.invited_user_dao import expire_invitations_created_more_than_two_days_ago
from app.dao.jobs_dao import (
dao_set_scheduled_jobs_to_pending,
dao_update_job,
dao_update_job_status_to_error,
find_jobs_with_missing_rows,
find_missing_row_for_job,
)
Expand Down Expand Up @@ -115,30 +115,34 @@ def check_job_status():
end_minutes_ago = utc_now() - timedelta(minutes=END_MINUTES)
start_minutes_ago = utc_now() - timedelta(minutes=START_MINUTES)

incomplete_in_progress_jobs = Job.query.filter(
incomplete_in_progress_jobs = select(Job).where(
Job.job_status == JobStatus.IN_PROGRESS,
between(Job.processing_started, start_minutes_ago, end_minutes_ago),
)
incomplete_pending_jobs = Job.query.filter(
incomplete_pending_jobs = select(Job).where(
Job.job_status == JobStatus.PENDING,
Job.scheduled_for.isnot(None),
between(Job.scheduled_for, start_minutes_ago, end_minutes_ago),
)

jobs_not_complete_after_allotted_time = (
incomplete_in_progress_jobs.union(incomplete_pending_jobs)
.order_by(Job.processing_started, Job.scheduled_for)
.all()
jobs_not_completed_after_allotted_time = union(
incomplete_in_progress_jobs, incomplete_pending_jobs
)
jobs_not_completed_after_allotted_time = (
jobs_not_completed_after_allotted_time.order_by(
Job.processing_started, Job.scheduled_for
)
)

jobs_not_complete_after_allotted_time = db.session.execute(
jobs_not_completed_after_allotted_time
).all()

# temporarily mark them as ERROR so that they don't get picked up by future check_job_status tasks
# if they haven't been re-processed in time.
job_ids = []
for job in jobs_not_complete_after_allotted_time:
job.job_status = JobStatus.ERROR
dao_update_job(job)
dao_update_job_status_to_error(job)
job_ids.append(str(job.id))

if job_ids:
current_app.logger.info("Job(s) {} have not completed.".format(job_ids))
process_incomplete_jobs.apply_async([job_ids], queue=QueueNames.JOBS)
Expand Down Expand Up @@ -168,6 +172,7 @@ def replay_created_notifications():

@notify_celery.task(name="check-for-missing-rows-in-completed-jobs")
def check_for_missing_rows_in_completed_jobs():

jobs = find_jobs_with_missing_rows()
for job in jobs:
(
Expand Down
9 changes: 8 additions & 1 deletion app/celery/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,14 @@ def process_row(row, template, job, service, sender_id=None):
return notification_id


# TODO
# Originally this was checking a daily limit
# It is now checking an overall limit (annual?) for the free tier
# Is there any limit for the paid tier?
# Assuming the limit is annual, is it calendar year, fiscal year, MOU year?
# Do we need a command to run to clear the redis value, or should it happen automatically?
def __total_sending_limits_for_job_exceeded(service, job, job_id):
print(hilite("ENTER __total_sending_limits_for_job_exceeded"))
try:
total_sent = check_service_over_total_message_limit(KeyType.NORMAL, service)
if total_sent + job.notification_count > service.total_message_limit:
Expand All @@ -172,7 +179,7 @@ def __total_sending_limits_for_job_exceeded(service, job, job_id):
dao_update_job(job)
current_app.logger.exception(
"Job {} size {} error. Total sending limits {} exceeded".format(
job_id, job.notification_count, service.message_limit
job_id, job.notification_count, service.total_message_limit
),
)
return True
Expand Down
17 changes: 15 additions & 2 deletions app/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ def populate_annual_billing_with_defaults(year, missing_services_only):
AnnualBilling.financial_year_start == year,
),
)
.filter(AnnualBilling.id == None) # noqa
.where(AnnualBilling.id == None) # noqa
)
active_services = db.session.execute(stmt).scalars().all()
else:
Expand All @@ -665,7 +665,7 @@ def populate_annual_billing_with_defaults(year, missing_services_only):
previous_year = year - 1
services_with_zero_free_allowance = (
db.session.query(AnnualBilling.service_id)
.filter(
.where(
AnnualBilling.financial_year_start == previous_year,
AnnualBilling.free_sms_fragment_limit == 0,
)
Expand Down Expand Up @@ -846,6 +846,19 @@ def create_new_service(name, message_limit, restricted, email_from, created_by_i
db.session.rollback()


@notify_command(name="get-service-sender-phones")
@click.option("-s", "--service_id", required=True, prompt=True)
def get_service_sender_phones(service_id):
sender_phone_numbers = """
select sms_sender, is_default
from service_sms_senders
where service_id = :service_id
"""
rows = db.session.execute(text(sender_phone_numbers), {"service_id": service_id})
for row in rows:
print(row)


@notify_command(name="promote-user-to-platform-admin")
@click.option("-u", "--user-email-address", required=True, prompt=True)
def promote_user_to_platform_admin(user_email_address):
Expand Down
14 changes: 13 additions & 1 deletion app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
from datetime import datetime, timedelta
from os import getenv, path

from boto3 import Session
from celery.schedules import crontab
from kombu import Exchange, Queue

import notifications_utils
from app.clients import AWS_CLIENT_CONFIG
from app.cloudfoundry_config import cloud_config


Expand Down Expand Up @@ -51,6 +53,13 @@ class TaskNames(object):
SCAN_FILE = "scan-file"


session = Session(
aws_access_key_id=getenv("CSV_AWS_ACCESS_KEY_ID"),
aws_secret_access_key=getenv("CSV_AWS_SECRET_ACCESS_KEY"),
region_name=getenv("CSV_AWS_REGION"),
)


class Config(object):
NOTIFY_APP_NAME = "api"
DEFAULT_REDIS_EXPIRE_TIME = 4 * 24 * 60 * 60
Expand Down Expand Up @@ -166,6 +175,9 @@ class Config(object):

current_minute = (datetime.now().minute + 1) % 60

S3_CLIENT = session.client("s3")
S3_RESOURCE = session.resource("s3", config=AWS_CLIENT_CONFIG)

CELERY = {
"worker_max_tasks_per_child": 500,
"task_ignore_result": True,
Expand Down Expand Up @@ -327,7 +339,7 @@ class Config(object):

FREE_SMS_TIER_FRAGMENT_COUNT = 250000

TOTAL_MESSAGE_LIMIT = 250000
TOTAL_MESSAGE_LIMIT = 100000

DAILY_MESSAGE_LIMIT = notifications_utils.DAILY_MESSAGE_LIMIT

Expand Down
Loading
Loading