{"action":"created","issue":{"url":"https://api.github.com/repos/yiisoft/yii2/issues/8864","labels_url":"https://api.github.com/repos/yiisoft/yii2/issues/8864/labels{/name}","comments_url":"https://api.github.com/repos/yiisoft/yii2/issues/8864/comments","events_url":"https://api.github.com/repos/yiisoft/yii2/issues/8864/events","html_url":"https://github.com/yiisoft/yii2/pull/8864","id":90062301,"number":8864,"title":"[WIP] Queue components","user":{"login":"creocoder","id":896494,"avatar_url":"https://avatars.githubusercontent.com/u/896494?v=3","gravatar_id":"","url":"https://api.github.com/users/creocoder","html_url":"https://github.com/creocoder","followers_url":"https://api.github.com/users/creocoder/followers","following_url":"https://api.github.com/users/creocoder/following{/other_user}","gists_url":"https://api.github.com/users/creocoder/gists{/gist_id}","starred_url":"https://api.github.com/users/creocoder/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/creocoder/subscriptions","organizations_url":"https://api.github.com/users/creocoder/orgs","repos_url":"https://api.github.com/users/creocoder/repos","events_url":"https://api.github.com/users/creocoder/events{/privacy}","received_events_url":"https://api.github.com/users/creocoder/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/yiisoft/yii2/labels/type:feature","name":"type:feature","color":"02d7e1"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":29,"created_at":"2015-06-22T10:22:13Z","updated_at":"2015-06-22T17:33:07Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/yiisoft/yii2/pulls/8864","html_url":"https://github.com/yiisoft/yii2/pull/8864","diff_url":"https://github.com/yiisoft/yii2/pull/8864.diff","patch_url":"https://github.com/yiisoft/yii2/pull/8864.patch"},"body":"Usage from application side:\r\n\r\n```php\r\n// use plain payload\r\nYii::$app->queue->push('Some message');\r\n\r\n// use job payload\r\nSendEmailJob::push();\r\n```\r\n\r\nConcrette job classes:\r\n\r\n```php\r\nclass SendEmailJob extends \\yii\\queue\\Job\r\n{\r\n    /**\r\n     * @var common\\models\\User\r\n     */\r\n    protected $user;\r\n\r\n    /**\r\n     * @inheritdoc\r\n     */\r\n    public function run()\r\n    {\r\n        // ...\r\n    }\r\n}\r\n```\r\n\r\nWorkers:\r\n\r\n```sh\r\n./yii queue/listen // listen default back-end, default pool\r\n./yii queue/listen rabbitmq // listen rabbitmq back-end, default pool\r\n./yii queue/listen rabbitmq --queue=emails //listen rabbitmq back-end, emals pool\r\n```"},"comment":{"url":"https://api.github.com/repos/yiisoft/yii2/issues/comments/114192503","html_url":"https://github.com/yiisoft/yii2/pull/8864#issuecomment-114192503","issue_url":"https://api.github.com/repos/yiisoft/yii2/issues/8864","id":114192503,"user":{"login":"creocoder","id":896494,"avatar_url":"https://avatars.githubusercontent.com/u/896494?v=3","gravatar_id":"","url":"https://api.github.com/users/creocoder","html_url":"https://github.com/creocoder","followers_url":"https://api.github.com/users/creocoder/followers","following_url":"https://api.github.com/users/creocoder/following{/other_user}","gists_url":"https://api.github.com/users/creocoder/gists{/gist_id}","starred_url":"https://api.github.com/users/creocoder/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/creocoder/subscriptions","organizations_url":"https://api.github.com/users/creocoder/orgs","repos_url":"https://api.github.com/users/creocoder/repos","events_url":"https://api.github.com/users/creocoder/events{/privacy}","received_events_url":"https://api.github.com/users/creocoder/received_events","type":"User","site_admin":false},"created_at":"2015-06-22T17:33:07Z","updated_at":"2015-06-22T17:33:07Z","body":"@klimov-paul After some thinking i realize that your suggestions complettely break original idea and add several drawbacks without any benefits, moreover its just can't be implemented this way. First of all features planned:\r\n\r\n- send raw message to queue\r\n- send anonymous function with serialized data to queue\r\n- send Job to queue\r\n\r\nIts impossible to implement with having silly Queue component which can only send raw messages to queue. Also Job instanse should not be serialized from message size point of view.\r\n\r\nExamples:\r\n\r\n```php\r\nYii::$app->queue->push(function ($data) {\r\n    Yii::$app->mailer->send(...);\r\n}, ['data' => $data]);\r\n\r\nYii::$app->queue->push(SendEmailJob::className(), ['data' => $data]);\r\n```\r\n\r\nIt was designed first way for such pushes because raw message push does not make sence from practical reasons and even if its needed it can be implemented through `pushMessage()` method for example. Second with your suggestions its impossible to pop different Job classes and serialized anonymous functions from queue.\r\n\r\n> MyJob::listen();\r\n\r\nWill not work because queue servers work different way FYI. You do not know what kind of Job will come next. This is why listening concrette Job is just naive. If you suggest put one kind of job per pool it would be serious restrictions and its absoluttely unacceptable. You can push into one pool 2 class based Jobs, 3 anonymous function jobs and 5 plain messages. When you pop from queue you do not know what you'll get to process (check Amazon SQS documentation about non garantee orders for example).\r\n\r\nBecause all of this i'll rollback my original idea."}}