Add (serp ai gen)
Add (scheduler)
This commit is contained in:
55
app/Jobs/AISerpGenArticleJob.php
Normal file
55
app/Jobs/AISerpGenArticleJob.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Jobs\Tasks\ParseNewsSerpDomainsTask;
|
||||
use App\Models\Category;
|
||||
use App\Models\SerpUrl;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class AISerpGenArticleJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
$category = Category::orderBy('serp_at', 'asc')
|
||||
->orWhereNull('serp_at')
|
||||
->first();
|
||||
|
||||
$news_serp_result = GetNewsSerpTask::handle($category, 'US');
|
||||
|
||||
if (is_null($news_serp_result)) {
|
||||
Log::error(json_encode($category->toArray()));
|
||||
throw Exception('Failed to execute GetNewsSerpTask');
|
||||
}
|
||||
|
||||
// We only take 1 record at a time
|
||||
if (ParseNewsSerpDomainsTask::handle($news_serp_result)) {
|
||||
$serp_url = SerpUrl::latest()->first();
|
||||
|
||||
if (is_null($serp_url)) {
|
||||
Log::error(json_encode($serp_url->toArray()));
|
||||
throw Exception('Failed to execute ParseNewsSerpDomainsTask');
|
||||
}
|
||||
|
||||
return GenerateArticleJob::dispatch($serp_url)->onQueue('default')->onConnection('default');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user