Added Debug notifications
Some checks failed
Push image to registry / build-image (push) Failing after 3m41s
Some checks failed
Push image to registry / build-image (push) Failing after 3m41s
This commit is contained in:
@ -58,7 +58,7 @@ abstract class BrowserJob implements ShouldQueue
|
||||
// throw $e;
|
||||
}
|
||||
catch (Throwable $e) {
|
||||
$browser->screenshot("failure-{$this->jobId}");
|
||||
$browser->screenshot(JobErrorScreenshot::getFileName($this->jobId));
|
||||
AllNotification::send(new JobErrorNotification($this->jobId, $e->getMessage()));
|
||||
dump($e);
|
||||
throw $e;
|
||||
|
27
app/Browser/JobDebugScreenshot.php
Normal file
27
app/Browser/JobDebugScreenshot.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Browser;
|
||||
|
||||
use Laravel\Dusk\Browser;
|
||||
use function rtrim;
|
||||
|
||||
|
||||
class JobDebugScreenshot {
|
||||
public const IMG_FILE_NAME = "debug-";
|
||||
|
||||
public static function getFileName(int $jobId): string {
|
||||
return static::IMG_FILE_NAME . $jobId . ".png";
|
||||
}
|
||||
|
||||
public static function getImgFileAbsolutePath(int $jobId): string {
|
||||
return rtrim(Browser::$storeScreenshotsAt, '/') . "/" . static::getFileName($jobId);
|
||||
}
|
||||
|
||||
public static function getImgFileProjectPath(int $jobId): string {
|
||||
return app_path("Browser/screenshots/" . static::getFileName($jobId));
|
||||
}
|
||||
|
||||
public static function getImgFileExternalPath(int $jobId): string {
|
||||
return "screenshots/" . static::getFileName($jobId);
|
||||
}
|
||||
}
|
@ -9,7 +9,7 @@ use function rtrim;
|
||||
class JobErrorScreenshot {
|
||||
public const IMG_FILE_NAME = "failure-";
|
||||
|
||||
private static function getFileName(int $jobId): string {
|
||||
public static function getFileName(int $jobId): string {
|
||||
return static::IMG_FILE_NAME . $jobId . ".png";
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ namespace App\Browser\Jobs\Hellcase;
|
||||
|
||||
use App\Browser\BrowserJob;
|
||||
use App\Browser\Components\Hellcase\MainNav;
|
||||
use App\Browser\JobDebugScreenshot;
|
||||
use App\Browser\Jobs\Hellcase\HellcaseLoginQrCode;
|
||||
use App\Models\JobArtifact;
|
||||
use App\Models\JobRun;
|
||||
@ -11,6 +12,7 @@ use App\Notification\NotificationBody\Hellcase\HellcaseNotificationDailyFreeBody
|
||||
use App\Notification\NotificationBody\Hellcase\HellcaseNotificationLoginBody;
|
||||
use App\Notification\Notifications\Hellcase\HellcaseNotificationDailyFree;
|
||||
use App\Notification\Notifications\Hellcase\HellcaseNotificationLogin;
|
||||
use App\Notification\Notifications\JobDebugNotification;
|
||||
use App\Notification\Notifications\JobErrorNotification;
|
||||
use App\Notification\Providers\AllNotification;
|
||||
use Facebook\WebDriver\WebDriverBy;
|
||||
@ -102,7 +104,8 @@ class HellcaseJob extends BrowserJob implements ShouldBeUniqueUntilProcessing
|
||||
try {
|
||||
$qrCode = $browser->driver->findElement(WebDriverBy::xpath('//div[./*[contains(text(), "Or sign in with QR")]]'));
|
||||
} catch (\Exception $e) {
|
||||
AllNotification::send(new JobErrorNotification($this->jobId, "Le QR code de la page de connexion de Steam n'a pas été trouvé"));
|
||||
$browser->takeScreenshot(JobDebugScreenshot::getFileName($this->jobId));
|
||||
AllNotification::send(new JobDebugNotification($this->jobId, "Le QR code de la page de connexion de Steam n'a pas été trouvé"));
|
||||
throw $e;
|
||||
}
|
||||
|
||||
@ -206,6 +209,8 @@ class HellcaseJob extends BrowserJob implements ShouldBeUniqueUntilProcessing
|
||||
$hours = $availibleInButton->getText();
|
||||
// If the text is like "in 26 sec." we need to put one minute
|
||||
if (!str_contains($hours, "hr")) {
|
||||
$browser->takeScreenshot(JobDebugScreenshot::getFileName($this->jobId));
|
||||
AllNotification::send(new JobDebugNotification($this->jobId, "I hate niggers"));
|
||||
// $this->reschedule(1);
|
||||
sleep(60);
|
||||
return $this->getDailyFree($browser);
|
||||
|
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notification\NotificationBody;
|
||||
|
||||
use App\Models\Job;
|
||||
use App\Notification\NotificationBody;
|
||||
use App\Notification\Stringifiable;
|
||||
|
||||
class JobDebugNotificationBody extends NotificationBody {
|
||||
|
||||
private Job $job;
|
||||
private string $title;
|
||||
private string $body;
|
||||
private string $error;
|
||||
private bool $hasScreenshot;
|
||||
|
||||
public function __construct(Job $job, string $title, string $body, string $error, bool $hasScreenshot = false) {
|
||||
$this->job = $job;
|
||||
$this->title = $title;
|
||||
$this->body = $body;
|
||||
$this->error = $error;
|
||||
$this->hasScreenshot = $hasScreenshot;
|
||||
}
|
||||
|
||||
private function constructString(bool $inMarkdown = false) {
|
||||
$mdBody = "";
|
||||
if ($this->body !== null) {
|
||||
$mdBody .= $this->body;
|
||||
}
|
||||
if ($this->error !== null) {
|
||||
$errorWrapper = $inMarkdown ? "```" : "";
|
||||
$mdBody .= " :\n" . $errorWrapper . $this->error . $errorWrapper;
|
||||
}
|
||||
if ($inMarkdown && $this->hasScreenshot) {
|
||||
$mdBody .= "\nScreenshot : ";
|
||||
}
|
||||
return $mdBody;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function toMarkdownString(): string {
|
||||
return $this->constructString(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function toString(): string {
|
||||
return $this->constructString();
|
||||
}
|
||||
}
|
40
app/Notification/Notifications/JobDebugNotification.php
Normal file
40
app/Notification/Notifications/JobDebugNotification.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notification\Notifications;
|
||||
|
||||
use App\Browser\JobDebugScreenshot;
|
||||
use App\Notification\Notification;
|
||||
use App\Notification\NotificationBody\JobDebugNotificationBody;
|
||||
use App\Notification\Stringifiable;
|
||||
use App\Notification\Stringifiable\StringifiableSimpleText;
|
||||
|
||||
class JobDebugNotification extends Notification {
|
||||
|
||||
private string|null $title;
|
||||
private string|null $screenShotProjectPath;
|
||||
|
||||
public function __construct(int $jobId, string $body, string $title = null, string $error = null, string $screenshotProjectPath = JobDebugScreenshot::getImgFileProjectPath($jobId), bool $isError = false) {
|
||||
parent::__construct($jobId, isError:$isError);
|
||||
$this->title = $title;
|
||||
$this->screenShotProjectPath = $screenshotProjectPath;
|
||||
$this->setBody(new JobDebugNotificationBody($this->job, $this->title, $body, $error, $this->screenShotProjectPath != null));
|
||||
}
|
||||
|
||||
public function getTitle(): Stringifiable {
|
||||
return new StringifiableSimpleText($this->title ?? "DEBUG Job {$this->job->name}");
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getImageProjectPath(): string|null {
|
||||
return $this->screenShotProjectPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getLinkURL(): string|null {
|
||||
return route('jobs.show', ['job' => $this->job->id]);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user