title: Laravel 5.2 Queue and Jobs - Not Pushing to Jobs DB
body: <p>EDIT 2:</p>
  
  <p>Here are the steps we are going through:</p>
  
  <ol>
  <li>Schedule is Run (creating <code>CollectHistoricalData</code> Jobs for each company)</li>
  <li><code>CollectHistoricalData</code> should be pushed to Queue (<code>jobs</code> table)</li>
  <li><code>CollectHistoricalData</code> has a function <code>ApiDaemon::GetCompanyWithQuery($company, $query)</code> which is run from a separate class that is referenced a couple of other places too.</li>
  <li><code>GetCompanyWithQuery</code> collects the data and inserts it into the database.</li>
  </ol>
  
  <p>It runs all the way through fine, but the hang up is rather than inserting the job into the jobs table, it just runs it synchronously, one after another.</p>
  
  <hr>
  
  <p>EDIT 1:</p>
  
  <p>The <code>.env</code> file is set to use the <code>database</code> <code>QUEUE_DRIVER</code>, I have even tried hard coding it in the <code>config/queue.php</code> file.</p>
  
  <hr>
  
  <p>We are using Laravel 5.2 for a project. In this project, we are needing to every hour cURL a url and save the data to the database. We at first were using Cron Jobs and basically firing off thousands of cURLs in about a minute, which would crash PHP due to the load.</p>
  
  <p>We decided to move over to Laravel's Jobs and Queues, without success. We are using the Database driver for our jobs, and have tried numerous different approaches to getting the jobs into the database, so the daemon workers we have can process them.</p>
  
  <p>Here is our code right now, we are using the Kernel.php <code>$schedule</code> to start the thing off, so we don't have hundreds of requests attempting to happen an hour, which results in tens of thousands of cURLs.</p>
  
  <p>Kernel.php Schedule:</p>
  
  <pre><code>    $schedule
          -&gt;call(function () {
              $items = DB::select('{selecting certain things to run}');
              foreach ($items as $q) {
                  $this-&gt;dispatch(new CollectHistoricalData(Company::find($q-&gt;company_id), ApiQuery::find($q-&gt;query_id)));
              }
          })
          -&gt;hourly()
          -&gt;name('Historical Pulls')
          -&gt;withoutOverlapping()
          -&gt;before(function() {
              $this-&gt;startTime = Carbon::now();
          })
          -&gt;after(function () {
              mail({mail us a report afterward});
          });
  </code></pre>
  
  <p>When this runs, it is sitting there running them all one by one, rather than pushing them to the Jobs table that was created.</p>
  
  <p>CollectHistoricalData.php:</p>
  
  <pre><code>&lt;?php
  
  namespace App\Jobs;
  
  use App\Helpers\Daemons\ApiDaemon;
  use App\Jobs\Job;
  use App\Models\Company;
  use App\Models\ApiQuery;
  use Illuminate\Queue\SerializesModels;
  use Illuminate\Queue\InteractsWithQueue;
  use Illuminate\Contracts\Queue\ShouldQueue;
  
  class CollectHistoricalData extends Job implements ShouldQueue
  {
      use InteractsWithQueue, SerializesModels;
  
      protected $company, $query;
  
  
      /**
       * CollectHistoricalData constructor.
       * @param Company $company
       * @param ApiQuery $query
       */
      public function __construct(Company $company, ApiQuery $query)
      {
          $this-&gt;company = $company;
          $this-&gt;query = $query;
      }
  
      /**
       * Execute the job.
       *
       * @return void
       */
      public function handle()
      {
          mail({let us know what started and when});
          QueryDaemon::GetCompanyWithQuery($this-&gt;company, $this-&gt;query);
      }
  
      public function failed()
      {
          mail({mail us letting us know it failed});
      }
  
  
  }
  </code></pre>
  
  <p>The job is referencing another class with the function inside it (since that code is a heafty beast all on its own), plus there are about 20 of these, so it is easiest to reference the class rather than recreating all 20 classes into Jobs.</p>
  
  <p>TL;DR</p>
  
  <p>We have a schedule that is supposed to push a job that references a function in another class, to the jobs table, but is rather running them one after another, slowly. What is causing this?</p>