-
Notifications
You must be signed in to change notification settings - Fork 7
Feat/alert system #2599
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?
Feat/alert system #2599
Conversation
- Nested extraction with correlation id as fliter. - Self retry with exponential backoff. - Different models for Hazards and Impacts.
This commit splits the data extraction, transform and load part. The filtration part is also included in the load part.
3fa8ab2 to
9fd5372
Compare
susilnem
left a comment
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.
Minor changes...
susilnem
left a comment
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.
Small changes!
sudip-khanal
left a comment
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.
Minor changes
susilnem
left a comment
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.
Do we have any analytics on usage and memory consumption?
Has any profiling been done so far?
| return | ||
|
|
||
| try: | ||
| eligible_items = LoadItem.objects.filter( |
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.
| eligible_items = LoadItem.objects.filter( | |
| eligible_items_qs = LoadItem.objects.filter( |
| count = eligible_items.count() | ||
|
|
||
| if count == 0: | ||
| logger.info(f"[Past Events] No eligible items in run {extraction_run_id}") | ||
| return | ||
|
|
||
| logger.info(f"[Past Events] Processing {count} items from run {extraction_run_id}") | ||
|
|
||
| first_item = eligible_items.first() | ||
| if not first_item: | ||
| logger.info("No Connector found for the Event") | ||
| return |
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.
These are almost same checks.
| processed += 1 | ||
| except Exception as e: | ||
| failed += 1 | ||
| logger.error(f"[Past Events] Failed for item {load_obj.id} in run {extraction_run_id}: {e}", exc_info=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.
| logger.error(f"[Past Events] Failed for item {load_obj.id} in run {extraction_run_id}: {e}", exc_info=True) | |
| logger.warning(f"[Past Events] Failed for item {load_obj.id} in run {extraction_run_id}") |
|
|
||
| logger.info(f"[Past Events] Completed run {extraction_run_id}: " f"{processed} processed, {failed} failed") | ||
|
|
||
| return {"extraction_run_id": extraction_run_id, "processed": processed, "failed": failed, "total": count} |
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.
Add a type dict for returning dict value
| go_event_ids = list( | ||
| Event.objects.filter(field_reports__num_affected__gte=item.total_people_exposed, dtype=connector.dtype) | ||
| .values_list("id", flat=True) | ||
| .distinct() | ||
| ) |
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.
N+1
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.
N+M+1
| .distinct() | ||
| ) | ||
|
|
||
| item.related_go_events = go_event_ids |
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.
Check if we have instead use M2M
Use bulk insert to add M2M (Use ignore existing)
| return extraction_run_id | ||
|
|
||
| except Exception as exc: | ||
| logger.exception(f"[ETL] Connector {connector.id} failed: {exc}") |
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.
| logger.exception(f"[ETL] Connector {connector.id} failed: {exc}") | |
| logger.warning(f"[ETL] Connector {connector.id} failed", exc_info=True) |
| try: | ||
| raise self.retry(exc=exc) | ||
| except MaxRetriesExceededError: | ||
| logger.error(f"[ETL] Max retries exceeded for connector {connector.id}", exc_info=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.
| logger.error(f"[ETL] Max retries exceeded for connector {connector.id}", exc_info=True) | |
| logger.error(f"[ETL] Max retries exceeded for connector {connector.label}", exc_info=True) |
| help_text=_("Unique identifier for the event item"), | ||
| ) | ||
|
|
||
| resp_data = models.JSONField( |
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.
Add a
XXX: This might increase the database size
| SOURCE_TYPE = Connector.ConnectorType.USGS_EARTHQUAKE | ||
|
|
||
| def handle(self, *args, **options): | ||
| if not self.SOURCE_TYPE: |
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.
| if not self.SOURCE_TYPE: |
| ) | ||
|
|
||
| action = "Created" if created else "Updated" | ||
| logger.info(f"{action} Event for correlation_id={correlation_id}") |
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.
| logger.info(f"{action} Event for correlation_id={correlation_id}") | |
| logger.info(f"{action} Event for {correlation_id=}") |
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.
alert_system/etl/Gdacs_flood/extraction.py
alert_system/etl/gdacs_flood/extraction.py
| ISO 8601 datetime range string | ||
| """ | ||
|
|
||
| now = datetime.now(timezone.utc) |
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.
| now = datetime.now(timezone.utc) | |
| from django.utils import timezone | |
| ... | |
| now = timezeone.now() |
| event_collection_type = gdacs_flood_config.event_collection_type | ||
| hazard_collection_type = getattr(gdacs_flood_config, "hazard_collection_type", None) | ||
| impact_collection_type = getattr(gdacs_flood_config, "impact_collection_type", None) | ||
| filter_event = getattr(gdacs_flood_config, "filter_event", None) | ||
| transformer_class = GdacsTransformer | ||
| loader_class = GdacsLoader |
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 can replace all this with a single typed dict...
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.