Skip to content

Conversation

@sudip-khanal
Copy link
Contributor

@sudip-khanal sudip-khanal commented Jan 22, 2026

Changes

  • Add reply functionality to the base alert email notification
  • Set up the email notification for alert system

Checklist

Things that should succeed before merging.

  • Updated/ran unit tests
  • Updated CHANGELOG.md

Release

If there is a version update, make sure to tag the repository with the latest version.

@sudip-khanal sudip-khanal mentioned this pull request Jan 22, 2026
2 tasks
@sudip-khanal sudip-khanal changed the title Feat/setup email notification on alert system Alert-system: Email setup Jan 22, 2026


@shared_task()
def process_email_alert(load_item_id: int) -> None:
Copy link
Member

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..


def get_alert_subscriptions(load_item: LoadItem):

regions = Country.objects.filter(iso3__in=load_item.country_codes).values_list("region_id", flat=True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)

logger.warning(f"LoadItem with ID [{load_item_id}] not found")
return

subscriptions = get_alert_subscriptions(load_item)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
id: int
user_id: int

)

created_at = models.DateTimeField(auto_now_add=True)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# TYPING
user_id: int

Comment on lines 222 to 227
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}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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,
)
}


today = timezone.now().date()
subscriptions_list = list(subscriptions)
user_ids = [sub.user.id for sub in subscriptions_list]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
id: int
id: int
user_id: int

Comment on lines 280 to 287
# - 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 * * *'
Copy link
Member

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.

Copy link
Contributor Author

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
Comment on lines 132 to 136
# 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 * * *"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants