PHP code example of yiicod / yii2-jobqueue

1. Go to this page and download the library: Download yiicod/yii2-jobqueue 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/ */

    

yiicod / yii2-jobqueue example snippets


    'bootstrap' => [
        'jobqueue'
    ],
    'components' => [
        'jobqueue' => [
            'class' => \yiicod\jobqueue\JobQueue::class
        ],
        'mongodb' => [
            'class' => '\yii\mongodb\Connection',
            'dsn' => 'mongodb://@localhost:27017/mydatabase',
        ],        
    ]

    'bootstrap' => [
        'jobqueue'
    ],
    'controllerMap' => [
        'job-queue' => [
            'class' => \yiicod\jobqueue\commands\JobQueueCommand::class,
        ]
    ],
    'components' => [
        'jobqueue' => [
            'class' => \yiicod\jobqueue\JobQueue::class
        ],
        'mongodb' => [
            'class' => '\yii\mongodb\Connection',
            'dsn' => 'mongodb://@localhost:27017/mydatabase',
        ],        
    ]    

$ php yii job-queue/start

$ php yii job-queue/stop

    'bootstrap' => [
        'jobqueue'
    ],
    'controllerMap' => [
        'job-queue' => [
            'class' => \yiicod\jobqueue\commands\WorkerCommand::class,
        ]
    ],
    'components' => [
        'jobqueue' => [
            'class' => \yiicod\jobqueue\JobQueue::class
        ],
        'mongodb' => [
            'class' => '\yii\mongodb\Connection',
            'dsn' => 'mongodb://@localhost:27017/mydatabase',
        ],        
    ]        

JobQueue::push(<--YOUR JOB QUEUE CLASS NAME->>, $data, $queue, $connection);
// Optional: $queue, $connection

'jobqueue' => [
    'class' => \yiicod\jobqueue\JobQueue::class,
    'connections' => [
        'default' => [
            'driver' => 'mongo-thread',
            'table' => 'yii-jobs',
            'queue' => 'default',
            'connection' => 'mongodb', // Default mongodb connection 
            'expire' => 60,
            'limit' => 1, // How many parallel process should run at the same time            
        ],
    ]
]

EVENT_RAISE_BEFORE_JOB = 'raiseBeforeJobEvent';
EVENT_RAISE_AFTER_JOB = 'raiseAfterJobEvent';
EVENT_RAISE_EXCEPTION_OCCURED_JOB = 'raiseExceptionOccurredJobEvent';
EVENT_RAISE_FAILED_JOB = 'raiseFailedJobEvent';
EVENT_STOP = 'stop';