The scheduler
Last updated on
OPX.Scheduler.Every is how a module runs repeating work on the server and on the client, and the two implementations behave differently.
Use OPX.Scheduler for repeating work instead of CreateThread(function() while true do ... Wait(n) end end). Same four functions on both sides, implemented differently because the two runtimes fail differently.
local handle = OPX.Scheduler.Every('mymodule.sweep', 1000, function()
-- runs about once a second
end)
OPX.Scheduler.Cancel(handle) -- in M.Stop| Function | Server | Client |
|---|---|---|
Every(name, intervalMs, step) | One managed task per job. intervalMs is a number or a function re-read every pass (to follow a live tunable). | One shared loop for every job. intervalMs must be a number; a function raises. 0 = every pass. |
Cancel(handle) | Stops the job. | Stops the job; it is dropped at the next pass. |
Report() | One line per job. | One line per job: name, interval, running/stopped. |
Stop() | Stops every job (resource stop). | Stops the loop (resource stop). |
name only appears in log lines; write it as <module>.<purpose>.
Server behaviour
| Rule | Value |
|---|---|
| First run | One interval after registration, never at once. |
| Smallest interval | 50 ms. A smaller value is raised to 50. |
| Interval that cannot be read | Runs at its last good interval, or every 60 s, and logs once. |
| A step that raises | Logged once per run of failures. The job is never suspended. |
Client behaviour
| Rule | Value |
|---|---|
| Jobs per pass | At most 4 due jobs per resume, in rotation, so none starves. |
| First run | Staggered, so jobs on the same interval do not land on the same frame. |
| A step that raises | Logged on the first and third failure. After 3 failures in a row the job is suspended (cancelled): [scheduler] <name> suspended after 3 failures. |
| Idle | The loop sleeps at most 100 ms between passes. |
The client loop starts after every module's Start (OPX.Scheduler.Start). /opx.client in the client console prints the job list.
Keep each client step small
All client jobs share the loop. A step that walks a long list every frame can exceed the client's instruction budget, and the platform then kills the coroutine without any log line. Spread long work over several passes (Two runtimes).
Events and channels
The three event prefixes opx_infinity uses (opx:net, opx:on, opx:in), who can hear each one, and how to build a name with OPX.Event.
Server authority
The server decides; a client only asks. How opx_infinity treats network events, staff powers, money and positions so that a modified client cannot cheat.