Created
April 19, 2019 14:43
-
-
Save rajwa766/01f3abc740020ed89492c3b30cfc8861 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace common\models\helpers\queue; | |
use Yii; | |
use yii\base\Behavior; | |
use yii\queue\Queue; | |
class CurrentJobBehavior extends Behavior | |
{ | |
public $current; | |
public function events() | |
{ | |
return [ | |
Queue::EVENT_BEFORE_EXEC => function ($event) { | |
$this->current = $event; | |
} | |
]; | |
} | |
} | |
?> | |
<?php | |
namespace common\models\helpers\queue; | |
use Yii; | |
use yii\db\Expression; | |
use common\models\Product; | |
use yii\base\BaseObject; | |
use yii\queue\JobInterface; | |
/** | |
* This is the model create job in the queue | |
*/ | |
class AddToQueue extends BaseObject implements JobInterface | |
{ | |
/** | |
* {@BlameableBehavior} | |
*/ | |
public function behaviors() | |
{ | |
return [ | |
'class'=>CurrentJobBehavior::className(), | |
]; | |
} | |
/** | |
* @var int $userId contain user id | |
* @var array $postData contain the search postdata | |
*/ | |
public $userId; | |
public $postData; | |
/** | |
* @param Queue $queue which pushed and is handling the job | |
* @return void|mixed result of the job execution | |
*/ | |
public function execute($queue) | |
{ | |
Product::productData($this->postData, $this->userId); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment