Skip to content

Conversation

@DyroS3
Copy link
Contributor

@DyroS3 DyroS3 commented Sep 1, 2025

fix(cron): resolve task execution conflicts and timing precision issues

Description

Fixed critical bugs in cron system causing scheduled tasks to fail after server restarts.


Motivation

When servers restarted before scheduled task times (e.g., server restarts at 19:10, task scheduled for 19:20), cron jobs would not execute. This affected resources like okokDeleteVehicles that depend on scheduled cleanup tasks.

Root Causes:

  1. Task execution conflicts - All jobs shared a single lastTimestamp, causing interference
  2. Timing precision issues - Fixed 60-second intervals caused timing drift and missed windows

Implementation Details

Per-task execution tracking:

  • Added individual lastRun timestamp for each cron job
  • Replaced shared global timestamp with job-specific tracking
  • Each task maintains independent execution state

Precision minute-boundary timing:

  • Dynamic timeout calculation to next minute boundary
  • Eliminated fixed intervals that caused cumulative drift
  • Tasks now execute at exact minute transitions (XX:XX:00)

Enhanced validation:

  • Added time range checks (hour 0-23, minute 0-59)
  • Improved error messages with resource identification

Usage Example

-- Usage remains the same - no breaking changes
TriggerEvent('cron:runAt', 19, 20, function()
    print("Task executed at 19:20")
end)

-- Multiple tasks now work independently
TriggerEvent('cron:runAt', 0, 59, DeleteVehTaskCoroutine)  -- Midnight cleanup
TriggerEvent('cron:runAt', 12, 0, NoonTaskCoroutine)      -- Noon task

PR Checklist

  • My commit messages and PR title follow the Conventional Commits standard.
  • My changes have been tested locally and function as expected.
  • My PR does not introduce any breaking changes.
  • I have provided a clear explanation of what my PR does, including the reasoning behind the changes and any relevant context.

Kenshiin13 and others added 30 commits August 24, 2025 17:20
Apparently, passing leading nil values via an export breaks it entirely.
…ment-isValid-on-register-command

add a new argument on the register command feature
feat(esx_menu_default) Redesign of the menu.
fix(esx_menu_default): remove debug print
feat(esx_menu_dialog) Updates the UI of esx_menu_dialog to match esx_menu_default
Fixed critical bugs in cron system causing scheduled tasks to fail after server restarts.
@DyroS3
Copy link
Contributor Author

DyroS3 commented Sep 1, 2025

This submission is intended to resolve this issue. #1294

Copy link
Member

@Kr3mu Kr3mu left a comment

Choose a reason for hiding this comment

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

lgtm, but I'll test it when I get home and if everything is alright I'll approve it.

@Kr3mu
Copy link
Member

Kr3mu commented Sep 2, 2025

Hey, reviewed your code once again when I came back from school, looks good to me. I like what you did, but I'll told kenshin to also verify this change. Thanks for opening the PR.

@CLAassistant
Copy link

CLAassistant commented Nov 16, 2025

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
2 out of 4 committers have signed the CLA.

✅ Kenshiin13
✅ DyroS3
❌ github-actions[bot]
❌ Kr3mu
You have signed the CLA already but the status is still pending? Let us recheck it.

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.

4 participants