Cron API
Cron jobs can be fully managed through the API and SDK. The section contains methods to execute CRUD-operations against the Cron endpoints.
#
ListReturns all cronjobs for selected environment, which is controlled by which API token that is in use.
$response = $client->cron->list();if ($response->wasSuccessful()) { $items = $response->getResultItems(); // Do something with items}
#
CreateCreate a cronjob. Note that you need to specify the environment.
Example:
$response = $client->cron->create([ 'type' => 'cronjobs', 'attributes' => [ 'enabled' => 1, 'command' => 'ls ./', 'comment' => 'This is a cron job created using the PHP SDK', 'schedule' => '* * * * *', 'notifications' => 'none', ], 'relationships' => [ 'environment' => [ 'data' => [ 'type' => 'environments', 'id' => 123, ] ] ],]);if ($response->wasSuccessful()) { // Do something} elseif ($response->hasErrors()) { $errors = $response->getErrors(); // Do something with errors}
#
GetReturns a specific cronjob by ID.
$response = $client->cron->get(123);if ( $response->wasSuccessful() && $item = $response->getFirstResultItem()) { // Do something echo $item->id; // 123}
#
DeleteDeletes a cronjob by ID.
$response = $client->cron->delete(123);if ($response->wasSuccessful()) { // Cronjob deleted}
#
UpdateUpdated a cronjob by ID.
$response = $client->cron->update(123, [ 'attributes' => [ 'comment' => 'Updated comment' ]]);if ($response->wasSuccessful()) { // Cronjob updated}