Skip to content

Add configurable lookback window to the Handle Notifications job (#170) - #392

Open
jvanderaa wants to merge 2 commits into
developfrom
170-configurable-lookback
Open

Add configurable lookback window to the Handle Notifications job (#170)#392
jvanderaa wants to merge 2 commits into
developfrom
170-configurable-lookback

Conversation

@jvanderaa

Copy link
Copy Markdown
Collaborator

Closes: #170

What's Changed

Adds two optional inputs to the Update Circuit Maintenances job so operators can re-fetch older notifications on demand, instead of always being limited to the normal incremental window (the timestamp of the last stored notification, or raw_notification_initial_days_since on the first run).

  • Days to look back (IntegerVar) — fetch notifications from the last N days (now - N days).
  • Fetch notifications since (StringVar, ISO 8601 date/time, e.g. 2026-01-31 or 2026-01-31T00:00:00Z) — fetch notifications on or after that instant; assumed UTC when no timezone is given.

Either input overrides the normal watermark. When both are set, the earliest start time wins ("look back at least this far"). Leave both blank for normal incremental processing. An unparseable Fetch notifications since value fails the job with a clear error rather than silently doing nothing.

Note: Nautobot's job framework has no DateTimeVar (vars are String/Text/Integer/Boolean/Choice/Object/File/IP/JSON), so the absolute datetime input is a StringVar parsed with dateutil and normalized to UTC.

Re-processing already-stored notifications

A lookback window widens the range of notifications the job fetches, but RawNotification records are deduplicated by (subject, provider, stamp), so an already-stored notification is skipped even inside the window. To re-parse notifications that were stored but failed to parse (e.g. after upgrading circuit-maintenance-parser), delete their RawNotification records first, then run the job with a lookback that covers them. This is documented in the user guide.

Screenshots

Not applicable — this adds standard Nautobot-rendered inputs to an existing Job form (no custom UI).

Testing

  • Added tests for get_since_reference (days override, datetime override, both → earliest, first-run default) and for the job failing on an invalid fetch_since value; updated the existing watermark test for the int return type.
  • test_handler (28) and test_jobs (4) pass; ruff lint + format clean; docs build (mkdocs strict) passes; no missing migrations.

Docs

  • docs/user/app_use_cases.md — new "Re-fetching older notifications (lookback window)" section documenting both inputs and the delete-then-reprocess workflow.

Adds two optional job inputs, 'Days to look back' (IntegerVar) and
'Fetch notifications since' (StringVar, ISO 8601), that override the normal
incremental fetch window so operators can re-fetch older notifications on
demand. When both are set the earliest start time wins. Nautobot has no
DateTimeVar, so the datetime input is a validated string parsed with
dateutil. Documents the feature and the delete-then-reprocess workflow for
already-stored notifications.

Closes #170
Collect override candidates as datetimes and convert to a timestamp once
via min(), removing the duplicated int(...timestamp()) calls. Raise a clear
error on an unparseable 'Fetch notifications since' value instead of
returning an empty result, so the Job Result reflects the failure.
@github-actions

Copy link
Copy Markdown

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  nautobot_circuit_maintenance/handle_notifications
  handler.py 462-463
Project Total  

This report was generated by python-coverage-comment-action

@glennmatthews glennmatthews left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks reasonable to me.

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.

Configurable lookback window

2 participants