Skip to content

Conversation

@arikalon1
Copy link
Contributor

…on expression

@arikalon1 arikalon1 requested a review from Sheeproid October 26, 2025 07:04
@coderabbitai
Copy link

coderabbitai bot commented Oct 26, 2025

Walkthrough

Initial-delay logic in the scheduler was tightened: cron-based schedules (CronScheduleRepeat) no longer receive the initial schedule delay. For non-cron triggers, NEW jobs get the initial delay — DynamicDelayRepeat returns its first delayPeriod; other non-cron types use INITIAL_SCHEDULE_DELAY_SEC. Subsequent delay branches unchanged.

Changes

Cohort / File(s) Change Summary
Scheduler delay calculation logic
src/robusta/core/schedule/scheduler.py
Updated __calc_job_delay_for_next_run to apply the initial delay only when scheduling_params is not CronScheduleRepeat and job.status is NEW. DynamicDelayRepeat returns its first delayPeriod; other non-cron types use INITIAL_SCHEDULE_DELAY_SEC. Existing branches for DynamicDelayRepeat, CronScheduleRepeat, and FIXED_DELAY_REPEAT for subsequent delays remain unchanged.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant Scheduler
    participant Job
    participant ScheduleParams

    Note over Scheduler,ScheduleParams: New or subsequent run decision
    Scheduler->>Job: inspect status
    Scheduler->>ScheduleParams: inspect type

    alt scheduling_params is CronScheduleRepeat
        Scheduler->>Scheduler: compute next_delay via cron logic
    else scheduling_params is DynamicDelayRepeat and Job.status == NEW
        Scheduler->>Scheduler: return first delayPeriod
    else scheduling_params not Cron and Job.status == NEW
        Scheduler->>Scheduler: return INITIAL_SCHEDULE_DELAY_SEC
    else
        Scheduler->>Scheduler: compute subsequent delay (dynamic/fixed) and apply max-time adjustment
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

  • Verify correct type-check for CronScheduleRepeat and that DynamicDelayRepeat first-delay handling is preserved.
  • Confirm initial-delay condition only triggers for job.status == NEW.
  • Check edge cases around job status transitions and max-time adjustment logic.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Description Check ❓ Inconclusive The pull request description provided is severely truncated, showing only "…on expression" which appears to be a fragment of the title rather than a meaningful description. While this fragment is tangentially related to the PR's subject (cron expressions), it lacks any substantive information about the problem being addressed, the solution implemented, or why this change is necessary. The description is too incomplete and vague to meaningfully convey information about the changeset, making it impossible to confirm whether it adequately describes the modifications.
✅ Passed checks (1 passed)
Check name Status Explanation
Title Check ✅ Passed The pull request title "Fix the scheduler delay for new jobs, when the trigger is based on cron expression" directly aligns with the main change in the pull request. The raw summary shows modifications to __calc_job_delay_for_next_run that specifically address how initial delays are applied for different trigger types, including CronScheduleRepeat. The title is concise, specific about the problem (scheduler delay for new jobs with cron triggers), and clearly communicates the primary change without unnecessary noise.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch cron-schedule-first-delay

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f3c8807 and 7c16389.

📒 Files selected for processing (1)
  • src/robusta/core/schedule/scheduler.py (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/robusta/core/schedule/scheduler.py (1)
src/robusta/core/schedule/model.py (3)
  • CronScheduleRepeat (25-26)
  • JobStatus (7-10)
  • DynamicDelayRepeat (21-22)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: run_tests
  • GitHub Check: run_tests
🔇 Additional comments (1)
src/robusta/core/schedule/scheduler.py (1)

135-135: Typo in comment has been fixed.

The previous review comment flagged "non-dron" as a typo. The comment now correctly reads "non-cron".


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.

Copy link

@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

Caution

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

⚠️ Outside diff range comments (1)
src/robusta/core/schedule/scheduler.py (1)

134-154: The initialization issue is confirmed: last_exec_time_sec starts at 0 for NEW jobs.

For NEW jobs with Cron scheduling, the code falls through to the calculation logic where last_exec_time_sec = 0 causes the formula 0 + next_delay - round(time.time()) to produce a large negative number. The max() call then returns INITIAL_SCHEDULE_DELAY_SEC, which masks the semantic error. NEW Cron jobs should return early with INITIAL_SCHEDULE_DELAY_SEC (like non-Cron NEW jobs do) rather than relying on this side-effect.

The fix is to extend the early return check to include CronScheduleRepeat:

if job.state.job_status == JobStatus.NEW:
    if isinstance(job.scheduling_params, DynamicDelayRepeat):
        return job.scheduling_params.delay_periods[0]
    else:
        return INITIAL_SCHEDULE_DELAY_SEC
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 471f567 and f3c8807.

📒 Files selected for processing (1)
  • src/robusta/core/schedule/scheduler.py (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/robusta/core/schedule/scheduler.py (1)
src/robusta/core/schedule/model.py (3)
  • CronScheduleRepeat (25-26)
  • JobStatus (7-10)
  • DynamicDelayRepeat (21-22)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: run_tests
  • GitHub Check: run_tests
  • GitHub Check: Deploy docs

Sheeproid
Sheeproid previously approved these changes Oct 26, 2025
@arikalon1 arikalon1 merged commit c4ce007 into master Oct 26, 2025
7 of 8 checks passed
@arikalon1 arikalon1 deleted the cron-schedule-first-delay branch October 26, 2025 07:57
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