Awesome
Dkron PHP Adapter
Adapter to communicate with Dkron.
Please read Dkron API for usage details
Install:
- add
"gromo/dkron-php-adapter": "dev-master"
to your projectcomposer.json
- run
composer install
Use:
// connect to single ip
$api = new \Dkron\Api('http://192.168.0.1:8080');
// get status
$status = $api->getStatus();
// get all jobs
$jobs = $api->getJobs();
// create & save job
$newJob = new \Dkron\Models\Job('my-job', '@every 5m');
$newJob->setExecutor('shell');
$newJob->setExecutorConfig([
'command' => 'ls -la /'
]);
$api->saveJob($newJob);
// create job from parsed json
$newJobFromArray = \Dkron\Models\Job::createFromArray([
'name' => 'job name',
'schedule' => 'job schedule',
'executor' => 'shell',
'executor_config' => [
'command' => 'ls -la /tmp',
],
// other parameters
]);
// get job data as json string
$json = json_encode($newJobFromArray);
// get job by name
$existingJob = $api->getJob('my-job');
// run job by name
$api->runJob($existingJob->getName());
// get job executions
$executions = $api->getJobExecutions($existingJob->getName());
// delete job by name
$api->deleteJob($existingJob->getName());
// get current leader node
$leader = $api->getLeader();
// get all nodes
$members = $api->getMembers();
// force current node to leave cluster
$api->leave();
// connect to multiple servers with round-robin requests
$mApi = new \Dkron\Api(['http://192.168.0.1:8080', 'http://192.168.0.2:8080']);
// force selected node to leave cluster
$mApi->leave('http://192.168.0.1:8080');
API methods
All URIs are relative to http://localhost:8080/v1
Method | Description | HTTP request |
---|---|---|
getStatus | Get status | GET / |
getJobs | Get all jobs | GET /jobs |
saveJob | Save job | POST /jobs |
getJob | Get job info by name | GET /jobs/{job_name} |
runJob | Run job by name | POST /jobs/{job_name} |
deleteJob | Delete job by name | DELETE /jobs/{job_name} |
getJobExecutions | Get job executions by job name | GET /jobs/{job_name}/executions |
getLeader | Get leader | GET /leader |
leave | Force the node to leave the cluster | GET /leave |
getMembers | Get members | GET /members |
Contribute
Please refer to CONTRIBUTING.md for information.