updevru / dkron-php-client
Requires
- php: >=7.4.0||^8.0
- ext-json: *
- ext-mbstring: *
- jms/serializer: ^3.17
- psr/http-client-implementation: ^1.0
Requires (Dev)
- nyholm/psr7: ^1.5
- php-http/curl-client: ^2.2
- php-http/mock-client: ^1.5
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-10-20 14:11:18 UTC
README
This is the PHP Dkron API client. This library allows using of the actual API version. You can find more info in the documentation.
Table of contents
Requirements
- PHP 7.4 and above
- PHP's cURL support
- PHP's JSON support
- Any HTTP client compatible with PSR-18 (covered by the installation instructions).
- Any HTTP factories implementation compatible with PSR-17 (covered by the installation instructions).
- Any HTTP messages implementation compatible with PSR-7 (covered by the installation instructions).
Installation
Install the library from the Packagist by executing this command:
composer require updevru/dkron-php-client
Note: API client uses php-http/curl-client and nyholm/psr7 as a PSR-18, PSR-17 and PSR-7 implementation. You can replace those implementations during installation by installing this library with the implementation of your choice, like this:
composer require php-http/curl-client nyholm/psr7 updevru/dkron-php-client
Usage
Firstly, you should initialize the Client.
use Http\Client\Curl\Client; use Nyholm\Psr7\Factory\Psr17Factory; use Updevru\Dkron\ApiClient; use Updevru\Dkron\Endpoint\EndpointCollection; $client = new Updevru\Dkron\ApiClient( new Updevru\Dkron\Endpoint\EndpointCollection( [ [ 'url' => 'http://localhost', 'login' => null, 'password' => null, ] ] ), new Http\Client\Curl\Client(), new Nyholm\Psr7\Factory\Psr17Factory(), new Nyholm\Psr7\Factory\Psr17Factory() ); $api = new \Updevru\Dkron\Api($client, new \Updevru\Dkron\Serializer\JMSSerializer());
If HTTP basic authorization is enabled, enter login and password.
Create new job:
$newJob = new \Updevru\Dkron\Dto\JobDto(); $newJob->setName('test_job'); $newJob->setSchedule('*/2 * * * * *'); $newJob->setConcurrency(\Updevru\Dkron\Dto\JobDto::CONCURRENCY_FORBID); $newJob->setExecutor('shell'); $newJob->setExecutorConfig(['command' => 'echo Hello']); $api->jobs->createOrUpdateJob($newJob);
Run job manually:
$api->jobs->runJob('test_job');
Show list executions:
$jobs = $api->jobs->getJobs();
Disable job:
$api->jobs->toggleJob('test_job');
Deleting job test_job:
$api->jobs->deleteJob('test_job');
Testing
Run unit tests:
composer tests
Demo working library:
php bin/test.php http://localhost:8080