review/app/Jobs/UpdateConstellations.php

56 lines
1.7 KiB
PHP

<?php
namespace App\Jobs;
use App\Constellation;
use App\Services\ConstellationCrawler;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Log;
use Illuminate\Support\Carbon;
class UpdateConstellations implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$crawler = app(ConstellationCrawler::class);
foreach ($crawler->getConstellations() as $name => $constellation) {
$existedConstellation = Constellation::where('name', $name)->whereDate('created_at', Carbon::today())->first();
if(!$existedConstellation) {
$constellation = Constellation::create([
'name' => $name,
'all' => $constellation['all'],
'all_desc' => $constellation['all_desc'],
'love' => $constellation['love'],
'love_desc' => $constellation['love_desc'],
'career' => $constellation['career'],
'career_desc' => $constellation['career_desc'],
'income' => $constellation['income'],
'income_desc' => $constellation['income_desc'],
]);
Log::info("{$constellation->name} updated");
}
}
}
}