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');
|
||||
}
|
||||
}
|
||||
}
|
||||
35
app/Jobs/PublishIndexPostJob.php
Normal file
35
app/Jobs/PublishIndexPostJob.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Models\Post;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class PublishIndexPostJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
protected $post;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*/
|
||||
public function __construct(Post $post)
|
||||
{
|
||||
$this->post = $post;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
if (! is_null($this->post)) {
|
||||
PublishIndexPostTask::handle($this->post);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
use App\Helpers\FirstParty\OSSUploader\OSSUploader;
|
||||
use App\Helpers\ThirdParty\DFS\SettingSerpLiveAdvanced;
|
||||
use App\Jobs\PublishIndexPostJob;
|
||||
use App\Models\NewsSerpResult;
|
||||
use DFSClientV3\DFSClient;
|
||||
use Exception;
|
||||
@@ -239,6 +240,8 @@ public static function handle($post)
|
||||
$post->status = 'publish';
|
||||
$post->save();
|
||||
|
||||
PublishIndexPostJob::dispatch($post)->onQueue('default')->onConnection('default');
|
||||
|
||||
return $post;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Jobs\Tasks;
|
||||
|
||||
use App\Helpers\FirstParty\OpenAI\OpenAI;
|
||||
use App\Jobs\GenerateArticleFeaturedImageJob;
|
||||
use App\Models\Author;
|
||||
use App\Models\Post;
|
||||
use App\Models\PostCategory;
|
||||
@@ -71,6 +72,8 @@ public static function handle(SerpUrl $serp_url)
|
||||
$post_category->category_id = $serp_url->category->id;
|
||||
|
||||
if ($post_category->save()) {
|
||||
GenerateArticleFeaturedImageJob::dispatch($post)->onQueue('default')->onConnection('default');
|
||||
|
||||
return self::saveAndReturnSerpProcessStatus($serp_url, 1);
|
||||
} else {
|
||||
return self::saveAndReturnSerpProcessStatus($serp_url, -5);
|
||||
|
||||
34
app/Jobs/Tasks/PublishIndexPostTask.php
Normal file
34
app/Jobs/Tasks/PublishIndexPostTask.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\Tasks;
|
||||
|
||||
use App\Models\Post;
|
||||
use Exception;
|
||||
use IndexNow;
|
||||
use LaravelGoogleIndexing;
|
||||
|
||||
class PublishIndexPostTask
|
||||
{
|
||||
public static function handle(Post $post)
|
||||
{
|
||||
$post->published_at = now();
|
||||
|
||||
if ($post->save()) {
|
||||
if (app()->environment() == 'production') {
|
||||
$post_url = route('front.post', ['slug' => $post->slug]);
|
||||
|
||||
try {
|
||||
IndexNow::submit($post_url);
|
||||
} catch (Exception) {
|
||||
}
|
||||
|
||||
try {
|
||||
LaravelGoogleIndexing::create()->update($post_url);
|
||||
} catch (Exception) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user