Skip to content

fix(cron): add pending-jobs check to cron#882

Merged
vprashrex merged 5 commits into
mainfrom
fix/invoke-cron-add-pending-jobs-endpoint
May 26, 2026
Merged

fix(cron): add pending-jobs check to cron#882
vprashrex merged 5 commits into
mainfrom
fix/invoke-cron-add-pending-jobs-endpoint

Conversation

@vprashrex
Copy link
Copy Markdown
Collaborator

@vprashrex vprashrex commented May 23, 2026

Target issue is #881

Summary

In the previous PR that added pending job monitoring, the invoke-cron.py script was modified locally but the changes were never pushed/included in the PR. The server-side implementation existed, but since the updated script wasn't shipped, the cron script was never calling /api/v1/cron/pending-jobs — so pending job monitoring was never actually running. This PR ships that missing change.

Checklist

Before submitting a pull request, please ensure that you mark these task.

  • Ran fastapi run --reload app/main.py or docker compose up in the repository root and test.
  • If you've fixed a bug or added code that is tested and has test cases.

Summary by CodeRabbit

Release Notes

  • New Features

    • Cron scheduler now supports invoking multiple API endpoints in sequence, enabling more comprehensive background job processing.
  • Improvements

    • Enhanced error handling with per-endpoint authentication retry on authorization failures.
    • Improved logging with detailed endpoint-specific success/failure reporting for better monitoring visibility.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 23, 2026

Warning

Review limit reached

@vprashrex, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 54 minutes and 42 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 7b099ecc-2be8-48cf-8f7e-97e55dc77dce

📥 Commits

Reviewing files that changed from the base of the PR and between 22509c4 and 591d9ab.

📒 Files selected for processing (1)
  • scripts/python/invoke-cron.py
📝 Walkthrough

Walkthrough

The cron invocation script now supports multiple endpoints via an ENDPOINTS list. EndpointInvoker stores the list and invoke_endpoint accepts an endpoint argument to build requests and retry once on 401/403. The run loop iterates each configured endpoint per cycle and logs per-endpoint successes or failures.

Changes

Multi-endpoint cron invocation

Layer / File(s) Summary
Endpoint configuration and invoker init
scripts/python/invoke-cron.py
Replaces single ENDPOINT with ENDPOINTS list and stores it on EndpointInvoker during construction (range_f0697454a7d6, range_c51d92cf3d7c).
invoke_endpoint signature and retry
scripts/python/invoke-cron.py
invoke_endpoint now accepts endpoint: str, builds the request URL from that endpoint, and re-authenticates+retries the same endpoint once on 401/403; error logging updated to include endpoint context (range_747b6c40e8ee, range_cd8f6d170cd4).
Run loop and per-endpoint logging
scripts/python/invoke-cron.py
Startup logs report full endpoints list and interval; periodic loop iterates over self.endpoints, invoking each endpoint sequentially with per-endpoint try/except and per-endpoint success/failure logging (range_d0edcf687495, range_76aa7ae4eab6).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

  • Issue #881: Implements calling both /api/v1/cron/evaluations and /api/v1/cron/pending-jobs by replacing ENDPOINT with ENDPOINTS and parameterizing invoke_endpoint.

Possibly related PRs

Suggested labels

enhancement

Suggested reviewers

  • Prajna1999

Poem

🐇 I hop through endpoints, one by one,
A token in paw, until the job's done.
Evaluations, pending jobs in tow,
Sequential calls where the cronlights glow.
Hooray — the loop now knows where to go!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'fix(cron): add pending-jobs check to cron' accurately and concisely describes the main change: adding a pending-jobs endpoint invocation to the cron script alongside the existing evaluations endpoint.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/invoke-cron-add-pending-jobs-endpoint

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@vprashrex vprashrex self-assigned this May 23, 2026
@vprashrex vprashrex added bug Something isn't working ready-for-review labels May 23, 2026
@vprashrex vprashrex linked an issue May 23, 2026 that may be closed by this pull request
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@scripts/python/invoke-cron.py`:
- Around line 96-97: Update the log messages that currently read
logger.debug(f"Request URL: {self.base_url}{endpoint}") and
logger.debug(f"Request headers: {headers}") (and the other changed statements at
the same function: lines around 136–137, 147–151) to include the required
function-name prefix in square brackets; replace them with messages like
logger.debug(f"[<enclosing_function_name>] Request URL:
{self.base_url}{endpoint}") and logger.debug(f"[<enclosing_function_name>]
Request headers: {mask_string(headers)}") (substitute <enclosing_function_name>
with the actual name of the function/method that contains these logger calls and
mask any sensitive values using mask_string where appropriate). Ensure all four
affected logger calls use the same pattern and include the function name prefix.
- Around line 149-151: The loop over self.endpoints currently lets a raised
exception from invoke_endpoint abort the whole cycle; modify the for endpoint in
self.endpoints loop to wrap the await self.invoke_endpoint(client, endpoint)
call in a per-endpoint try/except so one failing endpoint does not stop others,
e.g. call invoke_endpoint inside try, on success log via
logger.info(f"[{endpoint}] invoked successfully: {result}"), and on except catch
the exception, log it with logger.error including endpoint and exception
details, then continue to the next endpoint; keep the outer exception handling
for cycle-level failures but ensure per-endpoint errors are handled locally.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 733966bd-f710-45eb-b363-4594ffe23dc5

📥 Commits

Reviewing files that changed from the base of the PR and between 5888b7e and a0a4b3c.

📒 Files selected for processing (1)
  • scripts/python/invoke-cron.py

Comment thread scripts/python/invoke-cron.py Outdated
Comment thread scripts/python/invoke-cron.py Outdated
@vprashrex vprashrex changed the title fix(cron): invoke pending-jobs endpoint alongside evaluations hotfix(cron): invoke pending-jobs endpoint alongside evaluations May 23, 2026
@sentry
Copy link
Copy Markdown

sentry Bot commented May 25, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@vprashrex vprashrex requested a review from AkhileshNegi May 26, 2026 01:53
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
scripts/python/invoke-cron.py (1)

152-156: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Add function-name prefix to per-endpoint run-loop logs.

These messages should include the enclosing function name (e.g., [run]) before endpoint context.

Suggested patch
-                            logger.info(f"[{endpoint}] invoked successfully: {result}")
+                            logger.info(
+                                f"[run] [{endpoint}] invoked successfully: {result}"
+                            )
                         except Exception as endpoint_error:
                             logger.error(
-                                f"[{endpoint}] invocation failed: {endpoint_error}"
+                                f"[run] [{endpoint}] invocation failed: {endpoint_error}"
                             )

As per coding guidelines, Prefix all log messages with the function name in square brackets: logger.info(f"[function_name] Message {mask_string(sensitive_value)}").

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/python/invoke-cron.py` around lines 152 - 156, The per-endpoint log
lines inside the run loop currently log only the endpoint; update the logger
calls in the try/except around the invocation (the logger.info and logger.error
shown) to prefix the message with the enclosing function name (e.g., "[run]")
before the endpoint context (so messages become "[run][{endpoint}] ..."). Locate
the try/except that catches endpoint_error in invoke-cron.py and change both
logger.info and logger.error formats to include the function name prefix while
keeping the existing endpoint and error text.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Duplicate comments:
In `@scripts/python/invoke-cron.py`:
- Around line 152-156: The per-endpoint log lines inside the run loop currently
log only the endpoint; update the logger calls in the try/except around the
invocation (the logger.info and logger.error shown) to prefix the message with
the enclosing function name (e.g., "[run]") before the endpoint context (so
messages become "[run][{endpoint}] ..."). Locate the try/except that catches
endpoint_error in invoke-cron.py and change both logger.info and logger.error
formats to include the function name prefix while keeping the existing endpoint
and error text.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f492e180-7e9d-46d1-9b53-58bc5b4381b1

📥 Commits

Reviewing files that changed from the base of the PR and between a0a4b3c and f5a5704.

📒 Files selected for processing (1)
  • scripts/python/invoke-cron.py

@vprashrex vprashrex changed the title hotfix(cron): invoke pending-jobs endpoint alongside evaluations fix(cron): add pending-jobs check to cron May 26, 2026
Comment thread scripts/python/invoke-cron.py Outdated
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
scripts/python/invoke-cron.py (1)

35-35: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Add return annotations to the touched methods.

Line 35 and Line 132 still omit -> None, which violates the repo-wide typing rule.

Proposed fix
-    def __init__(self):
+    def __init__(self) -> None:
...
-    async def run(self):
+    async def run(self) -> None:

As per coding guidelines, Always add type hints to all function parameters and return values in Python code.

Also applies to: 132-132

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/python/invoke-cron.py` at line 35, Add explicit return type
annotations "-> None" to the methods missing them in this file: update the
constructor "def __init__(self):" to "def __init__(self) -> None:" and also add
"-> None" to the other touched method declared at line 132 (the other function
in the diff). Ensure every function/method in this file has an explicit return
annotation per the repo typing rule.
🧹 Nitpick comments (1)
scripts/python/invoke-cron.py (1)

153-156: ⚡ Quick win

Keep the traceback on per-endpoint failures.

Lines 153-156 only log str(endpoint_error), so unexpected failures lose the stack trace. Add exc_info=True here or switch to logger.exception(...).

Proposed fix
                         except Exception as endpoint_error:
                             logger.error(
-                                f"[{endpoint}] invocation failed: {endpoint_error}"
+                                f"[{endpoint}] invocation failed: {endpoint_error}",
+                                exc_info=True,
                             )
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/python/invoke-cron.py` around lines 153 - 156, The except block that
catches Exception as endpoint_error currently calls logger.error(f"[{endpoint}]
invocation failed: {endpoint_error}") which drops the traceback; change this to
include the exception info by either using logger.exception(f"[{endpoint}]
invocation failed") or calling logger.error(f"[{endpoint}] invocation failed:
{endpoint_error}", exc_info=True) so the stack trace for endpoint_error is
preserved (references: exception variable endpoint_error, logger.error currently
used, and the endpoint variable in the message).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@scripts/python/invoke-cron.py`:
- Line 35: Add explicit return type annotations "-> None" to the methods missing
them in this file: update the constructor "def __init__(self):" to "def
__init__(self) -> None:" and also add "-> None" to the other touched method
declared at line 132 (the other function in the diff). Ensure every
function/method in this file has an explicit return annotation per the repo
typing rule.

---

Nitpick comments:
In `@scripts/python/invoke-cron.py`:
- Around line 153-156: The except block that catches Exception as endpoint_error
currently calls logger.error(f"[{endpoint}] invocation failed:
{endpoint_error}") which drops the traceback; change this to include the
exception info by either using logger.exception(f"[{endpoint}] invocation
failed") or calling logger.error(f"[{endpoint}] invocation failed:
{endpoint_error}", exc_info=True) so the stack trace for endpoint_error is
preserved (references: exception variable endpoint_error, logger.error currently
used, and the endpoint variable in the message).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: c7501130-068b-47ca-8c1e-27599ad8d43d

📥 Commits

Reviewing files that changed from the base of the PR and between f5a5704 and 22509c4.

📒 Files selected for processing (1)
  • scripts/python/invoke-cron.py

@vprashrex vprashrex requested review from Prajna1999 and removed request for Prajna1999 May 26, 2026 08:31
@vprashrex vprashrex merged commit 78597ff into main May 26, 2026
3 checks passed
@vprashrex vprashrex deleted the fix/invoke-cron-add-pending-jobs-endpoint branch May 26, 2026 08:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working ready-for-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Invoke Cron: Add pending jobs check

2 participants