{"action":"created","issue":{"url":"https://api.github.com/repos/laravel/framework/issues/17155","repository_url":"https://api.github.com/repos/laravel/framework","labels_url":"https://api.github.com/repos/laravel/framework/issues/17155/labels{/name}","comments_url":"https://api.github.com/repos/laravel/framework/issues/17155/comments","events_url":"https://api.github.com/repos/laravel/framework/issues/17155/events","html_url":"https://github.com/laravel/framework/issues/17155","id":198854874,"number":17155,"title":"[5.3] queue fail() does not work correctly inside a queued command","user":{"login":"lioannou","id":1210658,"avatar_url":"https://avatars.githubusercontent.com/u/1210658?v=3","gravatar_id":"","url":"https://api.github.com/users/lioannou","html_url":"https://github.com/lioannou","followers_url":"https://api.github.com/users/lioannou/followers","following_url":"https://api.github.com/users/lioannou/following{/other_user}","gists_url":"https://api.github.com/users/lioannou/gists{/gist_id}","starred_url":"https://api.github.com/users/lioannou/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lioannou/subscriptions","organizations_url":"https://api.github.com/users/lioannou/orgs","repos_url":"https://api.github.com/users/lioannou/repos","events_url":"https://api.github.com/users/lioannou/events{/privacy}","received_events_url":"https://api.github.com/users/lioannou/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2017-01-05T01:31:55Z","updated_at":"2017-01-05T17:22:12Z","closed_at":null,"body":"- Laravel Version: 5.3.28\r\n- PHP Version: 7.1.0-3\r\n- Database Driver & Version: Redis Queue\r\n\r\n### Description:\r\n\r\nThe `InteractsWithQueue` has a public function `fail()` that states \"Fail the job from the queue\".\r\n\r\nIt is not not documented if this should permanently fail the job (regardless of the number of `--tries` set) and insert itself as a failed job on the `failed_jobs` table - or if it should fail this single attempt and allow more `tries` to occur.\r\n\r\nEither way - neither of these occur - meaning you can have a queue job fail without a database record and/or more tries.\r\n\r\n### Steps To Reproduce:\r\n\r\n    public function handle()\r\n    {\r\n        Log::info('I am running: '.$this->attempts());\r\n        $this->fail();\r\n    }\r\n\r\n    public function failed(Exception $exception)\r\n    {\r\n        Log::info('failed: '.$this->attempts());\r\n    }\r\n\r\nWhen I run `php artisan queue:work --tries=3` I get the following output (notice the green processed text):\r\n\r\n![image](https://cloud.githubusercontent.com/assets/1210658/21665890/56e024da-d2e6-11e6-8af6-8a86b9ec2716.png)\r\n\r\n\r\nAnd this is in my log file:\r\n\r\n    [2017-01-05 01:20:00] local.INFO: I am running: 1  \r\n    [2017-01-05 01:20:00] local.INFO: failed: 1  \r\n\r\nAnd my `failed_jobs` is empty.\r\n\r\nTo show that everything else works - if I do this:\r\n\r\n    public function handle()\r\n    {\r\n        Log::info('I am running: '.$this->attempts());\r\n        throw new Exception;\r\n    }\r\n\r\n    public function failed(Exception $exception)\r\n    {\r\n        Log::info('failed: '.$this->attempts());\r\n    }\r\n\r\nI then get this console output (notice the red failed text):\r\n\r\n![image](https://cloud.githubusercontent.com/assets/1210658/21665920/6c785772-d2e6-11e6-8b14-0e1d7101d8eb.png)\r\n\r\nAnd this is in my log file:\r\n\r\n```\r\n[2017-01-05 01:22:49] local.INFO: I am running: 1  \r\n[2017-01-05 01:22:49] local.ERROR: Exception in .... {full exception stack}\r\n[2017-01-05 01:22:52] local.INFO: I am running: 2  \r\n[2017-01-05 01:22:52] local.ERROR: Exception in .... {full exception stack}\r\n[2017-01-05 01:22:55] local.INFO: I am running: 3  \r\n[2017-01-05 01:22:55] local.INFO: failed: 1  \r\n[2017-01-05 01:22:55] local.ERROR: Exception in .... {full exception stack}\r\n```\r\n\r\nAnd I also get an entry in my `failed_jobs` as normal.\r\n\r\nSo I would expect calling `$this->fail()` to *either* push back onto the queues for more `tries` - or at least formally fail (with the console output correct & a job in my `failed_jobs` queue).\r\n\r\nI'll try and dig into the code to find the cause of error tomorrow if I get some time..."},"comment":{"url":"https://api.github.com/repos/laravel/framework/issues/comments/270702449","html_url":"https://github.com/laravel/framework/issues/17155#issuecomment-270702449","issue_url":"https://api.github.com/repos/laravel/framework/issues/17155","id":270702449,"user":{"login":"lioannou","id":1210658,"avatar_url":"https://avatars.githubusercontent.com/u/1210658?v=3","gravatar_id":"","url":"https://api.github.com/users/lioannou","html_url":"https://github.com/lioannou","followers_url":"https://api.github.com/users/lioannou/followers","following_url":"https://api.github.com/users/lioannou/following{/other_user}","gists_url":"https://api.github.com/users/lioannou/gists{/gist_id}","starred_url":"https://api.github.com/users/lioannou/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lioannou/subscriptions","organizations_url":"https://api.github.com/users/lioannou/orgs","repos_url":"https://api.github.com/users/lioannou/repos","events_url":"https://api.github.com/users/lioannou/events{/privacy}","received_events_url":"https://api.github.com/users/lioannou/received_events","type":"User","site_admin":false},"created_at":"2017-01-05T17:22:12Z","updated_at":"2017-01-05T17:22:12Z","body":"Just noticed - there might be a second bug (or maybe related).\r\n\r\nWhy does `Log::info('failed: '.$this->attempts());` give `1` in the last log dump above? It should be `3`?\r\n"}}
{"actor":{"display_login":"lioannou"}}