Repository navigation
Module API Reference
Алексей . edited this page Apr 14, 2026
·
5 revisions
[SFModule("id", "DisplayName",
Category = "General", // Grouping label
Description = "", // Shown in /sfs info
DefaultEnabled = true, // Auto-start when container runs
ExecutionModel = ModuleExecutionModel.MainThread,
RestartPolicy = ModuleRestartPolicy.Manual,
Order = 0)] // Lower = starts first| Property | Type | Default | Description |
|---|---|---|---|
Id |
string |
required | Unique identifier, used in /sfs commands |
DisplayName |
string |
required | Shown in dashboard UI |
Category |
string |
"General" |
Grouping label |
Description |
string |
"" |
Detailed description |
DefaultEnabled |
bool |
true |
Start automatically on container run |
ExecutionModel |
ModuleExecutionModel |
MainThread |
Thread model |
RestartPolicy |
ModuleRestartPolicy |
Manual |
Auto-restart behavior |
Order |
int |
0 |
Sort order (ascending) |
| Property | Type | Description |
|---|---|---|
Context |
ModuleContext |
Runtime context with telemetry and services |
Log |
ILogger |
Module-scoped logger (Microsoft.Extensions.Logging) |
| Method | Description |
|---|---|
Task ExecuteAsync(CancellationToken) |
Main module logic. Runs until token is cancelled or an exception is thrown. |
| Method | When Called |
|---|---|
Task OnStartingAsync() |
Before ExecuteAsync
|
Task OnCompletedAsync() |
After ExecuteAsync returns normally |
Task OnFaultedAsync(Exception) |
After ExecuteAsync throws (before rethrowing) |
Task OnStoppingAsync() |
Always, during teardown (in finally) |
Task OnStoppedAsync() |
Always, after OnStoppingAsync (in finally) |
ILogger CreateLogger(ModuleContext) |
Override to provide custom logger (Serilog, NLog, etc.) |
| Property | Type | Description |
|---|---|---|
Descriptor |
ModuleDescriptor |
Immutable module metadata |
CancellationToken |
CancellationToken |
Signals module shutdown |
Assets |
IModuleStorage |
Module asset folder at <GameDir>\SF\<id>\, see Module Storage
|
UserData |
IModuleStorage |
Per-user folder at <MyDocuments>\GTA San Andreas User Files\SF\<id>\
|
Config |
IModuleConfig |
Typed JSON config at <UserData>\config.json
|
| Method | Signature | Description |
|---|---|---|
Heartbeat |
void Heartbeat(string? activity = null) |
Record heartbeat, update last activity |
ReportActivity |
void ReportActivity(string activity) |
Record activity without heartbeat |
SetStatusText |
void SetStatusText(string? value) |
Set status shown in dashboard |
IncrementCounter |
void IncrementCounter(string name, long delta = 1) |
Increment named counter |
SetDetail |
void SetDetail(string key, string? value) |
Set/remove key-value detail |
TrackLoop |
ModuleLoopScope TrackLoop(string? activity = null) |
Start loop timing scope |
GetSnapshot |
ModuleRuntimeSnapshot GetSnapshot() |
Get full telemetry snapshot |
| Method | Signature | Description |
|---|---|---|
RegisterDisposable |
IDisposable RegisterDisposable(IDisposable) |
Auto-dispose on module stop |
RegisterChatCommand |
IDisposable RegisterChatCommand(string cmd, Action<string?> cb) |
Register chat command with telemetry |
| Method | Signature | Description |
|---|---|---|
SwitchToMainThreadAsync |
Task SwitchToMainThreadAsync() |
Switch continuation to main thread |
RunBackground |
Task RunBackground(Func<Task> work) |
Run async work on thread pool |
readonly struct implementing IDisposable. Records loop iteration duration on Dispose().
// Use as a using BLOCK (not declaration) with yield outside:
using (ModuleLoopScope _ = Context.TrackLoop("activity"))
{
// measured work
}
await Task.Yield(); // outside scopeTracks:
- Iteration count
- Average/max loop duration (milliseconds)
- Duty cycle - ratio of sync work to iteration period
Immutable record created from [SFModule] attribute via ModuleDescriptor.FromType(typeof(T)).
| Property | Type |
|---|---|
Id |
string |
DisplayName |
string |
Category |
string |
Description |
string |
DefaultEnabled |
bool |
ExecutionModel |
ModuleExecutionModel |
RestartPolicy |
ModuleRestartPolicy |
Order |
int |
ModuleType |
Type |
Sealed record with 25 fields capturing the full module state at a point in time.
| Field | Type | Description |
|---|---|---|
Descriptor |
ModuleDescriptor |
Module metadata |
State |
ModuleLifecycleState |
Current state |
LastStopReason |
ModuleStopReason |
Why module last stopped |
AutoStartEnabled |
bool |
Auto-start flag |
CreatedAt |
DateTimeOffset? |
First creation time |
StartedAt |
DateTimeOffset? |
Last start time |
StoppedAt |
DateTimeOffset? |
Last stop time |
LastHeartbeatAt |
DateTimeOffset? |
Last heartbeat |
LastActivityAt |
DateTimeOffset? |
Last activity |
LastActivity |
string? |
Last activity description |
StatusText |
string? |
Custom status text |
StartThreadId |
int? |
Thread where module started |
LastThreadId |
int? |
Last observed thread |
StartCount |
long |
Total starts |
RestartCount |
long |
Total restarts |
FaultCount |
long |
Total faults |
LoopCount |
long |
Total loop iterations |
AverageLoopMilliseconds |
double |
Avg loop duration |
MaxLoopMilliseconds |
double |
Max loop duration |
EstimatedLoadPercent |
double |
Duty cycle 0-100% |
LastMemoryBytes |
long |
Process memory (polled every 2s) |
LastExceptionType |
string? |
Last exception type name |
LastExceptionMessage |
string? |
Last exception message |
Counters |
IReadOnlyDictionary<string, long> |
Custom counters |
Details |
IReadOnlyDictionary<string, string> |
Custom details |
OwnedDisposableCount |
int |
Registered disposables |
Uptime |
TimeSpan? |
Computed from start/stop times |
MainThread | BackgroundWorker | Hybrid
Manual | OnFault
Created | Starting | Running | Stopping | Stopped | Faulted
None | Completed | UserRequested | RestartRequested | ContainerShutdown | Faulted
- Главная / Home
- Установка
- Архитектура и совместимость
- SA-MP R1, R3-1, R5-1
- Написание модулей
- Плагины и зависимости
- Жизненный цикл
- API модулей
- Потоки и время жизни
- Ранняя загрузка
- Конфигурация и ассеты