-
Notifications
You must be signed in to change notification settings - Fork 8
Alert-system: Email setup #2638
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
base: project/alert-system-workflow
Are you sure you want to change the base?
Alert-system: Email setup #2638
Conversation
…ix notification tests
|
|
||
|
|
||
| @shared_task() | ||
| def process_email_alert(load_item_id: int) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might need a separate Queue for the alert notification..
alert_system/utils.py
Outdated
|
|
||
| def get_alert_subscriptions(load_item: LoadItem): | ||
|
|
||
| regions = Country.objects.filter(iso3__in=load_item.country_codes).values_list("region_id", flat=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| regions = Country.objects.filter(iso3__in=load_item.country_codes).values_list("region_id", flat=True) | |
| region_ids = Country.objects.filter(iso3__in=load_item.country_codes).values_list("region_id", flat=True) |
alert_system/tasks.py
Outdated
| logger.warning(f"LoadItem with ID [{load_item_id}] not found") | ||
| return | ||
|
|
||
| subscriptions = get_alert_subscriptions(load_item) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| subscriptions = get_alert_subscriptions(load_item) | |
| subscriptions = list(get_alert_subscriptions(load_item)) |
| created_at = models.DateTimeField(auto_now_add=True, verbose_name=_("Created At")) | ||
| updated_at = models.DateTimeField(auto_now=True, verbose_name=_("Updated At")) | ||
| # Typing | ||
| id: int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| id: int | |
| user_id: int | |
| ) | ||
|
|
||
| created_at = models.DateTimeField(auto_now_add=True) | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| # TYPING | |
| user_id: int |
alert_system/tasks.py
Outdated
| threads_qs = AlertEmailThread.objects.filter( | ||
| correlation_id=load_item.correlation_id, | ||
| user_id__in=user_ids, | ||
| ).select_related("user") | ||
|
|
||
| existing_threads = {thread.user.id: thread for thread in threads_qs} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| threads_qs = AlertEmailThread.objects.filter( | |
| correlation_id=load_item.correlation_id, | |
| user_id__in=user_ids, | |
| ).select_related("user") | |
| existing_threads = {thread.user.id: thread for thread in threads_qs} | |
| existing_threads = { | |
| thread.user_id: thread | |
| for thread in AlertEmailThread.objects.filter( | |
| correlation_id=load_item.correlation_id, | |
| user_id__in=user_ids, | |
| ) | |
| } | |
alert_system/tasks.py
Outdated
|
|
||
| today = timezone.now().date() | ||
| subscriptions_list = list(subscriptions) | ||
| user_ids = [sub.user.id for sub in subscriptions_list] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| user_ids = [sub.user.id for sub in subscriptions_list] | |
| user_ids = [sub.user_id for sub in subscriptions_list] |
| verbose_name=_("Email Thread"), | ||
| ) | ||
|
|
||
| id: int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| id: int | |
| id: int | |
| user_id: int |
deploy/helm/ifrcgo-helm/values.yaml
Outdated
| # - command: 'poll_gdacs_cyclone' | ||
| # schedule: '0 0 * * 0' | ||
| - command: 'poll_gdacs_flood' | ||
| schedule: '0 0 * * 0' | ||
| - command: 'poll_usgs_earthquake' | ||
| schedule: '0 0 * * 0' | ||
| # - command: 'notify_validators' | ||
| # schedule: '0 0 * * *' | ||
| schedule: '15 9 * * *' | ||
| # - command: 'poll_usgs_earthquake' | ||
| # schedule: '0 0 * * 0' | ||
| - command: 'alert_notification' | ||
| schedule: '0 */2 * * *' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we commenting this for local use? If yes, please make it how it should be.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commenting out because this will flood database (we are just running the poll_gdacs_flood for now)
main/sentry.py
Outdated
| # POLL_USGS_EARTHQUAKE = "poll_usgs_earthquake", "0 0 * * 0" | ||
| POLL_GDACS_FLOOD = "poll_gdacs_flood", "15 9 * * *" | ||
| # POLL_GDACS_CYCLONE = "poll_gdacs_cyclone", "0 0 * * 0" | ||
| OAUTH_CLEARTOKENS = "oauth_cleartokens", "0 1 * * *" | ||
| ALERT_NOTIFICATION = "alert_notification", "0 */2 * * *" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
- Add new ALERT celery queue - Route process_email_alert task to ALERT queue
Changes
Checklist
Things that should succeed before merging.
Release
If there is a version update, make sure to tag the repository with the latest version.