PHP code example of voodoo-mobile / yii2-queue

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

    

voodoo-mobile / yii2-queue example snippets


return [
    // ...
    'controllerMap' => [
        'queue' => [
            'class' => 'vm\queue\Console\Controller',
            //'sleepTimeout' => 1
        ],
        
    ],
];

'modules' => [
    'task' => [
        'class' => 'app\modules\task\Module',
    ]
]

'components' => [
    'queue' => [
        'class' => 'vm\queue\Queues\SqsQueue',
        'module' => 'task',
        'url' => 'https://sqs.ap-southeast-1.amazonaws.com/123456789012/queue',
		'config' => [
			'key' => 'AKIA1234567890123456',
			'secret' => '1234567890123456789012345678901234567890',
			'region' => 'ap-southeast-1',
			'version' => 'latest'
        ],
    ]
]

'components' => [
    'db' => [
        //the db component
    ],
    'queue' => [
        'class' => 'vm\queue\Queues\DbQueue',
        'db' => 'db',
        'tableName' => 'queue',
        'module' => 'task',
    ]
]

class FooController extends vm\queue\Worker\Controller {

    public function actionBar($param1, $param2){
        echo $param1;
    }
}

class FooController extends vm\queue\Worker\Controller {

    public function actionBar($param1, $param2){
        try {
        } catch (\Exception $ex){
            \Yii::error('Ouch something just happened');
            return false;
        }
    }
}

use vm\queue\Job;

$route = 'foo/bar';
$data = ['param1' => 'foo', 'param2' => 'bar'];
Yii::$app->queue->post(new Job(['route' => $route, 'data' => $data]));

Yii::$app->queue->post(new Job(function(){
    echo 'Hello World!';
}));

    public function behaviors() {
        return array_merge([
            [
                'class' => \vm\queue\Behaviors\DeferredEventBehavior::class,
                'events' => [
                    self::EVENT_AFTER_VALIDATE => 'deferAfterValidate',
                ]
            ]
        ]);
    }

    public function deferAfterValidate(){
        //Do something here.
    }

    'controllerMap' => [
        'queue' => [
            /* @var $queue vm\queue\Web\Controller */
            'class' => 'vm\queue\Web\Controller'
        ]
    ],

    'controllerMap' => [
        'queue' => [
            /* @var $queue vm\queue\Web\Controller */
            'class' => 'vm\queue\Web\Controller',
            'as access' => [
                'class' => '\yii\filters\AccessControl',
                'rules' => [
                    [
                        'allow' => true,
                        'ips' => [
                            '127.0.0.1'
                        ]
                    ]
                ]
            ]
        ]
    ],