Added jobArtefacts to InstagramRepostJob
All checks were successful
Push image to registry / build-image (push) Successful in 4m45s
All checks were successful
Push image to registry / build-image (push) Successful in 4m45s
This commit is contained in:
@ -7,6 +7,7 @@ use App\Browser\JobDebugScreenshot;
|
||||
use App\Models\InstagramRepost;
|
||||
use App\Models\InstagramAccount;
|
||||
use App\Models\Job;
|
||||
use App\Models\JobArtifact;
|
||||
use App\Models\JobRun;
|
||||
use App\Notification\Notifications\JobDebugNotification;
|
||||
use App\Notification\Providers\AllNotification;
|
||||
@ -141,6 +142,11 @@ class InstagramRepostJob extends BrowserJob implements ShouldBeUniqueUntilProces
|
||||
shuffle($toDownloadReels);
|
||||
$toDownloadReels = array_slice($toDownloadReels, 0, self::MAX_REPOSTS_PER_JOB);
|
||||
|
||||
$this->jobRun->addArtifact(new JobArtifact([
|
||||
"name" => count($toDownloadReels) . " reels sélectionnés pour être repost",
|
||||
"content" => ""
|
||||
]));
|
||||
|
||||
// Download the reels
|
||||
$downloadedReels = [];
|
||||
foreach ($toDownloadReels as $repost) {
|
||||
@ -153,19 +159,30 @@ class InstagramRepostJob extends BrowserJob implements ShouldBeUniqueUntilProces
|
||||
];
|
||||
}
|
||||
|
||||
$this->jobRun->addArtifact(new JobArtifact([
|
||||
"name" => count($downloadedReels) . " reels sélectionnés qui ont été téléchargés",
|
||||
"content" => ""
|
||||
]));
|
||||
|
||||
// Now repost all downloaded reels
|
||||
$repostedReelsCounter = 0;
|
||||
foreach ($downloadedReels as $infos) {
|
||||
$reel = $infos[0];
|
||||
$videoInfo = $infos[1];
|
||||
|
||||
try {
|
||||
// TODO : Avoid getting the reel from the db again, store it in the downloadedReels array
|
||||
$this->repostReel($browser, InstagramRepost::where('reel_id', $reel->reel_id)->first(), $videoInfo);
|
||||
$repostedReelsCounter += $this->repostReel($browser, InstagramRepost::where('reel_id', $reel->reel_id)->first(), $videoInfo);
|
||||
} catch (\Exception $e) {
|
||||
Log::error("Failed to repost reel: {$videoInfo->getTitle()} - " . $e->getMessage());
|
||||
AllNotification::send(new JobDebugNotification($this->jobId, "Failed to repost reel: {$videoInfo->getTitle()} - " . $e->getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
$this->jobRun->addArtifact(new JobArtifact([
|
||||
"name" => $repostedReelsCounter . " reels sélectionnés qui ont été repostés",
|
||||
"content" => ""
|
||||
]));
|
||||
} catch (\Exception $e) {
|
||||
dump($e->getMessage());
|
||||
} finally {
|
||||
@ -260,8 +277,9 @@ class InstagramRepostJob extends BrowserJob implements ShouldBeUniqueUntilProces
|
||||
return $videoInfo;
|
||||
}
|
||||
|
||||
protected function repostReel(Browser $browser, InstagramRepost $reel, IInstagramVideo $videoInfo)
|
||||
protected function repostReel(Browser $browser, InstagramRepost $reel, IInstagramVideo $videoInfo): bool
|
||||
{
|
||||
try {
|
||||
Log::info("Reposting reel: {$reel->reel_id} - {$videoInfo->getTitle()}");
|
||||
|
||||
// Increment the repost tries
|
||||
@ -316,6 +334,8 @@ class InstagramRepostJob extends BrowserJob implements ShouldBeUniqueUntilProces
|
||||
$reel->reposted = true;
|
||||
$reel->save();
|
||||
|
||||
return true;
|
||||
|
||||
} catch (\Exception $e) {
|
||||
try {
|
||||
$browser->waitForText("Your post was shared", 60, true);
|
||||
@ -327,6 +347,11 @@ class InstagramRepostJob extends BrowserJob implements ShouldBeUniqueUntilProces
|
||||
Log::error("Failed to repost reel: {$reel->reel_id} - " . $e->getMessage());
|
||||
$browser->screenshot(JobDebugScreenshot::getFileName($this->jobId));
|
||||
AllNotification::send(new JobDebugNotification($this->jobId, "Failed to repost reel: {$reel->reel_id} - " . $e->getMessage()));
|
||||
|
||||
return false;
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user