// app/Jobs/SpecialJob.php
<?php
namespace Simile\Jobs;
use Illuminate\Support\Facades\Log;
use Simile\Http\Libraries\PriceHandler;
use Simile\Http\Libraries\ScrapeHandler;
use Simile\Jobs\Job;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Bus\SelfHandling;
use Illuminate\Contracts\Queue\ShouldQueue;
use Simile\Site;
class SpecialJob extends Job implements SelfHandling, ShouldQueue
{
use InteractsWithQueue, SerializesModels;
//protected $siteId;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($siteId)
{
$this->siteId = $siteId;
}
public function handle()
{
Log::info('grrr');
$site = Site::find($this->siteId);
// make sure the screenshot exists
if($screenshot = $site->latestScreenshot())
{
// find the new price
$fetchedPrice = (new PriceHandler)->getSitePrice($site);
// if the new price does not match the old one
if($screenshot->price !== $fetchedPrice) {
// save a new screenshot and price
(new ScrapeHandler)->saveScreenshot($site, $fetchedPrice);
}
// if not, mark the site as updated
else
{
$site->touch();
}
}
Log::info('woof' . $this->siteId);
}
}