Files
notifications-api/app/config.py

433 lines
16 KiB
Python
Raw Normal View History

import json
2024-08-13 14:51:51 -07:00
from datetime import datetime, timedelta
from os import getenv, path
2022-06-13 13:45:07 -07:00
2025-01-09 07:47:47 -08:00
from boto3 import Session
from celery.schedules import crontab
from kombu import Exchange, Queue
import notifications_utils
2025-01-09 07:47:47 -08:00
from app.clients import AWS_CLIENT_CONFIG
2022-10-31 15:37:12 -04:00
from app.cloudfoundry_config import cloud_config
2016-12-08 12:12:45 +00:00
class QueueNames(object):
2023-08-29 14:54:30 -07:00
PERIODIC = "periodic-tasks"
DATABASE = "database-tasks"
SEND_SMS = "send-sms-tasks"
CHECK_SMS = "check-sms_tasks"
SEND_EMAIL = "send-email-tasks"
REPORTING = "reporting-tasks"
JOBS = "job-tasks"
RETRY = "retry-tasks"
NOTIFY = "notify-internal-tasks"
CALLBACKS = "service-callbacks"
CALLBACKS_RETRY = "service-callbacks-retry"
SMS_CALLBACKS = "sms-callbacks"
ANTIVIRUS = "antivirus-tasks"
SAVE_API_EMAIL = "save-api-email-tasks"
SAVE_API_SMS = "save-api-sms-tasks"
@staticmethod
def all_queues():
return [
QueueNames.PERIODIC,
QueueNames.DATABASE,
QueueNames.SEND_SMS,
2023-05-04 07:56:24 -07:00
QueueNames.CHECK_SMS,
QueueNames.SEND_EMAIL,
QueueNames.REPORTING,
QueueNames.JOBS,
QueueNames.RETRY,
QueueNames.NOTIFY,
2017-12-13 10:57:08 +00:00
QueueNames.CALLBACKS,
QueueNames.CALLBACKS_RETRY,
QueueNames.SMS_CALLBACKS,
QueueNames.SAVE_API_EMAIL,
QueueNames.SAVE_API_SMS,
]
class TaskNames(object):
2023-08-29 14:54:30 -07:00
PROCESS_INCOMPLETE_JOBS = "process-incomplete-jobs"
SCAN_FILE = "scan-file"
2025-01-09 07:47:47 -08:00
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"),
)
2016-12-08 12:12:45 +00:00
class Config(object):
2023-08-29 14:54:30 -07:00
NOTIFY_APP_NAME = "api"
2024-12-04 09:20:38 -08:00
DEFAULT_REDIS_EXPIRE_TIME = 4 * 24 * 60 * 60
2023-08-29 14:54:30 -07:00
NOTIFY_ENVIRONMENT = getenv("NOTIFY_ENVIRONMENT", "development")
# URL of admin app
2023-08-29 14:54:30 -07:00
ADMIN_BASE_URL = getenv("ADMIN_BASE_URL", "http://localhost:6012")
2016-12-08 12:12:45 +00:00
# URL of api app (on AWS this is the internal api endpoint)
2023-08-29 14:54:30 -07:00
API_HOST_NAME = getenv("API_HOST_NAME", "http://localhost:6011")
2016-12-08 12:12:45 +00:00
2022-10-31 13:25:59 -04:00
# Credentials
# secrets that internal apps, such as the admin app or document download, must use to authenticate with the API
2022-10-31 15:37:12 -04:00
# ADMIN_CLIENT_ID is called ADMIN_CLIENT_USER_NAME in api repo, they should match
2023-08-29 14:54:30 -07:00
ADMIN_CLIENT_ID = getenv("ADMIN_CLIENT_ID", "notify-admin")
INTERNAL_CLIENT_API_KEYS = json.loads(
getenv(
2023-08-29 14:54:30 -07:00
"INTERNAL_CLIENT_API_KEYS",
('{"%s":["%s"]}' % (ADMIN_CLIENT_ID, getenv("ADMIN_CLIENT_SECRET"))),
)
2022-10-31 13:25:59 -04:00
)
2022-11-17 17:04:51 -05:00
ALLOW_EXPIRED_API_TOKEN = False
# encyption secret/salt
2023-08-29 14:54:30 -07:00
SECRET_KEY = getenv("SECRET_KEY")
DANGEROUS_SALT = getenv("DANGEROUS_SALT")
ROUTE_SECRET_KEY_1 = getenv("ROUTE_SECRET_KEY_1", "dev-route-secret-key-1")
ROUTE_SECRET_KEY_2 = getenv("ROUTE_SECRET_KEY_2", "dev-route-secret-key-2")
2022-10-31 13:25:59 -04:00
# DB settings
SQLALCHEMY_DATABASE_URI = cloud_config.database_url
2022-10-31 13:25:59 -04:00
SQLALCHEMY_RECORD_QUERIES = False
SQLALCHEMY_TRACK_MODIFICATIONS = False
2025-01-09 11:14:51 -08:00
SQLALCHEMY_POOL_SIZE = int(getenv("SQLALCHEMY_POOL_SIZE", 40))
2022-10-31 13:25:59 -04:00
SQLALCHEMY_POOL_TIMEOUT = 30
SQLALCHEMY_POOL_RECYCLE = 300
SQLALCHEMY_STATEMENT_TIMEOUT = 1200
2024-08-19 14:25:51 -07:00
PAGE_SIZE = 20
2022-10-31 13:25:59 -04:00
API_PAGE_SIZE = 250
2022-10-31 15:37:12 -04:00
REDIS_URL = cloud_config.redis_url
REDIS_ENABLED = getenv("REDIS_ENABLED", "1") == "1"
2022-10-31 13:25:59 -04:00
EXPIRE_CACHE_TEN_MINUTES = 600
EXPIRE_CACHE_EIGHT_DAYS = 8 * 24 * 60 * 60
2022-10-31 13:25:59 -04:00
# AWS Settings
AWS_US_TOLL_FREE_NUMBER = getenv("AWS_US_TOLL_FREE_NUMBER")
# Whether to ignore POSTs from SNS for replies to SMS we sent
RECEIVE_INBOUND_SMS = False
2023-01-31 17:27:17 -05:00
NOTIFY_EMAIL_DOMAIN = cloud_config.ses_email_domain
2023-08-29 14:54:30 -07:00
SES_STUB_URL = (
None # TODO: set to a URL in env and remove this to use a stubbed SES service
)
# AWS SNS topics for delivery receipts
2022-10-04 17:42:04 -07:00
VALIDATE_SNS_TOPICS = True
2023-01-31 17:27:17 -05:00
VALID_SNS_TOPICS = cloud_config.sns_topic_arns
2022-10-31 13:25:59 -04:00
# these should always add up to 100%
SMS_PROVIDER_RESTING_POINTS = {
2023-08-29 14:54:30 -07:00
"sns": 100,
2022-10-31 13:25:59 -04:00
}
2016-12-08 12:12:45 +00:00
2018-04-25 14:22:23 +01:00
# Zendesk
2023-08-29 14:54:30 -07:00
ZENDESK_API_KEY = getenv("ZENDESK_API_KEY")
2016-12-08 12:12:45 +00:00
# Logging
DEBUG = False
# Antivirus
2023-08-29 14:54:30 -07:00
ANTIVIRUS_ENABLED = getenv("ANTIVIRUS_ENABLED", "1") == "1"
2022-10-31 13:25:59 -04:00
SENDING_NOTIFICATIONS_TIMEOUT_PERIOD = 259200 # 3 days
INVITATION_EXPIRATION_DAYS = 2
2023-08-29 14:54:30 -07:00
TEST_MESSAGE_FILENAME = "Test message"
ONE_OFF_MESSAGE_FILENAME = "Report"
MAX_VERIFY_CODE_COUNT = 5
MAX_FAILED_LOGIN_COUNT = 10
2022-10-31 13:25:59 -04:00
API_RATE_LIMIT_ENABLED = True
# Default data
2023-08-29 14:54:30 -07:00
CONFIG_FILES = path.dirname(__file__) + "/config_files/"
NOTIFY_SERVICE_ID = "d6aa2c68-a2d9-4437-ab19-3ae8eb202553"
NOTIFY_USER_ID = "6af522d0-2915-4e52-83a3-3690455a5fe6"
INVITATION_EMAIL_TEMPLATE_ID = "4f46df42-f795-4cc4-83bb-65ca312f49cc"
SMS_CODE_TEMPLATE_ID = "36fb0730-6259-4da1-8a80-c8de22ad4246"
EMAIL_2FA_TEMPLATE_ID = "299726d2-dba6-42b8-8209-30e1d66ea164"
NEW_USER_EMAIL_VERIFICATION_TEMPLATE_ID = "ece42649-22a8-4d06-b87f-d52d5d3f0a27"
PASSWORD_RESET_TEMPLATE_ID = (
"474e9242-823b-4f99-813d-ed392e7f1201" # nosec B105 - this is not a password
)
ALREADY_REGISTERED_EMAIL_TEMPLATE_ID = "0880fbb1-a0c6-46f0-9a8e-36c986381ceb"
CHANGE_EMAIL_CONFIRMATION_TEMPLATE_ID = "eb4d9930-87ab-4aef-9bce-786762687884"
SERVICE_NOW_LIVE_TEMPLATE_ID = "618185c6-3636-49cd-b7d2-6f6f5eb3bdde"
ORGANIZATION_INVITATION_EMAIL_TEMPLATE_ID = "203566f0-d835-47c5-aa06-932439c86573"
TEAM_MEMBER_EDIT_EMAIL_TEMPLATE_ID = "c73f1d71-4049-46d5-a647-d013bdeca3f0"
TEAM_MEMBER_EDIT_MOBILE_TEMPLATE_ID = "8a31520f-4751-4789-8ea1-fe54496725eb"
REPLY_TO_EMAIL_ADDRESS_VERIFICATION_TEMPLATE_ID = (
"a42f1d17-9404-46d5-a647-d013bdfca3e1"
)
MOU_SIGNER_RECEIPT_TEMPLATE_ID = "4fd2e43c-309b-4e50-8fb8-1955852d9d71"
MOU_SIGNED_ON_BEHALF_SIGNER_RECEIPT_TEMPLATE_ID = (
"c20206d5-bf03-4002-9a90-37d5032d9e84"
)
MOU_SIGNED_ON_BEHALF_ON_BEHALF_RECEIPT_TEMPLATE_ID = (
"522b6657-5ca5-4368-a294-6b527703bd0b"
)
NOTIFY_INTERNATIONAL_SMS_SENDER = getenv("AWS_US_TOLL_FREE_NUMBER")
LETTERS_VOLUME_EMAIL_TEMPLATE_ID = "11fad854-fd38-4a7c-bd17-805fb13dfc12"
NHS_EMAIL_BRANDING_ID = "a7dc4e56-660b-4db7-8cff-12c37b12b5ea"
# we only need real email in Live environment (production)
2023-08-29 14:54:30 -07:00
DVLA_EMAIL_ADDRESSES = json.loads(getenv("DVLA_EMAIL_ADDRESSES", "[]"))
2024-08-13 14:51:51 -07:00
current_minute = (datetime.now().minute + 1) % 60
2025-01-09 07:47:47 -08:00
S3_CLIENT = session.client("s3")
S3_RESOURCE = session.resource("s3", config=AWS_CLIENT_CONFIG)
Rewrite config to fix deprecation warnings The new format was introduced in Celery 4 [1] and is due for removal in Celery 6 [2], hence the warnings e.g. [2021-10-26 14:31:57,588: WARNING/MainProcess] /Users/benthorner/.pyenv/versions/notifications-api/lib/python3.6/site-packages/celery/app/utils.py:206: CDeprecationWarning: The 'CELERY_TIMEZONE' setting is deprecated and scheduled for removal in version 6.0.0. Use the timezone instead alternative=f'Use the {_TO_NEW_KEY[setting]} instead') This rewrites the config to match our other apps [3][4]. Some of the settings have been removed entirely: - "CELERY_ENABLE_UTC = True" - this has been enabled by default since Celery 3 [5]. - "CELERY_ACCEPT_CONTENT = ['json']", "CELERY_TASK_SERIALIZER = 'json'" - these are the default settings since Celery 4 [6][7]. Finally, this removes a redundant (and broken) bit of development config - NOTIFICATION_QUEUE_PREFIX - that should be set in environment.sh [8]. [1]: https://docs.celeryproject.org/en/stable/history/whatsnew-4.0.html#lowercase-setting-names [2]: https://docs.celeryproject.org/en/stable/history/whatsnew-5.0.html#step-2-update-your-configuration-with-the-new-setting-names [3]: https://github.com/alphagov/notifications-govuk-alerts/blob/252ad01d3934e5d75aabbee92badbf38a009046a/app/config.py#L27 [4]: https://github.com/alphagov/notifications-template-preview/blob/03df0d92522f13091b081f3fe04c188e85d2ade6/app/__init__.py#L33 [5]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-enable_utc [6]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-task_serializer [7]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-accept_content [8]: https://github.com/alphagov/notifications-api/blob/2edbdec4eeaee4a937ece1a98000bd439624c0e0/README.md#environmentsh
2021-10-26 16:36:25 +01:00
CELERY = {
"broker_connection_retry_on_startup": True,
"worker_max_tasks_per_child": 500,
"task_ignore_result": True,
"result_persistent": False,
2023-08-29 14:54:30 -07:00
"broker_url": REDIS_URL,
"broker_transport_options": {
"visibility_timeout": 310,
},
2023-08-29 14:54:30 -07:00
"timezone": getenv("TIMEZONE", "UTC"),
"imports": [
"app.celery.tasks",
"app.celery.scheduled_tasks",
"app.celery.reporting_tasks",
"app.celery.nightly_tasks",
Rewrite config to fix deprecation warnings The new format was introduced in Celery 4 [1] and is due for removal in Celery 6 [2], hence the warnings e.g. [2021-10-26 14:31:57,588: WARNING/MainProcess] /Users/benthorner/.pyenv/versions/notifications-api/lib/python3.6/site-packages/celery/app/utils.py:206: CDeprecationWarning: The 'CELERY_TIMEZONE' setting is deprecated and scheduled for removal in version 6.0.0. Use the timezone instead alternative=f'Use the {_TO_NEW_KEY[setting]} instead') This rewrites the config to match our other apps [3][4]. Some of the settings have been removed entirely: - "CELERY_ENABLE_UTC = True" - this has been enabled by default since Celery 3 [5]. - "CELERY_ACCEPT_CONTENT = ['json']", "CELERY_TASK_SERIALIZER = 'json'" - these are the default settings since Celery 4 [6][7]. Finally, this removes a redundant (and broken) bit of development config - NOTIFICATION_QUEUE_PREFIX - that should be set in environment.sh [8]. [1]: https://docs.celeryproject.org/en/stable/history/whatsnew-4.0.html#lowercase-setting-names [2]: https://docs.celeryproject.org/en/stable/history/whatsnew-5.0.html#step-2-update-your-configuration-with-the-new-setting-names [3]: https://github.com/alphagov/notifications-govuk-alerts/blob/252ad01d3934e5d75aabbee92badbf38a009046a/app/config.py#L27 [4]: https://github.com/alphagov/notifications-template-preview/blob/03df0d92522f13091b081f3fe04c188e85d2ade6/app/__init__.py#L33 [5]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-enable_utc [6]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-task_serializer [7]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-accept_content [8]: https://github.com/alphagov/notifications-api/blob/2edbdec4eeaee4a937ece1a98000bd439624c0e0/README.md#environmentsh
2021-10-26 16:36:25 +01:00
],
# this is overriden by the -Q command, but locally, we should read from all queues
2023-08-29 14:54:30 -07:00
"task_queues": [
Queue(queue, Exchange("default"), routing_key=queue)
for queue in QueueNames.all_queues()
Rewrite config to fix deprecation warnings The new format was introduced in Celery 4 [1] and is due for removal in Celery 6 [2], hence the warnings e.g. [2021-10-26 14:31:57,588: WARNING/MainProcess] /Users/benthorner/.pyenv/versions/notifications-api/lib/python3.6/site-packages/celery/app/utils.py:206: CDeprecationWarning: The 'CELERY_TIMEZONE' setting is deprecated and scheduled for removal in version 6.0.0. Use the timezone instead alternative=f'Use the {_TO_NEW_KEY[setting]} instead') This rewrites the config to match our other apps [3][4]. Some of the settings have been removed entirely: - "CELERY_ENABLE_UTC = True" - this has been enabled by default since Celery 3 [5]. - "CELERY_ACCEPT_CONTENT = ['json']", "CELERY_TASK_SERIALIZER = 'json'" - these are the default settings since Celery 4 [6][7]. Finally, this removes a redundant (and broken) bit of development config - NOTIFICATION_QUEUE_PREFIX - that should be set in environment.sh [8]. [1]: https://docs.celeryproject.org/en/stable/history/whatsnew-4.0.html#lowercase-setting-names [2]: https://docs.celeryproject.org/en/stable/history/whatsnew-5.0.html#step-2-update-your-configuration-with-the-new-setting-names [3]: https://github.com/alphagov/notifications-govuk-alerts/blob/252ad01d3934e5d75aabbee92badbf38a009046a/app/config.py#L27 [4]: https://github.com/alphagov/notifications-template-preview/blob/03df0d92522f13091b081f3fe04c188e85d2ade6/app/__init__.py#L33 [5]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-enable_utc [6]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-task_serializer [7]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-accept_content [8]: https://github.com/alphagov/notifications-api/blob/2edbdec4eeaee4a937ece1a98000bd439624c0e0/README.md#environmentsh
2021-10-26 16:36:25 +01:00
],
2023-08-29 14:54:30 -07:00
"beat_schedule": {
Rewrite config to fix deprecation warnings The new format was introduced in Celery 4 [1] and is due for removal in Celery 6 [2], hence the warnings e.g. [2021-10-26 14:31:57,588: WARNING/MainProcess] /Users/benthorner/.pyenv/versions/notifications-api/lib/python3.6/site-packages/celery/app/utils.py:206: CDeprecationWarning: The 'CELERY_TIMEZONE' setting is deprecated and scheduled for removal in version 6.0.0. Use the timezone instead alternative=f'Use the {_TO_NEW_KEY[setting]} instead') This rewrites the config to match our other apps [3][4]. Some of the settings have been removed entirely: - "CELERY_ENABLE_UTC = True" - this has been enabled by default since Celery 3 [5]. - "CELERY_ACCEPT_CONTENT = ['json']", "CELERY_TASK_SERIALIZER = 'json'" - these are the default settings since Celery 4 [6][7]. Finally, this removes a redundant (and broken) bit of development config - NOTIFICATION_QUEUE_PREFIX - that should be set in environment.sh [8]. [1]: https://docs.celeryproject.org/en/stable/history/whatsnew-4.0.html#lowercase-setting-names [2]: https://docs.celeryproject.org/en/stable/history/whatsnew-5.0.html#step-2-update-your-configuration-with-the-new-setting-names [3]: https://github.com/alphagov/notifications-govuk-alerts/blob/252ad01d3934e5d75aabbee92badbf38a009046a/app/config.py#L27 [4]: https://github.com/alphagov/notifications-template-preview/blob/03df0d92522f13091b081f3fe04c188e85d2ade6/app/__init__.py#L33 [5]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-enable_utc [6]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-task_serializer [7]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-accept_content [8]: https://github.com/alphagov/notifications-api/blob/2edbdec4eeaee4a937ece1a98000bd439624c0e0/README.md#environmentsh
2021-10-26 16:36:25 +01:00
# app/celery/scheduled_tasks.py
2023-08-29 14:54:30 -07:00
"run-scheduled-jobs": {
"task": "run-scheduled-jobs",
"schedule": crontab(minute="0,15,30,45"),
"options": {"queue": QueueNames.PERIODIC},
Rewrite config to fix deprecation warnings The new format was introduced in Celery 4 [1] and is due for removal in Celery 6 [2], hence the warnings e.g. [2021-10-26 14:31:57,588: WARNING/MainProcess] /Users/benthorner/.pyenv/versions/notifications-api/lib/python3.6/site-packages/celery/app/utils.py:206: CDeprecationWarning: The 'CELERY_TIMEZONE' setting is deprecated and scheduled for removal in version 6.0.0. Use the timezone instead alternative=f'Use the {_TO_NEW_KEY[setting]} instead') This rewrites the config to match our other apps [3][4]. Some of the settings have been removed entirely: - "CELERY_ENABLE_UTC = True" - this has been enabled by default since Celery 3 [5]. - "CELERY_ACCEPT_CONTENT = ['json']", "CELERY_TASK_SERIALIZER = 'json'" - these are the default settings since Celery 4 [6][7]. Finally, this removes a redundant (and broken) bit of development config - NOTIFICATION_QUEUE_PREFIX - that should be set in environment.sh [8]. [1]: https://docs.celeryproject.org/en/stable/history/whatsnew-4.0.html#lowercase-setting-names [2]: https://docs.celeryproject.org/en/stable/history/whatsnew-5.0.html#step-2-update-your-configuration-with-the-new-setting-names [3]: https://github.com/alphagov/notifications-govuk-alerts/blob/252ad01d3934e5d75aabbee92badbf38a009046a/app/config.py#L27 [4]: https://github.com/alphagov/notifications-template-preview/blob/03df0d92522f13091b081f3fe04c188e85d2ade6/app/__init__.py#L33 [5]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-enable_utc [6]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-task_serializer [7]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-accept_content [8]: https://github.com/alphagov/notifications-api/blob/2edbdec4eeaee4a937ece1a98000bd439624c0e0/README.md#environmentsh
2021-10-26 16:36:25 +01:00
},
2023-08-29 14:54:30 -07:00
"delete-verify-codes": {
"task": "delete-verify-codes",
"schedule": timedelta(minutes=63),
"options": {"queue": QueueNames.PERIODIC},
Rewrite config to fix deprecation warnings The new format was introduced in Celery 4 [1] and is due for removal in Celery 6 [2], hence the warnings e.g. [2021-10-26 14:31:57,588: WARNING/MainProcess] /Users/benthorner/.pyenv/versions/notifications-api/lib/python3.6/site-packages/celery/app/utils.py:206: CDeprecationWarning: The 'CELERY_TIMEZONE' setting is deprecated and scheduled for removal in version 6.0.0. Use the timezone instead alternative=f'Use the {_TO_NEW_KEY[setting]} instead') This rewrites the config to match our other apps [3][4]. Some of the settings have been removed entirely: - "CELERY_ENABLE_UTC = True" - this has been enabled by default since Celery 3 [5]. - "CELERY_ACCEPT_CONTENT = ['json']", "CELERY_TASK_SERIALIZER = 'json'" - these are the default settings since Celery 4 [6][7]. Finally, this removes a redundant (and broken) bit of development config - NOTIFICATION_QUEUE_PREFIX - that should be set in environment.sh [8]. [1]: https://docs.celeryproject.org/en/stable/history/whatsnew-4.0.html#lowercase-setting-names [2]: https://docs.celeryproject.org/en/stable/history/whatsnew-5.0.html#step-2-update-your-configuration-with-the-new-setting-names [3]: https://github.com/alphagov/notifications-govuk-alerts/blob/252ad01d3934e5d75aabbee92badbf38a009046a/app/config.py#L27 [4]: https://github.com/alphagov/notifications-template-preview/blob/03df0d92522f13091b081f3fe04c188e85d2ade6/app/__init__.py#L33 [5]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-enable_utc [6]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-task_serializer [7]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-accept_content [8]: https://github.com/alphagov/notifications-api/blob/2edbdec4eeaee4a937ece1a98000bd439624c0e0/README.md#environmentsh
2021-10-26 16:36:25 +01:00
},
2024-12-13 16:45:09 -08:00
"process-delivery-receipts": {
"task": "process-delivery-receipts",
"schedule": timedelta(minutes=2),
2024-12-13 16:45:09 -08:00
"options": {"queue": QueueNames.PERIODIC},
},
2025-01-08 08:44:49 -08:00
"cleanup-delivery-receipts": {
"task": "cleanup-delivery-receipts",
"schedule": timedelta(minutes=82),
"options": {"queue": QueueNames.PERIODIC},
},
2025-01-10 07:58:24 -08:00
"batch-insert-notifications": {
"task": "batch-insert-notifications",
"schedule": 10.0,
"options": {"queue": QueueNames.PERIODIC},
},
"expire-or-delete-invitations": {
"task": "expire-or-delete-invitations",
2023-08-29 14:54:30 -07:00
"schedule": timedelta(minutes=66),
"options": {"queue": QueueNames.PERIODIC},
Rewrite config to fix deprecation warnings The new format was introduced in Celery 4 [1] and is due for removal in Celery 6 [2], hence the warnings e.g. [2021-10-26 14:31:57,588: WARNING/MainProcess] /Users/benthorner/.pyenv/versions/notifications-api/lib/python3.6/site-packages/celery/app/utils.py:206: CDeprecationWarning: The 'CELERY_TIMEZONE' setting is deprecated and scheduled for removal in version 6.0.0. Use the timezone instead alternative=f'Use the {_TO_NEW_KEY[setting]} instead') This rewrites the config to match our other apps [3][4]. Some of the settings have been removed entirely: - "CELERY_ENABLE_UTC = True" - this has been enabled by default since Celery 3 [5]. - "CELERY_ACCEPT_CONTENT = ['json']", "CELERY_TASK_SERIALIZER = 'json'" - these are the default settings since Celery 4 [6][7]. Finally, this removes a redundant (and broken) bit of development config - NOTIFICATION_QUEUE_PREFIX - that should be set in environment.sh [8]. [1]: https://docs.celeryproject.org/en/stable/history/whatsnew-4.0.html#lowercase-setting-names [2]: https://docs.celeryproject.org/en/stable/history/whatsnew-5.0.html#step-2-update-your-configuration-with-the-new-setting-names [3]: https://github.com/alphagov/notifications-govuk-alerts/blob/252ad01d3934e5d75aabbee92badbf38a009046a/app/config.py#L27 [4]: https://github.com/alphagov/notifications-template-preview/blob/03df0d92522f13091b081f3fe04c188e85d2ade6/app/__init__.py#L33 [5]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-enable_utc [6]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-task_serializer [7]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-accept_content [8]: https://github.com/alphagov/notifications-api/blob/2edbdec4eeaee4a937ece1a98000bd439624c0e0/README.md#environmentsh
2021-10-26 16:36:25 +01:00
},
2023-08-29 14:54:30 -07:00
"check-job-status": {
"task": "check-job-status",
"schedule": crontab(),
"options": {"queue": QueueNames.PERIODIC},
Rewrite config to fix deprecation warnings The new format was introduced in Celery 4 [1] and is due for removal in Celery 6 [2], hence the warnings e.g. [2021-10-26 14:31:57,588: WARNING/MainProcess] /Users/benthorner/.pyenv/versions/notifications-api/lib/python3.6/site-packages/celery/app/utils.py:206: CDeprecationWarning: The 'CELERY_TIMEZONE' setting is deprecated and scheduled for removal in version 6.0.0. Use the timezone instead alternative=f'Use the {_TO_NEW_KEY[setting]} instead') This rewrites the config to match our other apps [3][4]. Some of the settings have been removed entirely: - "CELERY_ENABLE_UTC = True" - this has been enabled by default since Celery 3 [5]. - "CELERY_ACCEPT_CONTENT = ['json']", "CELERY_TASK_SERIALIZER = 'json'" - these are the default settings since Celery 4 [6][7]. Finally, this removes a redundant (and broken) bit of development config - NOTIFICATION_QUEUE_PREFIX - that should be set in environment.sh [8]. [1]: https://docs.celeryproject.org/en/stable/history/whatsnew-4.0.html#lowercase-setting-names [2]: https://docs.celeryproject.org/en/stable/history/whatsnew-5.0.html#step-2-update-your-configuration-with-the-new-setting-names [3]: https://github.com/alphagov/notifications-govuk-alerts/blob/252ad01d3934e5d75aabbee92badbf38a009046a/app/config.py#L27 [4]: https://github.com/alphagov/notifications-template-preview/blob/03df0d92522f13091b081f3fe04c188e85d2ade6/app/__init__.py#L33 [5]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-enable_utc [6]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-task_serializer [7]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-accept_content [8]: https://github.com/alphagov/notifications-api/blob/2edbdec4eeaee4a937ece1a98000bd439624c0e0/README.md#environmentsh
2021-10-26 16:36:25 +01:00
},
2023-08-29 14:54:30 -07:00
"check-for-missing-rows-in-completed-jobs": {
"task": "check-for-missing-rows-in-completed-jobs",
"schedule": crontab(minute="*/10"),
"options": {"queue": QueueNames.PERIODIC},
Rewrite config to fix deprecation warnings The new format was introduced in Celery 4 [1] and is due for removal in Celery 6 [2], hence the warnings e.g. [2021-10-26 14:31:57,588: WARNING/MainProcess] /Users/benthorner/.pyenv/versions/notifications-api/lib/python3.6/site-packages/celery/app/utils.py:206: CDeprecationWarning: The 'CELERY_TIMEZONE' setting is deprecated and scheduled for removal in version 6.0.0. Use the timezone instead alternative=f'Use the {_TO_NEW_KEY[setting]} instead') This rewrites the config to match our other apps [3][4]. Some of the settings have been removed entirely: - "CELERY_ENABLE_UTC = True" - this has been enabled by default since Celery 3 [5]. - "CELERY_ACCEPT_CONTENT = ['json']", "CELERY_TASK_SERIALIZER = 'json'" - these are the default settings since Celery 4 [6][7]. Finally, this removes a redundant (and broken) bit of development config - NOTIFICATION_QUEUE_PREFIX - that should be set in environment.sh [8]. [1]: https://docs.celeryproject.org/en/stable/history/whatsnew-4.0.html#lowercase-setting-names [2]: https://docs.celeryproject.org/en/stable/history/whatsnew-5.0.html#step-2-update-your-configuration-with-the-new-setting-names [3]: https://github.com/alphagov/notifications-govuk-alerts/blob/252ad01d3934e5d75aabbee92badbf38a009046a/app/config.py#L27 [4]: https://github.com/alphagov/notifications-template-preview/blob/03df0d92522f13091b081f3fe04c188e85d2ade6/app/__init__.py#L33 [5]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-enable_utc [6]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-task_serializer [7]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-accept_content [8]: https://github.com/alphagov/notifications-api/blob/2edbdec4eeaee4a937ece1a98000bd439624c0e0/README.md#environmentsh
2021-10-26 16:36:25 +01:00
},
2023-08-29 14:54:30 -07:00
"replay-created-notifications": {
"task": "replay-created-notifications",
"schedule": crontab(minute="0, 15, 30, 45"),
"options": {"queue": QueueNames.PERIODIC},
Rewrite config to fix deprecation warnings The new format was introduced in Celery 4 [1] and is due for removal in Celery 6 [2], hence the warnings e.g. [2021-10-26 14:31:57,588: WARNING/MainProcess] /Users/benthorner/.pyenv/versions/notifications-api/lib/python3.6/site-packages/celery/app/utils.py:206: CDeprecationWarning: The 'CELERY_TIMEZONE' setting is deprecated and scheduled for removal in version 6.0.0. Use the timezone instead alternative=f'Use the {_TO_NEW_KEY[setting]} instead') This rewrites the config to match our other apps [3][4]. Some of the settings have been removed entirely: - "CELERY_ENABLE_UTC = True" - this has been enabled by default since Celery 3 [5]. - "CELERY_ACCEPT_CONTENT = ['json']", "CELERY_TASK_SERIALIZER = 'json'" - these are the default settings since Celery 4 [6][7]. Finally, this removes a redundant (and broken) bit of development config - NOTIFICATION_QUEUE_PREFIX - that should be set in environment.sh [8]. [1]: https://docs.celeryproject.org/en/stable/history/whatsnew-4.0.html#lowercase-setting-names [2]: https://docs.celeryproject.org/en/stable/history/whatsnew-5.0.html#step-2-update-your-configuration-with-the-new-setting-names [3]: https://github.com/alphagov/notifications-govuk-alerts/blob/252ad01d3934e5d75aabbee92badbf38a009046a/app/config.py#L27 [4]: https://github.com/alphagov/notifications-template-preview/blob/03df0d92522f13091b081f3fe04c188e85d2ade6/app/__init__.py#L33 [5]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-enable_utc [6]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-task_serializer [7]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-accept_content [8]: https://github.com/alphagov/notifications-api/blob/2edbdec4eeaee4a937ece1a98000bd439624c0e0/README.md#environmentsh
2021-10-26 16:36:25 +01:00
},
# app/celery/nightly_tasks.py
2023-08-29 14:54:30 -07:00
"timeout-sending-notifications": {
"task": "timeout-sending-notifications",
"schedule": crontab(hour=4, minute=5),
"options": {"queue": QueueNames.PERIODIC},
Rewrite config to fix deprecation warnings The new format was introduced in Celery 4 [1] and is due for removal in Celery 6 [2], hence the warnings e.g. [2021-10-26 14:31:57,588: WARNING/MainProcess] /Users/benthorner/.pyenv/versions/notifications-api/lib/python3.6/site-packages/celery/app/utils.py:206: CDeprecationWarning: The 'CELERY_TIMEZONE' setting is deprecated and scheduled for removal in version 6.0.0. Use the timezone instead alternative=f'Use the {_TO_NEW_KEY[setting]} instead') This rewrites the config to match our other apps [3][4]. Some of the settings have been removed entirely: - "CELERY_ENABLE_UTC = True" - this has been enabled by default since Celery 3 [5]. - "CELERY_ACCEPT_CONTENT = ['json']", "CELERY_TASK_SERIALIZER = 'json'" - these are the default settings since Celery 4 [6][7]. Finally, this removes a redundant (and broken) bit of development config - NOTIFICATION_QUEUE_PREFIX - that should be set in environment.sh [8]. [1]: https://docs.celeryproject.org/en/stable/history/whatsnew-4.0.html#lowercase-setting-names [2]: https://docs.celeryproject.org/en/stable/history/whatsnew-5.0.html#step-2-update-your-configuration-with-the-new-setting-names [3]: https://github.com/alphagov/notifications-govuk-alerts/blob/252ad01d3934e5d75aabbee92badbf38a009046a/app/config.py#L27 [4]: https://github.com/alphagov/notifications-template-preview/blob/03df0d92522f13091b081f3fe04c188e85d2ade6/app/__init__.py#L33 [5]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-enable_utc [6]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-task_serializer [7]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-accept_content [8]: https://github.com/alphagov/notifications-api/blob/2edbdec4eeaee4a937ece1a98000bd439624c0e0/README.md#environmentsh
2021-10-26 16:36:25 +01:00
},
2023-08-29 14:54:30 -07:00
"create-nightly-billing": {
"task": "create-nightly-billing",
"schedule": crontab(hour=4, minute=15),
"options": {"queue": QueueNames.REPORTING},
Rewrite config to fix deprecation warnings The new format was introduced in Celery 4 [1] and is due for removal in Celery 6 [2], hence the warnings e.g. [2021-10-26 14:31:57,588: WARNING/MainProcess] /Users/benthorner/.pyenv/versions/notifications-api/lib/python3.6/site-packages/celery/app/utils.py:206: CDeprecationWarning: The 'CELERY_TIMEZONE' setting is deprecated and scheduled for removal in version 6.0.0. Use the timezone instead alternative=f'Use the {_TO_NEW_KEY[setting]} instead') This rewrites the config to match our other apps [3][4]. Some of the settings have been removed entirely: - "CELERY_ENABLE_UTC = True" - this has been enabled by default since Celery 3 [5]. - "CELERY_ACCEPT_CONTENT = ['json']", "CELERY_TASK_SERIALIZER = 'json'" - these are the default settings since Celery 4 [6][7]. Finally, this removes a redundant (and broken) bit of development config - NOTIFICATION_QUEUE_PREFIX - that should be set in environment.sh [8]. [1]: https://docs.celeryproject.org/en/stable/history/whatsnew-4.0.html#lowercase-setting-names [2]: https://docs.celeryproject.org/en/stable/history/whatsnew-5.0.html#step-2-update-your-configuration-with-the-new-setting-names [3]: https://github.com/alphagov/notifications-govuk-alerts/blob/252ad01d3934e5d75aabbee92badbf38a009046a/app/config.py#L27 [4]: https://github.com/alphagov/notifications-template-preview/blob/03df0d92522f13091b081f3fe04c188e85d2ade6/app/__init__.py#L33 [5]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-enable_utc [6]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-task_serializer [7]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-accept_content [8]: https://github.com/alphagov/notifications-api/blob/2edbdec4eeaee4a937ece1a98000bd439624c0e0/README.md#environmentsh
2021-10-26 16:36:25 +01:00
},
2023-08-29 14:54:30 -07:00
"create-nightly-notification-status": {
"task": "create-nightly-notification-status",
"schedule": crontab(
hour=4, minute=30
), # after 'timeout-sending-notifications'
"options": {"queue": QueueNames.REPORTING},
Rewrite config to fix deprecation warnings The new format was introduced in Celery 4 [1] and is due for removal in Celery 6 [2], hence the warnings e.g. [2021-10-26 14:31:57,588: WARNING/MainProcess] /Users/benthorner/.pyenv/versions/notifications-api/lib/python3.6/site-packages/celery/app/utils.py:206: CDeprecationWarning: The 'CELERY_TIMEZONE' setting is deprecated and scheduled for removal in version 6.0.0. Use the timezone instead alternative=f'Use the {_TO_NEW_KEY[setting]} instead') This rewrites the config to match our other apps [3][4]. Some of the settings have been removed entirely: - "CELERY_ENABLE_UTC = True" - this has been enabled by default since Celery 3 [5]. - "CELERY_ACCEPT_CONTENT = ['json']", "CELERY_TASK_SERIALIZER = 'json'" - these are the default settings since Celery 4 [6][7]. Finally, this removes a redundant (and broken) bit of development config - NOTIFICATION_QUEUE_PREFIX - that should be set in environment.sh [8]. [1]: https://docs.celeryproject.org/en/stable/history/whatsnew-4.0.html#lowercase-setting-names [2]: https://docs.celeryproject.org/en/stable/history/whatsnew-5.0.html#step-2-update-your-configuration-with-the-new-setting-names [3]: https://github.com/alphagov/notifications-govuk-alerts/blob/252ad01d3934e5d75aabbee92badbf38a009046a/app/config.py#L27 [4]: https://github.com/alphagov/notifications-template-preview/blob/03df0d92522f13091b081f3fe04c188e85d2ade6/app/__init__.py#L33 [5]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-enable_utc [6]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-task_serializer [7]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-accept_content [8]: https://github.com/alphagov/notifications-api/blob/2edbdec4eeaee4a937ece1a98000bd439624c0e0/README.md#environmentsh
2021-10-26 16:36:25 +01:00
},
2023-08-29 14:54:30 -07:00
"delete-notifications-older-than-retention": {
"task": "delete-notifications-older-than-retention",
"schedule": crontab(
hour=7, minute=0
), # after 'create-nightly-notification-status'
"options": {"queue": QueueNames.REPORTING},
Rewrite config to fix deprecation warnings The new format was introduced in Celery 4 [1] and is due for removal in Celery 6 [2], hence the warnings e.g. [2021-10-26 14:31:57,588: WARNING/MainProcess] /Users/benthorner/.pyenv/versions/notifications-api/lib/python3.6/site-packages/celery/app/utils.py:206: CDeprecationWarning: The 'CELERY_TIMEZONE' setting is deprecated and scheduled for removal in version 6.0.0. Use the timezone instead alternative=f'Use the {_TO_NEW_KEY[setting]} instead') This rewrites the config to match our other apps [3][4]. Some of the settings have been removed entirely: - "CELERY_ENABLE_UTC = True" - this has been enabled by default since Celery 3 [5]. - "CELERY_ACCEPT_CONTENT = ['json']", "CELERY_TASK_SERIALIZER = 'json'" - these are the default settings since Celery 4 [6][7]. Finally, this removes a redundant (and broken) bit of development config - NOTIFICATION_QUEUE_PREFIX - that should be set in environment.sh [8]. [1]: https://docs.celeryproject.org/en/stable/history/whatsnew-4.0.html#lowercase-setting-names [2]: https://docs.celeryproject.org/en/stable/history/whatsnew-5.0.html#step-2-update-your-configuration-with-the-new-setting-names [3]: https://github.com/alphagov/notifications-govuk-alerts/blob/252ad01d3934e5d75aabbee92badbf38a009046a/app/config.py#L27 [4]: https://github.com/alphagov/notifications-template-preview/blob/03df0d92522f13091b081f3fe04c188e85d2ade6/app/__init__.py#L33 [5]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-enable_utc [6]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-task_serializer [7]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-accept_content [8]: https://github.com/alphagov/notifications-api/blob/2edbdec4eeaee4a937ece1a98000bd439624c0e0/README.md#environmentsh
2021-10-26 16:36:25 +01:00
},
2023-08-29 14:54:30 -07:00
"delete-inbound-sms": {
"task": "delete-inbound-sms",
"schedule": crontab(hour=5, minute=40),
"options": {"queue": QueueNames.PERIODIC},
Rewrite config to fix deprecation warnings The new format was introduced in Celery 4 [1] and is due for removal in Celery 6 [2], hence the warnings e.g. [2021-10-26 14:31:57,588: WARNING/MainProcess] /Users/benthorner/.pyenv/versions/notifications-api/lib/python3.6/site-packages/celery/app/utils.py:206: CDeprecationWarning: The 'CELERY_TIMEZONE' setting is deprecated and scheduled for removal in version 6.0.0. Use the timezone instead alternative=f'Use the {_TO_NEW_KEY[setting]} instead') This rewrites the config to match our other apps [3][4]. Some of the settings have been removed entirely: - "CELERY_ENABLE_UTC = True" - this has been enabled by default since Celery 3 [5]. - "CELERY_ACCEPT_CONTENT = ['json']", "CELERY_TASK_SERIALIZER = 'json'" - these are the default settings since Celery 4 [6][7]. Finally, this removes a redundant (and broken) bit of development config - NOTIFICATION_QUEUE_PREFIX - that should be set in environment.sh [8]. [1]: https://docs.celeryproject.org/en/stable/history/whatsnew-4.0.html#lowercase-setting-names [2]: https://docs.celeryproject.org/en/stable/history/whatsnew-5.0.html#step-2-update-your-configuration-with-the-new-setting-names [3]: https://github.com/alphagov/notifications-govuk-alerts/blob/252ad01d3934e5d75aabbee92badbf38a009046a/app/config.py#L27 [4]: https://github.com/alphagov/notifications-template-preview/blob/03df0d92522f13091b081f3fe04c188e85d2ade6/app/__init__.py#L33 [5]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-enable_utc [6]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-task_serializer [7]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-accept_content [8]: https://github.com/alphagov/notifications-api/blob/2edbdec4eeaee4a937ece1a98000bd439624c0e0/README.md#environmentsh
2021-10-26 16:36:25 +01:00
},
2023-08-29 14:54:30 -07:00
"save-daily-notification-processing-time": {
"task": "save-daily-notification-processing-time",
"schedule": crontab(hour=6, minute=0),
"options": {"queue": QueueNames.PERIODIC},
Rewrite config to fix deprecation warnings The new format was introduced in Celery 4 [1] and is due for removal in Celery 6 [2], hence the warnings e.g. [2021-10-26 14:31:57,588: WARNING/MainProcess] /Users/benthorner/.pyenv/versions/notifications-api/lib/python3.6/site-packages/celery/app/utils.py:206: CDeprecationWarning: The 'CELERY_TIMEZONE' setting is deprecated and scheduled for removal in version 6.0.0. Use the timezone instead alternative=f'Use the {_TO_NEW_KEY[setting]} instead') This rewrites the config to match our other apps [3][4]. Some of the settings have been removed entirely: - "CELERY_ENABLE_UTC = True" - this has been enabled by default since Celery 3 [5]. - "CELERY_ACCEPT_CONTENT = ['json']", "CELERY_TASK_SERIALIZER = 'json'" - these are the default settings since Celery 4 [6][7]. Finally, this removes a redundant (and broken) bit of development config - NOTIFICATION_QUEUE_PREFIX - that should be set in environment.sh [8]. [1]: https://docs.celeryproject.org/en/stable/history/whatsnew-4.0.html#lowercase-setting-names [2]: https://docs.celeryproject.org/en/stable/history/whatsnew-5.0.html#step-2-update-your-configuration-with-the-new-setting-names [3]: https://github.com/alphagov/notifications-govuk-alerts/blob/252ad01d3934e5d75aabbee92badbf38a009046a/app/config.py#L27 [4]: https://github.com/alphagov/notifications-template-preview/blob/03df0d92522f13091b081f3fe04c188e85d2ade6/app/__init__.py#L33 [5]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-enable_utc [6]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-task_serializer [7]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-accept_content [8]: https://github.com/alphagov/notifications-api/blob/2edbdec4eeaee4a937ece1a98000bd439624c0e0/README.md#environmentsh
2021-10-26 16:36:25 +01:00
},
2024-09-06 11:13:13 -07:00
"delete_old_s3_objects": {
"task": "delete-old-s3-objects",
2024-09-11 08:50:29 -07:00
"schedule": crontab(hour=7, minute=10),
2024-09-06 11:13:13 -07:00
"options": {"queue": QueueNames.PERIODIC},
},
2024-07-19 13:58:23 -07:00
"regenerate-job-cache": {
"task": "regenerate-job-cache",
2024-07-19 15:02:54 -07:00
"schedule": crontab(minute="*/30"),
2024-07-19 13:58:23 -07:00
"options": {"queue": QueueNames.PERIODIC},
},
2025-08-05 13:41:57 -07:00
"generate-notifications-reports": {
"task": "generate-notifications-reports",
2025-08-06 12:17:53 -07:00
"schedule": crontab(hour=1, minute=0),
2025-08-05 13:41:57 -07:00
"options": {"queue": QueueNames.PERIODIC},
},
2024-08-13 14:51:51 -07:00
"regenerate-job-cache-on-startup": {
"task": "regenerate-job-cache",
"schedule": crontab(
minute=current_minute
), # Runs once at the next minute
"options": {
"queue": QueueNames.PERIODIC,
"expires": 60,
}, # Ensure it doesn't run if missed
},
"clean-job-cache": {
"task": "clean-job-cache",
2024-09-26 15:17:57 -07:00
"schedule": crontab(hour=2, minute=11),
"options": {"queue": QueueNames.PERIODIC},
},
2023-08-29 14:54:30 -07:00
"cleanup-unfinished-jobs": {
"task": "cleanup-unfinished-jobs",
"schedule": crontab(hour=4, minute=5),
"options": {"queue": QueueNames.PERIODIC},
Rewrite config to fix deprecation warnings The new format was introduced in Celery 4 [1] and is due for removal in Celery 6 [2], hence the warnings e.g. [2021-10-26 14:31:57,588: WARNING/MainProcess] /Users/benthorner/.pyenv/versions/notifications-api/lib/python3.6/site-packages/celery/app/utils.py:206: CDeprecationWarning: The 'CELERY_TIMEZONE' setting is deprecated and scheduled for removal in version 6.0.0. Use the timezone instead alternative=f'Use the {_TO_NEW_KEY[setting]} instead') This rewrites the config to match our other apps [3][4]. Some of the settings have been removed entirely: - "CELERY_ENABLE_UTC = True" - this has been enabled by default since Celery 3 [5]. - "CELERY_ACCEPT_CONTENT = ['json']", "CELERY_TASK_SERIALIZER = 'json'" - these are the default settings since Celery 4 [6][7]. Finally, this removes a redundant (and broken) bit of development config - NOTIFICATION_QUEUE_PREFIX - that should be set in environment.sh [8]. [1]: https://docs.celeryproject.org/en/stable/history/whatsnew-4.0.html#lowercase-setting-names [2]: https://docs.celeryproject.org/en/stable/history/whatsnew-5.0.html#step-2-update-your-configuration-with-the-new-setting-names [3]: https://github.com/alphagov/notifications-govuk-alerts/blob/252ad01d3934e5d75aabbee92badbf38a009046a/app/config.py#L27 [4]: https://github.com/alphagov/notifications-template-preview/blob/03df0d92522f13091b081f3fe04c188e85d2ade6/app/__init__.py#L33 [5]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-enable_utc [6]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-task_serializer [7]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-accept_content [8]: https://github.com/alphagov/notifications-api/blob/2edbdec4eeaee4a937ece1a98000bd439624c0e0/README.md#environmentsh
2021-10-26 16:36:25 +01:00
},
2025-07-09 10:23:57 -07:00
"remove-sms-email-jobs": {
"task": "remove-sms-email-jobs",
2023-08-29 14:54:30 -07:00
"schedule": crontab(hour=8, minute=0),
"options": {"queue": QueueNames.PERIODIC},
Rewrite config to fix deprecation warnings The new format was introduced in Celery 4 [1] and is due for removal in Celery 6 [2], hence the warnings e.g. [2021-10-26 14:31:57,588: WARNING/MainProcess] /Users/benthorner/.pyenv/versions/notifications-api/lib/python3.6/site-packages/celery/app/utils.py:206: CDeprecationWarning: The 'CELERY_TIMEZONE' setting is deprecated and scheduled for removal in version 6.0.0. Use the timezone instead alternative=f'Use the {_TO_NEW_KEY[setting]} instead') This rewrites the config to match our other apps [3][4]. Some of the settings have been removed entirely: - "CELERY_ENABLE_UTC = True" - this has been enabled by default since Celery 3 [5]. - "CELERY_ACCEPT_CONTENT = ['json']", "CELERY_TASK_SERIALIZER = 'json'" - these are the default settings since Celery 4 [6][7]. Finally, this removes a redundant (and broken) bit of development config - NOTIFICATION_QUEUE_PREFIX - that should be set in environment.sh [8]. [1]: https://docs.celeryproject.org/en/stable/history/whatsnew-4.0.html#lowercase-setting-names [2]: https://docs.celeryproject.org/en/stable/history/whatsnew-5.0.html#step-2-update-your-configuration-with-the-new-setting-names [3]: https://github.com/alphagov/notifications-govuk-alerts/blob/252ad01d3934e5d75aabbee92badbf38a009046a/app/config.py#L27 [4]: https://github.com/alphagov/notifications-template-preview/blob/03df0d92522f13091b081f3fe04c188e85d2ade6/app/__init__.py#L33 [5]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-enable_utc [6]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-task_serializer [7]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-accept_content [8]: https://github.com/alphagov/notifications-api/blob/2edbdec4eeaee4a937ece1a98000bd439624c0e0/README.md#environmentsh
2021-10-26 16:36:25 +01:00
},
2023-08-29 14:54:30 -07:00
"check-for-services-with-high-failure-rates-or-sending-to-tv-numbers": {
"task": "check-for-services-with-high-failure-rates-or-sending-to-tv-numbers",
"schedule": crontab(day_of_week="mon-fri", hour=14, minute=30),
"options": {"queue": QueueNames.PERIODIC},
Rewrite config to fix deprecation warnings The new format was introduced in Celery 4 [1] and is due for removal in Celery 6 [2], hence the warnings e.g. [2021-10-26 14:31:57,588: WARNING/MainProcess] /Users/benthorner/.pyenv/versions/notifications-api/lib/python3.6/site-packages/celery/app/utils.py:206: CDeprecationWarning: The 'CELERY_TIMEZONE' setting is deprecated and scheduled for removal in version 6.0.0. Use the timezone instead alternative=f'Use the {_TO_NEW_KEY[setting]} instead') This rewrites the config to match our other apps [3][4]. Some of the settings have been removed entirely: - "CELERY_ENABLE_UTC = True" - this has been enabled by default since Celery 3 [5]. - "CELERY_ACCEPT_CONTENT = ['json']", "CELERY_TASK_SERIALIZER = 'json'" - these are the default settings since Celery 4 [6][7]. Finally, this removes a redundant (and broken) bit of development config - NOTIFICATION_QUEUE_PREFIX - that should be set in environment.sh [8]. [1]: https://docs.celeryproject.org/en/stable/history/whatsnew-4.0.html#lowercase-setting-names [2]: https://docs.celeryproject.org/en/stable/history/whatsnew-5.0.html#step-2-update-your-configuration-with-the-new-setting-names [3]: https://github.com/alphagov/notifications-govuk-alerts/blob/252ad01d3934e5d75aabbee92badbf38a009046a/app/config.py#L27 [4]: https://github.com/alphagov/notifications-template-preview/blob/03df0d92522f13091b081f3fe04c188e85d2ade6/app/__init__.py#L33 [5]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-enable_utc [6]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-task_serializer [7]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-accept_content [8]: https://github.com/alphagov/notifications-api/blob/2edbdec4eeaee4a937ece1a98000bd439624c0e0/README.md#environmentsh
2021-10-26 16:36:25 +01:00
},
2023-08-29 14:54:30 -07:00
},
}
Rewrite config to fix deprecation warnings The new format was introduced in Celery 4 [1] and is due for removal in Celery 6 [2], hence the warnings e.g. [2021-10-26 14:31:57,588: WARNING/MainProcess] /Users/benthorner/.pyenv/versions/notifications-api/lib/python3.6/site-packages/celery/app/utils.py:206: CDeprecationWarning: The 'CELERY_TIMEZONE' setting is deprecated and scheduled for removal in version 6.0.0. Use the timezone instead alternative=f'Use the {_TO_NEW_KEY[setting]} instead') This rewrites the config to match our other apps [3][4]. Some of the settings have been removed entirely: - "CELERY_ENABLE_UTC = True" - this has been enabled by default since Celery 3 [5]. - "CELERY_ACCEPT_CONTENT = ['json']", "CELERY_TASK_SERIALIZER = 'json'" - these are the default settings since Celery 4 [6][7]. Finally, this removes a redundant (and broken) bit of development config - NOTIFICATION_QUEUE_PREFIX - that should be set in environment.sh [8]. [1]: https://docs.celeryproject.org/en/stable/history/whatsnew-4.0.html#lowercase-setting-names [2]: https://docs.celeryproject.org/en/stable/history/whatsnew-5.0.html#step-2-update-your-configuration-with-the-new-setting-names [3]: https://github.com/alphagov/notifications-govuk-alerts/blob/252ad01d3934e5d75aabbee92badbf38a009046a/app/config.py#L27 [4]: https://github.com/alphagov/notifications-template-preview/blob/03df0d92522f13091b081f3fe04c188e85d2ade6/app/__init__.py#L33 [5]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-enable_utc [6]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-task_serializer [7]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-accept_content [8]: https://github.com/alphagov/notifications-api/blob/2edbdec4eeaee4a937ece1a98000bd439624c0e0/README.md#environmentsh
2021-10-26 16:36:25 +01:00
# we can set celeryd_prefetch_multiplier to be 1 for celery apps which handle only long running tasks
2023-08-29 14:54:30 -07:00
if getenv("CELERYD_PREFETCH_MULTIPLIER"):
CELERY["worker_prefetch_multiplier"] = getenv("CELERYD_PREFETCH_MULTIPLIER")
2023-08-29 14:54:30 -07:00
FROM_NUMBER = "development"
2016-02-09 13:31:45 +00:00
2017-02-03 13:34:09 +00:00
SIMULATED_EMAIL_ADDRESSES = (
2023-08-29 14:54:30 -07:00
"simulate-delivered@notifications.service.gov.uk",
"simulate-delivered-2@notifications.service.gov.uk",
"simulate-delivered-3@notifications.service.gov.uk",
2017-02-03 13:34:09 +00:00
)
# 7755 is success, 7167 is failure
SIMULATED_SMS_NUMBERS = ("+14254147755", "+14254147167")
FREE_SMS_TIER_FRAGMENT_COUNT = 250000
2025-06-06 09:18:07 -07:00
TOTAL_MESSAGE_LIMIT = 5000000
2023-03-14 16:28:38 -04:00
DAILY_MESSAGE_LIMIT = notifications_utils.DAILY_MESSAGE_LIMIT
2023-03-14 16:28:38 -04:00
2023-08-29 14:54:30 -07:00
HIGH_VOLUME_SERVICE = json.loads(getenv("HIGH_VOLUME_SERVICE", "[]"))
2023-08-29 14:54:30 -07:00
DOCUMENT_DOWNLOAD_API_HOST = getenv(
"DOCUMENT_DOWNLOAD_API_HOST", "http://localhost:7000"
)
DOCUMENT_DOWNLOAD_API_KEY = getenv("DOCUMENT_DOWNLOAD_API_KEY", "auth-token")
def _s3_credentials_from_env(bucket_prefix):
2022-10-31 15:37:12 -04:00
return {
2023-08-29 14:54:30 -07:00
"bucket": getenv(f"{bucket_prefix}_BUCKET_NAME"),
"access_key_id": getenv(f"{bucket_prefix}_AWS_ACCESS_KEY_ID"),
"secret_access_key": getenv(f"{bucket_prefix}_AWS_SECRET_ACCESS_KEY"),
"region": getenv(f"{bucket_prefix}_AWS_REGION"),
2022-10-31 15:37:12 -04:00
}
class Development(Config):
DEBUG = True
NOTIFY_LOG_LEVEL = "DEBUG"
SQLALCHEMY_ECHO = False
2023-08-29 14:54:30 -07:00
DVLA_EMAIL_ADDRESSES = ["success@simulator.amazonses.com"]
2022-10-31 13:25:59 -04:00
# Buckets
2023-08-29 14:54:30 -07:00
CSV_UPLOAD_BUCKET = _s3_credentials_from_env("CSV")
2022-10-31 13:25:59 -04:00
# credential overrides
2023-08-29 14:54:30 -07:00
DANGEROUS_SALT = "development-notify-salt"
SECRET_KEY = (
"dev-notify-secret-key" # nosec B105 - this is only used in development
)
INTERNAL_CLIENT_API_KEYS = {Config.ADMIN_CLIENT_ID: ["dev-notify-secret-key"]}
ALLOW_EXPIRED_API_TOKEN = getenv("ALLOW_EXPIRED_API_TOKEN", "0") == "1"
class Test(Development):
2023-08-29 14:54:30 -07:00
FROM_NUMBER = "testing"
TESTING = True
2022-10-31 13:25:59 -04:00
ANTIVIRUS_ENABLED = True
2023-08-29 14:54:30 -07:00
DVLA_EMAIL_ADDRESSES = [
"success@simulator.amazonses.com",
"success+2@simulator.amazonses.com",
]
2022-10-31 13:25:59 -04:00
HIGH_VOLUME_SERVICE = [
2023-08-29 14:54:30 -07:00
"941b6f9a-50d7-4742-8d50-f365ca74bf27",
"63f95b86-2d19-4497-b8b2-ccf25457df4e",
"7e5950cb-9954-41f5-8376-962b8c8555cf",
"10d1b9c9-0072-4fa9-ae1c-595e333841da",
]
2022-07-01 11:45:49 -07:00
# this is overriden in CI
2023-08-29 14:54:30 -07:00
SQLALCHEMY_DATABASE_URI = getenv("SQLALCHEMY_DATABASE_TEST_URI")
Rewrite config to fix deprecation warnings The new format was introduced in Celery 4 [1] and is due for removal in Celery 6 [2], hence the warnings e.g. [2021-10-26 14:31:57,588: WARNING/MainProcess] /Users/benthorner/.pyenv/versions/notifications-api/lib/python3.6/site-packages/celery/app/utils.py:206: CDeprecationWarning: The 'CELERY_TIMEZONE' setting is deprecated and scheduled for removal in version 6.0.0. Use the timezone instead alternative=f'Use the {_TO_NEW_KEY[setting]} instead') This rewrites the config to match our other apps [3][4]. Some of the settings have been removed entirely: - "CELERY_ENABLE_UTC = True" - this has been enabled by default since Celery 3 [5]. - "CELERY_ACCEPT_CONTENT = ['json']", "CELERY_TASK_SERIALIZER = 'json'" - these are the default settings since Celery 4 [6][7]. Finally, this removes a redundant (and broken) bit of development config - NOTIFICATION_QUEUE_PREFIX - that should be set in environment.sh [8]. [1]: https://docs.celeryproject.org/en/stable/history/whatsnew-4.0.html#lowercase-setting-names [2]: https://docs.celeryproject.org/en/stable/history/whatsnew-5.0.html#step-2-update-your-configuration-with-the-new-setting-names [3]: https://github.com/alphagov/notifications-govuk-alerts/blob/252ad01d3934e5d75aabbee92badbf38a009046a/app/config.py#L27 [4]: https://github.com/alphagov/notifications-template-preview/blob/03df0d92522f13091b081f3fe04c188e85d2ade6/app/__init__.py#L33 [5]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-enable_utc [6]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-task_serializer [7]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-accept_content [8]: https://github.com/alphagov/notifications-api/blob/2edbdec4eeaee4a937ece1a98000bd439624c0e0/README.md#environmentsh
2021-10-26 16:36:25 +01:00
CELERY = {
**Config.CELERY,
2023-08-29 14:54:30 -07:00
"broker_url": "you-forgot-to-mock-celery-in-your-tests://",
Rewrite config to fix deprecation warnings The new format was introduced in Celery 4 [1] and is due for removal in Celery 6 [2], hence the warnings e.g. [2021-10-26 14:31:57,588: WARNING/MainProcess] /Users/benthorner/.pyenv/versions/notifications-api/lib/python3.6/site-packages/celery/app/utils.py:206: CDeprecationWarning: The 'CELERY_TIMEZONE' setting is deprecated and scheduled for removal in version 6.0.0. Use the timezone instead alternative=f'Use the {_TO_NEW_KEY[setting]} instead') This rewrites the config to match our other apps [3][4]. Some of the settings have been removed entirely: - "CELERY_ENABLE_UTC = True" - this has been enabled by default since Celery 3 [5]. - "CELERY_ACCEPT_CONTENT = ['json']", "CELERY_TASK_SERIALIZER = 'json'" - these are the default settings since Celery 4 [6][7]. Finally, this removes a redundant (and broken) bit of development config - NOTIFICATION_QUEUE_PREFIX - that should be set in environment.sh [8]. [1]: https://docs.celeryproject.org/en/stable/history/whatsnew-4.0.html#lowercase-setting-names [2]: https://docs.celeryproject.org/en/stable/history/whatsnew-5.0.html#step-2-update-your-configuration-with-the-new-setting-names [3]: https://github.com/alphagov/notifications-govuk-alerts/blob/252ad01d3934e5d75aabbee92badbf38a009046a/app/config.py#L27 [4]: https://github.com/alphagov/notifications-template-preview/blob/03df0d92522f13091b081f3fe04c188e85d2ade6/app/__init__.py#L33 [5]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-enable_utc [6]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-task_serializer [7]: https://docs.celeryproject.org/en/stable/userguide/configuration.html#std-setting-accept_content [8]: https://github.com/alphagov/notifications-api/blob/2edbdec4eeaee4a937ece1a98000bd439624c0e0/README.md#environmentsh
2021-10-26 16:36:25 +01:00
}
2016-07-04 16:54:03 +01:00
2022-10-31 13:25:59 -04:00
class Production(Config):
2022-07-25 15:19:05 -07:00
# buckets
2022-10-31 15:37:12 -04:00
CSV_UPLOAD_BUCKET = cloud_config.s3_credentials(
2023-08-29 14:54:30 -07:00
f"notify-api-csv-upload-bucket-{Config.NOTIFY_ENVIRONMENT}"
)
2023-12-12 15:55:45 -08:00
FROM_NUMBER = "Notify.gov"
2022-06-29 08:47:36 -07:00
2022-10-31 13:25:59 -04:00
class Staging(Production):
2016-12-08 12:12:45 +00:00
pass
2022-11-02 12:02:21 -04:00
2022-11-02 09:09:16 -04:00
class Demo(Production):
pass
2016-12-08 12:12:45 +00:00
2022-11-02 12:02:21 -04:00
configs = {
2023-08-29 14:54:30 -07:00
"development": Development,
"test": Test,
"staging": Staging,
"demo": Demo,
"sandbox": Staging,
"production": Production,
}