PHP code example of citomni / jobrunner

1. Go to this page and download the library: Download citomni/jobrunner library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

citomni / jobrunner example snippets


\CitOmni\JobRunner\Operation\StartJob

$result = (new \CitOmni\JobRunner\Operation\StartJob($this->app))->execute(
	'commerce.import_products',
	[
		'source_key' => 'supplier-a',
	],
	'commerce.import_products:supplier-a',
	'Import supplier A products'
);

\CitOmni\JobRunner\Operation\EnqueueTrustedJob

$result = (new \CitOmni\JobRunner\Operation\EnqueueTrustedJob($this->app))->execute(
	'deploy.publish_app',
	[
		'app_id' => 42,
		'environment' => 'production',
	],
	'deploy.publish_app:42:production',
	'Publish application'
);


declare(strict_types=1);

return [
	'jobrunner' => [
		'handlers' => [
			'commerce.import_products' => \App\JobRunner\ImportProductsJobHandler::class,
		],
	],
];

\CitOmni\JobRunner\Contract\JobHandlerInterface


declare(strict_types=1);

namespace App\JobRunner;

use CitOmni\JobRunner\Contract\JobHandlerInterface;
use CitOmni\JobRunner\Value\JobContext;

final class ImportProductsJobHandler implements JobHandlerInterface {
	public function run(JobContext $context): array {
		$payload = $context->payload();

		$sourceKey = (string)($payload['source_key'] ?? '');
		if ($sourceKey === '') {
			throw new \InvalidArgumentException('Payload source_key is 

$context->app();

$context->app();
$context->jobId();
$context->jobUuid();
$context->jobType();
$context->payload();

$context->info('Message.');
$context->warning('Message.');
$context->error('Message.');
$context->debug('Message.');

$context->stdout('Process output.');
$context->stderr('Process warning.');

$context->setStep(
	'import',
	'Importing products.',
	2,
	5
);

$context->heartbeat();

if ($context->isCancellationRequested()) {
	return [
		'cancelled' => true,
	];
}

\CitOmni\JobRunner\Operation\GetJobStatus

$status = (new \CitOmni\JobRunner\Operation\GetJobStatus($this->app))->execute(
	$jobId,
	$afterSeq,
	200
);

\CitOmni\JobRunner\Operation\CancelJob

$context->isCancellationRequested()

'jobrunner' => [
	'tables' => [
		'jobs' => 'jobrun_jobs',
		'logs' => 'jobrun_logs',
	],
	'handlers' => [
	],
	'php_binary' => 'php',
	'cli_entrypoint' => 'bin/citomni',
	'log_chunk_max_bytes' => 16384,
	'trusted_worker_idle_sleep_seconds' => 3,
],

[
	'app_id' => 42,
	'environment' => 'production',
]

$context->isCancellationRequested();
text
sql/citomni_jobrunner.sql
text
jobrun_jobs
jobrun_logs
text
started
already_active
launch_failed
bash
php bin/citomni job:work
text
jobrunner.trusted_worker_idle_sleep_seconds
text
php bin/citomni job:run <job-id> --token=<worker-token>
text
php bin/citomni job:run-trusted <job-id> --token=<handoff-token>
text
php bin/citomni job:work
text
jobrunner.php_binary
jobrunner.cli_entrypoint
job:run command registration
process launch permissions
text
php bin/citomni job:work
text
database access
job:run-trusted command registration
jobrunner.php_binary
jobrunner.cli_entrypoint
handler registration
claim_mode = trusted