-
Notifications
You must be signed in to change notification settings - Fork 1
Configuration
Since the daemon is a PHP script that is pinged directly and is not loaded by WordPress, when it starts running it won't have access to WordPress or any of its functions. The daemon will load WordPress manually when it is pinged, but before it does it won't have access to the database for configuration. Furthermore, in order to load WordPress, the daemon must know where WordPress is.
This is where the config comes in. Since the client has access to WordPress, it has access to WordPress' API and can know its root directory (ABSPATH). All of the information needed by the daemon is dumped into the config file by the client so that the daemon can simply load this file and get to work.
When setting up the Cronarchy instance, you can override the default configuration by passing an array as the fourth argument to Cronarchy::setup(), or as the second argument to the Config constructor if you are setting things up manually.
$instance = Cronarchy::setup($instanceId, $daemonUrl, $configPath, [
// config here
]);
// == or ==
$config = new Config($configPath, [
// config here
]);The config is only written to file once by Cronarchy: when it is created for the first time or when not found. After the config file has been created, Cronarchy will not automatically detect config changes in your code.
You may safely delete the config file as it will be automatically re-created. In fact, this can be quite useful during development.
At runtime, if you wish to update the config (for instance if you want to sync this configuration with database options), you must first make changes to the config and then explicitly call $cronarchyInstance->getConfig()->save() in order to update the config:
$config = $myCronarchyInstance->getConfig();
$config['run_interval'] = 30;
$config['logging_enabled'] = true;
$config->save();Specifies how frequently the daemon should run, in seconds.
[
'run_interval' => 10 // run every 10 seconds
]
Specifies the maximum amount of time a job can run for. If a job exceeds this limit, the daemon will terminate and treat the job as "failed".
[
'max_job_run_time' => 30 // up to 30 seconds per job
]
Specifies the maximum amount of time the daemon can run for. If the daemon has been running for a longer amount of time, it is considered to be "stuck" and will be reset.
[
'max_total_run_time' => 10 * 60 // up to 10 minutes total
]
If true, jobs that fail are deleted and are not re-run. If false, a failed job will be attempted again on the next daemon run. The default is false to match WP Cron's behavior.
[
'delete_failed_jobs' => true|false
]
If true, logging to a log file is enabled for the daemon. If false, nothing will be logged.
[
'logging_enabled' => true|false
]
If logging is enabled, all log output will be written to the file at this path. By default, logs will be written to a cronarchy.log file in the same directory as the config file.
[
'log_file_path' => MY_PLUGIN_DIR . '/cron.log'
]