Main
Main
Main Warlock agent process responsible for task orchestration.
class Main extends \Hazaar\Warlock\ProcessExtends: Hazaar\Warlock\Process
Properties
tasks
Main task queue.
public array $tasksType: array
tags
Tags for scheduled tasks.
public array $tagsType: array
reconnect
Reconnect automatically when control channel is interrupted.
protected bool $reconnect = trueType: bool
config
Agent configuration loaded from environment and config files.
private Config $configType: Hazaar\Config
app
Application metadata used by spawned task processes.
private Application $appType: Hazaar\Warlock\Agent\Struct\Application
Methods
__construct
public __construct(?string $configFile, string $env = 'development'): voidParameters
| Parameter | Type | Description |
|---|---|---|
$configFile | string | agent config filename |
$env | string | runtime environment name |
getConfig
Returns the agent configuration.
public getConfig(): ConfigReturns: Hazaar\Config
setSilent
Enables or disables agent log output.
public setSilent(bool $silent = true): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$silent | bool |
createConnection
Creates the agent control-channel socket connection.
public createConnection(Protocol $protocol, ?string $guid): ConnectionReturns: Hazaar\Warlock\Interface\Connection
Parameters
| Parameter | Type | Description |
|---|---|---|
$protocol | Hazaar\Warlock\Protocol | |
$guid | string |
bootstrap
Performs one-time agent setup before entering the run loop.
public bootstrap(): selfReturns: self
registerServices
Loads and registers service tasks from a services config file.
public registerServices(string $configFile = 'services'): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$configFile | string |
registerScheduledTasks
Registers scheduled tasks based on the provided configuration array.
public registerScheduledTasks(array $scheduleConfig): voidReturns: void
Iterates through each task in the schedule configuration, validates the presence of the 'action' attribute, creates an Endpoint for the action, sets parameters if provided, and schedules the task to run at the specified time. Handles special scheduling keyword '@reboot' by calculating the appropriate start time with an optional boot delay. Logs notices and errors for missing or invalid configuration attributes.
Parameters
| Parameter | Type | Description |
|---|---|---|
$scheduleConfig | array |
registerEventHandlers
Registers event handlers based on the provided configuration array.
public registerEventHandlers(array $eventConfig): voidReturns: void
Iterates through each event in the event configuration, creates an Endpoint for the handler, and subscribes to the event with the corresponding handler. Logs notices and errors for invalid configuration attributes.
Parameters
| Parameter | Type | Description |
|---|---|---|
$eventConfig | array | array of event configurations where the key is the event name and the value is the handler (callable) |
shutdown
public shutdown(): voidReturns: void
init
public init(): boolReturns: bool
announce
public announce(): voidReturns: void
trigger
public trigger(string $event, mixed $data, bool $echoSelf): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$event | string | |
$data | mixed | |
$echoSelf | bool |
run
protected run(): voidReturns: void
processCommand
protected processCommand(PacketType $command, ?\stdClass $payload): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$command | Hazaar\Warlock\Enum\PacketType | |
$payload | stdClass |
processEvent
private processEvent(string $event, mixed $payload): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$event | string | |
$payload | mixed |
scheduleRunner
private scheduleRunner(int|string $when, Endpoint $endpoint, array $args, ?string $tag, bool $overwrite): false|stringReturns: false|string
Parameters
| Parameter | Type | Description |
|---|---|---|
$when | int | string |
$endpoint | Hazaar\Warlock\Agent\Struct\Endpoint | |
$args | array | |
$tag | string | |
$overwrite | bool |
handleTaskError
Handles a task reporting an unhandled exception from its child process.
public handleTaskError(Task $task, mixed $error): boolReturns: bool
If a task.error_handler callable is configured, schedules it as a new task, passing it the error and information about the task that failed. Without a task.error_handler configured, the error is only logged, which is what happened previously.
Parameters
| Parameter | Type | Description |
|---|---|---|
$task | Hazaar\Warlock\Agent\Task | |
$error | mixed |
scheduleErrorHandler
Schedules an error handler task, replacing any non-running task already queued for the
private scheduleErrorHandler(Endpoint $endpoint, mixed $error, array $taskInfo, string $tag, int $when): ?stringReturns: string
same tag. Skips scheduling if the tagged handler is currently running.
Parameters
| Parameter | Type | Description |
|---|---|---|
$endpoint | Hazaar\Warlock\Agent\Struct\Endpoint | |
$error | mixed | |
$taskInfo | array | |
$tag | string | |
$when | int |
taskQueueAdd
private taskQueueAdd(Task $task): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$task | Hazaar\Warlock\Agent\Task |
taskCancel
private taskCancel(string $taskID): boolReturns: bool
Parameters
| Parameter | Type | Description |
|---|---|---|
$taskID | string |
Generated by Hazaar API Doc Generator on Fri, 04 Sep 2026 23:32:17 +0000