Skip to content

Instantly share code, notes, and snippets.

@rajwa766
Created April 19, 2019 14:43
Show Gist options
  • Save rajwa766/01f3abc740020ed89492c3b30cfc8861 to your computer and use it in GitHub Desktop.
Save rajwa766/01f3abc740020ed89492c3b30cfc8861 to your computer and use it in GitHub Desktop.
<?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