Packages
game_server_sdk
1.0.1063
1.0.1082
1.0.1079
1.0.1078
1.0.1077
1.0.1076
1.0.1075
1.0.1074
1.0.1073
1.0.1070
1.0.1068
1.0.1067
1.0.1063
1.0.1059
1.0.1058
1.0.1057
1.0.1056
1.0.1055
1.0.1050
1.0.1049
1.0.1048
1.0.1047
1.0.1046
1.0.1044
1.0.1043
1.0.1042
1.0.1041
1.0.1040
1.0.1039
1.0.1038
1.0.1034
1.0.1033
1.0.1029
1.0.1028
1.0.1026
1.0.1025
1.0.1024
1.0.1023
1.0.1022
1.0.1021
1.0.1020
1.0.1019
1.0.1018
1.0.1017
1.0.1016
1.0.1015
1.0.1014
1.0.1013
1.0.1012
1.0.1011
1.0.1009
1.0.1008
1.0.1007
1.0.1006
1.0.1005
1.0.1004
1.0.1003
1.0.1001
1.0.999
1.0.998
1.0.997
1.0.996
1.0.995
1.0.994
1.0.993
1.0.992
1.0.991
1.0.990
1.0.989
1.0.988
1.0.987
1.0.986
1.0.985
1.0.984
1.0.983
1.0.982
1.0.981
1.0.980
1.0.979
1.0.978
1.0.977
1.0.976
1.0.975
1.0.974
1.0.973
1.0.972
1.0.971
1.0.970
1.0.969
1.0.968
1.0.967
1.0.966
1.0.965
1.0.964
1.0.963
1.0.962
1.0.961
1.0.959
1.0.958
1.0.956
1.0.951
1.0.950
1.0.943
1.0.942
1.0.941
1.0.940
1.0.938
1.0.936
1.0.935
1.0.931
1.0.929
1.0.928
1.0.927
1.0.926
1.0.925
1.0.924
1.0.923
1.0.921
1.0.920
1.0.919
1.0.918
1.0.917
1.0.916
1.0.911
1.0.910
1.0.902
1.0.899
1.0.898
1.0.897
1.0.896
1.0.894
1.0.893
1.0.891
1.0.890
1.0.889
1.0.888
1.0.887
1.0.886
1.0.885
1.0.884
1.0.883
1.0.882
1.0.881
1.0.880
1.0.879
1.0.878
1.0.877
1.0.26
1.0.25
1.0.22
1.0.21
1.0.20
1.0.19
1.0.15
1.0.14
1.0.13
1.0.12
1.0.10
1.0.9
1.0.8
1.0.7
1.0.6
1.0.5
1.0.4
1.0.3
1.0.2
1.0.1
1.0.0
0.1.0
SDK for GameServer hooks development. Provides type specs, documentation, and IDE autocomplete for GameServer modules without requiring the full server.
Current section
Files
Jump to
Current section
Files
lib/game_server/schedule.ex
defmodule GameServer.Schedule do
@moduledoc ~S"""
Dynamic cron-like job scheduling for hooks.
Use this module in your `after_startup/0` hook to register scheduled jobs
that will call your hook functions at specified intervals.
Jobs are durable and safe for distributed deployments: they run through the
background job queue (`GameServer.Jobs`, backed by Oban), so exactly one
instance executes each job per period and a crash mid-run is retried.
Scheduled callbacks are automatically protected from user RPC calls.
## Examples
def after_startup do
# Simple intervals
Schedule.every_minutes(5, :on_every_5m)
Schedule.hourly(:on_hourly)
Schedule.daily(:on_daily)
# With options
Schedule.daily(:on_morning_report, hour: 9)
Schedule.weekly(:on_monday, day: :monday, hour: 10)
# Full cron syntax
Schedule.cron(:my_job, "0 */6 * * *", :on_every_6h)
:ok
end
# Callback receives a context map (public function, but protected from RPC)
def on_hourly(context) do
IO.puts("Triggered at #{context["triggered_at"]}")
:ok
end
## Context
Callbacks run as background jobs, so the context is a **JSON map with string
keys** (`triggered_at` is an ISO8601 string):
%{
"triggered_at" => "2026-07-22T14:00:00Z",
"job_name" => "on_hourly",
"schedule" => "0 * * * *"
}
## Distributed Safety
A single per-minute tick (`GameServer.Schedule.TickWorker`, driven by Oban's
leader-elected Cron plugin) enqueues each due callback as a **unique** job.
Oban's uniqueness guarantees a callback runs at most once per period across
the whole cluster — no application-level locks required.
**Note:** This is an SDK stub. Calling these functions will raise an error.
The actual implementation runs on the GameServer.
"""
@doc ~S"""
Cancel a scheduled job.
## Examples
Schedule.cancel(:my_job)
"""
@spec cancel(atom()) :: :ok
def cancel(_name) do
case Application.get_env(:game_server_sdk, :stub_mode, :raise) do
:placeholder ->
:ok
_ ->
raise "GameServer.Schedule.cancel/1 is a stub - only available at runtime on GameServer"
end
end
@doc ~S"""
Register a job with full cron syntax.
## Examples
Schedule.cron(:my_job, "*/15 * * * *", :on_every_15m)
Schedule.cron(:weekdays, "0 9 * * 1-5", :on_weekday_morning)
"""
@spec cron(atom(), String.t(), atom()) :: :ok | {:error, term()}
def cron(_name, _cron_expr, _hook_fn) do
case Application.get_env(:game_server_sdk, :stub_mode, :raise) do
:placeholder ->
:ok
_ ->
raise "GameServer.Schedule.cron/3 is a stub - only available at runtime on GameServer"
end
end
@doc ~S"""
Run a job every day.
## Options
* `:hour` - hour of the day (0-23), default: 0
* `:minute` - minute of the hour (0-59), default: 0
## Examples
Schedule.daily(:on_midnight)
Schedule.daily(:on_morning, hour: 9)
Schedule.daily(:on_evening, hour: 18, minute: 30)
"""
@spec daily(atom()) :: :ok | {:error, term()}
def daily(_hook_fn) do
case Application.get_env(:game_server_sdk, :stub_mode, :raise) do
:placeholder ->
:ok
_ ->
raise "GameServer.Schedule.daily/1 is a stub - only available at runtime on GameServer"
end
end
@doc ~S"""
Run a job every day.
## Options
* `:hour` - hour of the day (0-23), default: 0
* `:minute` - minute of the hour (0-59), default: 0
## Examples
Schedule.daily(:on_midnight)
Schedule.daily(:on_morning, hour: 9)
Schedule.daily(:on_evening, hour: 18, minute: 30)
"""
@spec daily(atom(), hour: 0..23, minute: 0..59) :: :ok | {:error, term()}
def daily(_hook_fn, _opts) do
case Application.get_env(:game_server_sdk, :stub_mode, :raise) do
:placeholder ->
:ok
_ ->
raise "GameServer.Schedule.daily/2 is a stub - only available at runtime on GameServer"
end
end
@doc ~S"""
Run a job every N minutes.
## Examples
Schedule.every_minutes(5, :on_5m)
Schedule.every_minutes(15, :on_15m)
"""
@spec every_minutes(pos_integer(), atom()) :: :ok | {:error, term()}
def every_minutes(_n, _hook_fn) do
case Application.get_env(:game_server_sdk, :stub_mode, :raise) do
:placeholder ->
:ok
_ ->
raise "GameServer.Schedule.every_minutes/2 is a stub - only available at runtime on GameServer"
end
end
@doc ~S"""
Run a job every hour.
## Options
* `:minute` - minute of the hour (0-59), default: 0
## Examples
Schedule.hourly(:on_hourly)
Schedule.hourly(:on_half_hour, minute: 30)
"""
@spec hourly(atom()) :: :ok | {:error, term()}
def hourly(_hook_fn) do
case Application.get_env(:game_server_sdk, :stub_mode, :raise) do
:placeholder ->
:ok
_ ->
raise "GameServer.Schedule.hourly/1 is a stub - only available at runtime on GameServer"
end
end
@doc ~S"""
Run a job every hour.
## Options
* `:minute` - minute of the hour (0-59), default: 0
## Examples
Schedule.hourly(:on_hourly)
Schedule.hourly(:on_half_hour, minute: 30)
"""
@spec hourly(atom(), [{:minute, 0..59}]) :: :ok | {:error, term()}
def hourly(_hook_fn, _opts) do
case Application.get_env(:game_server_sdk, :stub_mode, :raise) do
:placeholder ->
:ok
_ ->
raise "GameServer.Schedule.hourly/2 is a stub - only available at runtime on GameServer"
end
end
@doc ~S"""
List all scheduled jobs.
Returns a list of job info maps.
"""
@spec list() :: [%{name: atom(), schedule: String.t(), hook: atom(), state: atom()}]
def list() do
case Application.get_env(:game_server_sdk, :stub_mode, :raise) do
:placeholder ->
""
_ ->
raise "GameServer.Schedule.list/0 is a stub - only available at runtime on GameServer"
end
end
@doc ~S"""
Returns the set of callback function names registered for background jobs.
The union of hook functions bound to an active schedule and any hook enqueued
via `GameServer.Jobs`. These are protected from user RPC calls via
`Hooks.call/3`. Cancelling a schedule drops its callback from the set unless
another schedule (or a `Jobs` enqueue) still references it.
"""
@spec registered_callbacks() :: MapSet.t(atom())
def registered_callbacks() do
case Application.get_env(:game_server_sdk, :stub_mode, :raise) do
:placeholder ->
nil
_ ->
raise "GameServer.Schedule.registered_callbacks/0 is a stub - only available at runtime on GameServer"
end
end
@doc ~S"""
Run a job every week.
## Options
* `:day` - day of week (`:sunday`, `:monday`, etc.), default: `:sunday`
* `:hour` - hour of the day (0-23), default: 0
* `:minute` - minute of the hour (0-59), default: 0
## Examples
Schedule.weekly(:on_sunday)
Schedule.weekly(:on_monday_morning, day: :monday, hour: 9)
"""
@spec weekly(atom()) :: :ok | {:error, term()}
def weekly(_hook_fn) do
case Application.get_env(:game_server_sdk, :stub_mode, :raise) do
:placeholder ->
:ok
_ ->
raise "GameServer.Schedule.weekly/1 is a stub - only available at runtime on GameServer"
end
end
@doc ~S"""
Run a job every week.
## Options
* `:day` - day of week (`:sunday`, `:monday`, etc.), default: `:sunday`
* `:hour` - hour of the day (0-23), default: 0
* `:minute` - minute of the hour (0-59), default: 0
## Examples
Schedule.weekly(:on_sunday)
Schedule.weekly(:on_monday_morning, day: :monday, hour: 9)
"""
@spec weekly(atom(), day: atom(), hour: 0..23, minute: 0..59) :: :ok | {:error, term()}
def weekly(_hook_fn, _opts) do
case Application.get_env(:game_server_sdk, :stub_mode, :raise) do
:placeholder ->
:ok
_ ->
raise "GameServer.Schedule.weekly/2 is a stub - only available at runtime on GameServer"
end
end
end