-
Notifications
You must be signed in to change notification settings - Fork 13
refactor: organize the Sources in different files for easier development #339
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
Open
chadell
wants to merge
12
commits into
develop
Choose a base branch
from
refactor-source-notifications
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
9a0f1e5
refactor: organize the Sources in different files for easier development
chadell db0a14c
Merge remote-tracking branch 'origin/develop' into refactor-source-no…
chadell 4342d7f
changes doc
chadell 6b4b2c0
add point
chadell bd568f9
change suffix
chadell d63119e
pylint fixes
chadell a01a4f4
Update nautobot_circuit_maintenance/handle_notifications/sources/emai…
20bd0d4
a bit more refactor, but still getting the cyclic import warning desp…
chadell 3c29285
Merge branch 'refactor-source-notifications' of github.com:nautobot/n…
chadell 21b4dae
Refactored to pass tests.
jvanderaa e62f7c1
Merge branch 'develop' into refactor-source-notifications
jvanderaa 853875b
Update for tests.
jvanderaa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Refactor `Sources.py` into a `sources` module with different files. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,12 @@ | |
| import uuid | ||
| from typing import List, Optional | ||
|
|
||
| from circuit_maintenance_parser import Maintenance, NotificationData, ProviderError, init_provider | ||
| from circuit_maintenance_parser import ( | ||
| Maintenance, | ||
| NotificationData, | ||
| ProviderError, | ||
| init_provider, | ||
| ) | ||
| from dateutil import parser | ||
| from django.conf import settings | ||
| from django.core.exceptions import ObjectDoesNotExist | ||
|
|
@@ -28,7 +33,8 @@ | |
| RawNotification, | ||
| ) | ||
|
|
||
| from .sources import MaintenanceNotification, get_notifications | ||
| from .sources import get_notifications | ||
| from .sources.maintenance_notification import MaintenanceNotification | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we make this importable from |
||
|
|
||
| name = "Circuit Maintenance" # pylint: disable=invalid-name | ||
|
|
||
|
|
@@ -62,7 +68,9 @@ def create_circuit_maintenance( | |
| circuit_entry = Circuit.objects.filter(cid__iexact=circuit.circuit_id, provider=provider).last() | ||
| if circuit_entry: | ||
| circuit_impact_entry, created = CircuitImpact.objects.get_or_create( | ||
| maintenance=circuit_maintenance_entry, circuit=circuit_entry, defaults={"impact": circuit.impact} | ||
| maintenance=circuit_maintenance_entry, | ||
| circuit=circuit_entry, | ||
| defaults={"impact": circuit.impact}, | ||
| ) | ||
| if created: | ||
| job.logger.info( | ||
|
|
@@ -88,7 +96,8 @@ def create_circuit_maintenance( | |
|
|
||
| if not CircuitImpact.objects.filter(maintenance=circuit_maintenance_entry): | ||
| job.logger.warning( | ||
| "Circuit Maintenance has none Circuit IDs in the DB.", extra={"object": circuit_maintenance_entry} | ||
| "Circuit Maintenance has none Circuit IDs in the DB.", | ||
| extra={"object": circuit_maintenance_entry}, | ||
| ) | ||
|
|
||
| return circuit_maintenance_entry | ||
|
|
@@ -233,7 +242,8 @@ def get_maintenances_from_notification(job: Job, notification: MaintenanceNotifi | |
| parser_provider = init_provider(provider_type=provider_type) | ||
| if not parser_provider: | ||
| job.logger.warning( | ||
| f"Notification Parser not found for {notification.provider_type}", extra={"object": notification} | ||
| f"Notification Parser not found for {notification.provider_type}", | ||
| extra={"object": notification}, | ||
| ) | ||
| notification.source.tag_message(job, notification.msg_id, MessageProcessingStatus.PARSING_FAILED) | ||
| return None | ||
|
|
@@ -291,7 +301,10 @@ def create_raw_notification( | |
| stamp=parser.parse(notification.date), | ||
| ) | ||
| # If the RawNotification was already created, we ignore it. | ||
| job.logger.debug(f"Raw notification already existed with ID: {raw_entry.id}", extra={"object": raw_entry}) | ||
| job.logger.debug( | ||
| f"Raw notification already existed with ID: {raw_entry.id}", | ||
| extra={"object": raw_entry}, | ||
| ) | ||
| return None | ||
| except ObjectDoesNotExist: | ||
| try: | ||
|
|
@@ -384,7 +397,10 @@ def get_since_reference(job: Job) -> int: | |
| days=PLUGIN_SETTINGS.get("raw_notification_initial_days_since") | ||
| ) | ||
| since_reference = int(since_reference.timestamp()) | ||
| job.logger.info(f"Processing notifications since {since_reference}", extra={"object": last_raw_notification}) | ||
| job.logger.info( | ||
| f"Processing notifications since {since_reference}", | ||
| extra={"object": last_raw_notification}, | ||
| ) | ||
| return since_reference | ||
|
|
||
|
|
||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Was this not working properly?