2

I am trying to update a database row within a queued job which works when my queue connection is set to sync but now when it's set to database.

Edit: Fixed Serialization issue, update db in queue issue still persists.

public function handle()
    {

      $id = $this->settings->id;
      $server = $this->settings->server;
      $number = $this->settings->number;
      $api_script = storage_path('script.py');
      $delay = 5;

      //Determine Delay

      //Process Script Here

      //Check If Script Successful

      DB::table('orders')->where('order_id', $this->settings->order_id)->update(['status' => "Finalising..."]);

      ProcessEmails::dispatch($this->settings)->delay(now()->addMinutes($delay));
      // echo $process->getOutput();
    }

Above is the job that I want to execute, the update database command works in sync but not when the connection is set to database.

Thanks for your help!

Tim Rowley
  • 420
  • 4
  • 15
  • This problem shows up in the same environment only by changing queue driver or is the same application one local and one in production? – dparoli Aug 25 '19 at 00:32
  • @dparoli Same environment, only changing the .env variable. – Tim Rowley Aug 25 '19 at 00:34
  • Take a look here, seems your same problem even if not linked to queues: https://stackoverflow.com/questions/45266254/laravel-unable-to-prepare-route-for-serialization-uses-closure and here: https://laravel.com/docs/5.8/deployment#optimizing-route-loading where it write about serialization. – dparoli Aug 25 '19 at 00:38
  • @dparoli Thanks for that,I actually already sorted the route issue by moving the return view to a controller. The queue/database update issue still persists. – Tim Rowley Aug 25 '19 at 00:43
  • Glad to be of help. Please try to use `\DB::table('orders')...` – dparoli Aug 25 '19 at 00:51
  • @dparoli No success with that :( – Tim Rowley Aug 25 '19 at 00:54
  • Probably superflous but FYI sync does not require a queue worker but database driver needs it, do you run `php artisan queue:work`? – dparoli Aug 25 '19 at 00:57
  • @dparoli Thanks for the consideration but yes, the job runs through and dispatches the next job all fine, the only issue is the db not updating as per the DB::table command. – Tim Rowley Aug 25 '19 at 01:00

1 Answers1

5

Overtime you encounter some really, really stupid mistakes. My issue was resolved by simply restarting the queue:work command. I had the queue:work running throughout all my edit and by ending it and starting it back up.. boom, magically my DB inserts work.

Tim Rowley
  • 420
  • 4
  • 15