Framework: Queued job's handle method is not getting called

Created on 19 Nov 2016  路  12Comments  路  Source: laravel/framework

  • Laravel Version: 5.3.* ( latest version )
  • PHP Version: 7.0.3

Description:

  • Queue Driver: Redis

Queued job's handle method is not getting called by the queue processor. Queue worker shows that job has been processed properly but code specified inside the handle method is not getting executed.

Then I tried to queue a mail to check whether its the problem with the driver but emails are getting triggered properly.

Steps To Reproduce:

Below job is been dispatched from the controller

<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;

class SearchTool implements ShouldQueue
{
    use InteractsWithQueue, Queueable, SerializesModels;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct()
    {

    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        touch('/tmp/tool_got_called.txt');

        return;
    }

}
dispatch(new SearchTool());
php artisan queue:work redis --tries=3

am I doing anything wrong?

Thanks

Most helpful comment

I have the same issue with queue:work using the database as well. queue:listen seems to work.

Laravel v5.4.16

All 12 comments

It works when I run with php artisan queue:listen redis

can anyone explain what's the problem?

I have the same issue with queue:work using the database as well. queue:listen seems to work.

Laravel v5.4.16

Same problem here with database driver, it works with listen but not with work command. Any explication?

Any explanation for this?

queue:listen does not work either for me, any updates on this?

Just found out it must be an OS X issue, not a surprise.

Works fine on Ubuntu 16.04

I have the same problem. It works If I do dispatchNow(), but I don't want to do that. I have set QUEUE_DRIVER=sync. The job is constructed but not dispatched.

__construct():
image

handle():
image

If I use laravel-dump-server, I can't see any output in the handle method. This is what I get:

GET http://localhost/api/videos/176
-----------------------------------

 ------------ --------------------------------- 
  date         Wed, 29 Aug 2018 11:28:31 -0500  
  controller   "VideoController"                
  source       RetrieveVideo.php on line 42     
  file         app/Jobs/RetrieveVideo.php       
 ------------ --------------------------------- 

array:2 [
  "video" => array:20 [
    "id" => 176
    "state" => "pending"
    "type" => "other"
    "latitude" => 6.20714165
    "longitude" => -75.57301754
    "hash" => "da6359d74e0512eb0da262828b8b54fdf10035d6773c4ecc5ca2b00efa9a63b7"
    "ids3" => 293
    "reg_id" => "fyYB19USp8s:APA91bEG6LiQrUok1VvaLpNkGCgrH-XqfkD_DFWtaIxsNj7NE8En8O5ubg2VNcvT1TCB-Y_DjttHWSLpeToxW1EVSbk4HrqmjijJPbARQfE5MZmF4UgMnJz4I977ec2qaFplodbqGGJs"
    "thumbnail_id" => 989
    "has_thumbnail_error" => false
    "geo" => array:5 [
      0 => array:3 [
        "id" => 33409
        "name" => "Patio Bonito"
        "type" => "neighborhood"
      ]
      1 => array:3 [
        "id" => 33639
        "name" => "El Poblado"
        "type" => "commune"
      ]
      2 => array:3 [
        "id" => 33991
        "name" => "MEVALPNVCCD05E01000009"
        "type" => "quadrant"
      ]
      3 => array:3 [
        "id" => 34068
        "name" => "EST El Poblado"
        "type" => "policeStation"
      ]
      4 => array:3 [
        "id" => 34086
        "name" => "Distrito 5"
        "type" => "policeDistrict"
      ]
    ]
    "created_at" => "2018-08-29 11:02:06"
    "updated_at" => "2018-08-29 11:02:08"
    "recording_sid" => "RT5b1e998952549651eafe176f9072309a"
    "participant_sid" => "PA42d240f0fe67ce2c21d95a7e0e7c46e0"
    "composition_sid" => null
    "platform" => "android"
    "audio_sid" => null
    "comments_count" => 0
    "comments" => []
  ]
  "request" => Illuminate\Http\Request {#55
    #json: null
    #convertedFiles: null
    #userResolver: Closure {#399
      class: "Illuminate\Auth\AuthServiceProvider"
      this: Illuminate\Auth\AuthServiceProvider {#138 鈥
      parameters: {
        $guard: {
          default: null
        }
      }
      use: {
        $app: Illuminate\Foundation\Application {#5 鈥
      }
      file: "./vendor/laravel/framework/src/Illuminate/Auth/AuthServiceProvider.php"
      line: "85 to 87"
    }
    #routeResolver: Closure {#429
      class: "Illuminate\Routing\Router"
      this: Illuminate\Routing\Router {#34 鈥
      use: {
        $route: Illuminate\Routing\Route {#318 鈥
      }
      file: "./vendor/laravel/framework/src/Illuminate/Routing/Router.php"
      line: "635 to 637"
    }
    +attributes: Symfony\Component\HttpFoundation\ParameterBag {#65
      #parameters: []
    }
    +request: Symfony\Component\HttpFoundation\ParameterBag {#63
      #parameters: []
    }
    +query: Symfony\Component\HttpFoundation\ParameterBag {#63}
    +server: Symfony\Component\HttpFoundation\ServerBag {#67
      #parameters: array:67 [
        "SRC" => "/usr/local"
        "PHP_EXTRA_CONFIGURE_ARGS" => "--enable-fpm --with-fpm-user=www-data --with-fpm-group=www-data"
        "LAME_VERSION" => "3.99.5"
        "HOSTNAME" => "ae8d4e407aed"
        "PHP_INI_DIR" => "/usr/local/etc/php"
        "LD_LIBRARY_PATH" => "/usr/local/lib"
        "LIBASS_VERSION" => "0.13.7"
        "OPENCOREAMR_VERSION" => "0.1.4"
        "HOME" => "/var/www"
        "FRIBIDI_VERSION" => "0.19.7"
        "PHP_LDFLAGS" => "-Wl,-O1 -Wl,--hash-style=both -pie"
        "PHP_CFLAGS" => "-fstack-protector-strong -fpic -fpie -O2"
        "PHP_MD5" => ""
        "PHP_VERSION" => "7.2.5"
        "OPUS_VERSION" => "1.2"
        "OPENJPEG_VERSION" => "2.1.2"
        "VPX_VERSION" => "1.6.1"
        "GPG_KEYS" => "1729F83938DA44E27BA0F4D3DBDB397470D12172 B1B44D8F021E4E2D6021E995DC9FF8D3EE5AF27F"
        "PHP_CPPFLAGS" => "-fstack-protector-strong -fpic -fpie -O2"
        "PHP_ASC_URL" => "https://secure.php.net/get/php-7.2.5.tar.xz.asc/from/this/mirror"
        "COMPOSER_ALLOW_SUPERUSER" => "1"
        "PHP_URL" => "https://secure.php.net/get/php-7.2.5.tar.xz/from/this/mirror"
        "FFMPEG_VERSION" => "3.4"
        "FONTCONFIG_VERSION" => "2.12.4"
        "PATH" => "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
        "THEORA_VERSION" => "1.1.1"
        "OGG_VERSION" => "1.3.2"
        "LIBVIDSTAB_VERSION" => "1.1.0"
        "XVID_VERSION" => "1.3.4"
        "FDKAAC_VERSION" => "0.1.5"
        "PHPIZE_DEPS" => "autoconf \t\tdpkg-dev \t\tfile \t\tg++ \t\tgcc \t\tlibc-dev \t\tmake \t\tpkg-config \t\tre2c"
        "VORBIS_VERSION" => "1.3.5"
        "PWD" => "/var/www"
        "PHP_SHA256" => "af70a33b3f7a51510467199b39af151333fbbe4cc21923bad9c7cf64268cddb2"
        "X264_VERSION" => "20170226-2245-stable"
        "X265_VERSION" => "2.3"
        "FREETYPE_VERSION" => "2.5.5"
        "USER" => "www-data"
        "HTTP_ACCEPT" => "application/json"
        "HTTP_USER_AGENT" => "insomnia/6.0.2"
        "HTTP_HOST" => "localhost"
        "PATH_INFO" => ""
        "SCRIPT_FILENAME" => "/var/www/public/index.php"
        "REDIRECT_STATUS" => "200"
        "SERVER_NAME" => ""
        "SERVER_PORT" => "80"
        "SERVER_ADDR" => "172.19.0.6"
        "REMOTE_PORT" => "58386"
        "REMOTE_ADDR" => "172.19.0.1"
        "SERVER_SOFTWARE" => "nginx/1.13.12"
        "GATEWAY_INTERFACE" => "CGI/1.1"
        "REQUEST_SCHEME" => "http"
        "SERVER_PROTOCOL" => "HTTP/1.1"
        "DOCUMENT_ROOT" => "/var/www/public"
        "DOCUMENT_URI" => "/index.php"
        "REQUEST_URI" => "/api/videos/176"
        "SCRIPT_NAME" => "/index.php"
        "CONTENT_LENGTH" => ""
        "CONTENT_TYPE" => ""
        "REQUEST_METHOD" => "GET"
        "QUERY_STRING" => ""
        "FCGI_ROLE" => "RESPONDER"
        "PHP_SELF" => "/index.php"
        "REQUEST_TIME_FLOAT" => 1535560111.6944
        "REQUEST_TIME" => 1535560111
        "argv" => []
        "argc" => 0
      ]
    }
    +files: Symfony\Component\HttpFoundation\FileBag {#60
      #parameters: []
    }
    +cookies: Symfony\Component\HttpFoundation\ParameterBag {#66
      #parameters: []
    }
    +headers: Symfony\Component\HttpFoundation\HeaderBag {#68
      #headers: array:5 [
        "accept" => array:1 [
          0 => "application/json"
        ]
        "user-agent" => array:1 [
          0 => "insomnia/6.0.2"
        ]
        "host" => array:1 [
          0 => "localhost"
        ]
        "content-length" => array:1 [
          0 => ""
        ]
        "content-type" => array:1 [
          0 => ""
        ]
      ]
      #cacheControl: []
    }
    #content: null
    #languages: null
    #charsets: null
    #encodings: null
    #acceptableContentTypes: null
    #pathInfo: "/api/videos/176"
    #requestUri: "/api/videos/176"
    #baseUrl: ""
    #basePath: null
    #method: "GET"
    #format: null
    #session: null
    #locale: null
    #defaultLocale: "en"
    -isHostValid: true
    -isForwardedValid: true
    basePath: ""
    format: "html"
  }
]

Solved!
I had to remove $this->request from the constructor.
image

For me it was also the constructor, where I've got a Statement to work with an interface:

$this->myService = resolve(MyServiceInterface::class);

In my AppServiceProvider I've got this:
$this->app->singleton(MyServiceInterface::class, function() { return new MyService(); });

So it seems like, the Job can't resolve a request a Singleton pattern or in general a Statement like above.

I was having this problem too, where the handle method on my job was not getting called.
I tried removing some things from my __construct(), but that did not work. My daemon was running and processing the job in an instant and not logging any of my Log calls in the handle method.
Eh. So, I just did config:clear, config:cache, cache:clear and then restarted the worker daemon.
When I ran the job command again, it did not skip the handle method and executed properly.
So, if anyone else comes here, and can try what I tried... it worked for me.

php artisan queue:work
Running this command will instruct Laravel to create an instance of your application and start executing jobs, this instance will stay alive indefinitely which means the action of starting your Laravel application happens only once when the command was run & the same instance will be used to execute your jobs, that means the following:

You save server resources by avoiding booting up the whole app on every job.
You have to manually restart the worker to reflect any code change you made in your application.

Make sure your .env file is set to the correct QUEUE_CONNECTION.

I was looking for a few hours for the reason why my jobs were not dispatching, until I finally double checked my QUEUE_CONNECTION in the .env file, and it was set to database when my connection was configured for redis.

Hours to find, seconds to fix... ;) Hope it helps someone...

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JamborJan picture JamborJan  路  3Comments

jackmu95 picture jackmu95  路  3Comments

lzp819739483 picture lzp819739483  路  3Comments

klimentLambevski picture klimentLambevski  路  3Comments

Anahkiasen picture Anahkiasen  路  3Comments