Compare commits
4 Commits
fec63ff249
...
jobs/epic-
Author | SHA1 | Date | |
---|---|---|---|
d33d0ba6a1 | |||
fcb3f8d7d8 | |||
1bebf03a70 | |||
7079206658 |
@@ -5,8 +5,6 @@ namespace App\Browser;
|
|||||||
use App\Models\Job;
|
use App\Models\Job;
|
||||||
use App\Models\JobArtifact;
|
use App\Models\JobArtifact;
|
||||||
use App\Models\JobRun;
|
use App\Models\JobRun;
|
||||||
use App\Notification\Notifications\JobErrorNotification;
|
|
||||||
use App\Notification\Providers\AllNotification;
|
|
||||||
use Closure;
|
use Closure;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Facebook\WebDriver\Chrome\ChromeOptions;
|
use Facebook\WebDriver\Chrome\ChromeOptions;
|
||||||
@@ -58,8 +56,7 @@ abstract class BrowserJob implements ShouldQueue
|
|||||||
// throw $e;
|
// throw $e;
|
||||||
}
|
}
|
||||||
catch (Throwable $e) {
|
catch (Throwable $e) {
|
||||||
$browser->screenshot(JobErrorScreenshot::getFileName($this->jobId));
|
$browser->screenshot("failure-{$this->jobId}");
|
||||||
AllNotification::send(new JobErrorNotification($this->jobId, $e->getMessage()));
|
|
||||||
dump($e);
|
dump($e);
|
||||||
throw $e;
|
throw $e;
|
||||||
} finally {
|
} finally {
|
||||||
@@ -159,6 +156,7 @@ abstract class BrowserJob implements ShouldQueue
|
|||||||
'--whitelisted-ips=""',
|
'--whitelisted-ips=""',
|
||||||
'--disable-dev-shm-usage',
|
'--disable-dev-shm-usage',
|
||||||
'--user-data-dir=/home/seluser/profile/',
|
'--user-data-dir=/home/seluser/profile/',
|
||||||
|
'--auto-open-devtools-for-tabs',
|
||||||
])->all());
|
])->all());
|
||||||
|
|
||||||
return RemoteWebDriver::create(
|
return RemoteWebDriver::create(
|
||||||
|
47
app/Browser/Components/Hellcase/EpicGamesLogin.php
Normal file
47
app/Browser/Components/Hellcase/EpicGamesLogin.php
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Browser\Components\Hellcase;
|
||||||
|
|
||||||
|
use Laravel\Dusk\Browser;
|
||||||
|
use Laravel\Dusk\Component as BaseComponent;
|
||||||
|
|
||||||
|
class EpicGamesLogin extends BaseComponent
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Get the root selector for the component.
|
||||||
|
*/
|
||||||
|
public function selector(): string
|
||||||
|
{
|
||||||
|
return 'form';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Assert that the browser page contains the component.
|
||||||
|
*/
|
||||||
|
public function assert(Browser $browser): void
|
||||||
|
{
|
||||||
|
$browser->assertVisible($this->selector());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the element shortcuts for the component.
|
||||||
|
*
|
||||||
|
* @return array<string, string>
|
||||||
|
*/
|
||||||
|
public function elements(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'@email' => 'input#email',
|
||||||
|
'@password' => 'input#password',
|
||||||
|
'@signin-button' => 'button[type="submit"]',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function fillForm(Browser $browser, $email, $password) {
|
||||||
|
$browser->type('@email', $email);
|
||||||
|
sleep(1);
|
||||||
|
$browser->type('@password', $password);
|
||||||
|
sleep(1);
|
||||||
|
$browser->click('@signin-button');
|
||||||
|
}
|
||||||
|
}
|
@@ -1,27 +0,0 @@
|
|||||||
<?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);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,27 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Browser;
|
|
||||||
|
|
||||||
use Laravel\Dusk\Browser;
|
|
||||||
use function rtrim;
|
|
||||||
|
|
||||||
|
|
||||||
class JobErrorScreenshot {
|
|
||||||
public const IMG_FILE_NAME = "failure-";
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
174
app/Browser/Jobs/EpicGames/EpicGamesJob.php
Normal file
174
app/Browser/Jobs/EpicGames/EpicGamesJob.php
Normal file
@@ -0,0 +1,174 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Browser\Jobs\EpicGames;
|
||||||
|
|
||||||
|
use App\Browser\BrowserJob;
|
||||||
|
use App\Browser\Components\Hellcase\EpicGamesLogin;
|
||||||
|
use App\Models\JobInfo;
|
||||||
|
use App\Models\JobRun;
|
||||||
|
use App\Notification\Notifications\SimpleNotification;
|
||||||
|
use App\Notification\Providers\AllNotification;
|
||||||
|
use Exception;
|
||||||
|
use Facebook\WebDriver\WebDriverBy;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldBeUniqueUntilProcessing;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
use Laravel\Dusk\Browser;
|
||||||
|
|
||||||
|
class EpicGamesJob extends BrowserJob implements ShouldBeUniqueUntilProcessing
|
||||||
|
{
|
||||||
|
private const APPROXIMATIVE_RUNNING_MINUTES = 2;
|
||||||
|
|
||||||
|
private const WEBSITE_URL = "https://www.epicgames.com/store/en-US/";
|
||||||
|
|
||||||
|
private JobRun $jobRun;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
Log::info("Constructing " . self::class);
|
||||||
|
parent::__construct(3);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function run(Browser $browser): ?JobRun
|
||||||
|
{
|
||||||
|
// $browser->visit("https://bscscan.com/contractsVerified");
|
||||||
|
// sleep(3);
|
||||||
|
Log::info("Running " . self::class);
|
||||||
|
$this->jobRun = new JobRun([
|
||||||
|
"job_id" => $this->jobId,
|
||||||
|
"success" => false,
|
||||||
|
]);
|
||||||
|
$this->jobRun->save();
|
||||||
|
|
||||||
|
// $this->goToEpicGamesWebsite($browser);
|
||||||
|
// $this->removePopups($browser);
|
||||||
|
sleep(5);
|
||||||
|
$this->signin($browser);
|
||||||
|
$this->getFreeGames($browser);
|
||||||
|
|
||||||
|
$this->jobRun->success = true;
|
||||||
|
$this->jobRun->save();
|
||||||
|
|
||||||
|
Log::info(self::class . " run ended");
|
||||||
|
|
||||||
|
return $this->jobRun;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public function runTest(Browser $browser): ?JobRun
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$this->goToEpicGamesWebsite($browser);
|
||||||
|
sleep(2);
|
||||||
|
$this->removePopups($browser);
|
||||||
|
sleep(2);
|
||||||
|
$this->signin($browser);
|
||||||
|
return $this->makeSimpleJobRun(
|
||||||
|
true,
|
||||||
|
"Connexion réussie",
|
||||||
|
"Datboi a réussi à se connecter sur EpicGames"
|
||||||
|
);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
return $this->makeSimpleJobRun(
|
||||||
|
true,
|
||||||
|
"Connexion échouée",
|
||||||
|
"Datboi n'a pas réussi à se connecter sur EpicGames :\n" . $e->getMessage()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function goToEpicGamesWebsite(Browser $browser)
|
||||||
|
{
|
||||||
|
sleep(3);
|
||||||
|
$browser->visit(self::WEBSITE_URL);
|
||||||
|
sleep(3);
|
||||||
|
$this->assertNotDetected($browser);
|
||||||
|
$browser->waitForText("Store", 30, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function signin(Browser $browser)
|
||||||
|
{
|
||||||
|
// $browser->visit("https://store.epicgames.com/login?state=%2Fen-US%2F");
|
||||||
|
$browser->driver->executeScript('window.open("https://store.epicgames.com/login?state=%2Fen-US%2F")');
|
||||||
|
sleep(5);
|
||||||
|
$this->assertNotDetected($browser);
|
||||||
|
$browser->waitForText("Sign In", 30, true);
|
||||||
|
sleep(3);
|
||||||
|
|
||||||
|
$jobInfos = JobInfo::where("job_id", $this->jobId)->get();
|
||||||
|
$email = $jobInfos->where("key", "epicgames_account_email")->first()->value;
|
||||||
|
$password = $jobInfos->where("key", "epicgames_account_password")->first()->value;
|
||||||
|
$browser->within(new EpicGamesLogin, function (Browser $browser) use ($email, $password) {
|
||||||
|
$browser->fillForm($email, $password);
|
||||||
|
});
|
||||||
|
|
||||||
|
sleep(40);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getFreeGames(Browser $browser)
|
||||||
|
{
|
||||||
|
$browser->driver->executeScript('window.open("https://www.epicgames.com/store/en-US/free-games")');
|
||||||
|
// $browser->visit('https://www.epicgames.com/store/en-US/free-games');
|
||||||
|
$browser->waitForText("Free Games", 30, true);
|
||||||
|
$freeGamesLinkElements = $browser->driver->findElements(WebDriverBy::xpath('//a[contains(@aria-label, "Free Now")]'));
|
||||||
|
$freeGamesLinks = [];
|
||||||
|
foreach ($freeGamesLinkElements as $element) {
|
||||||
|
$freeGamesLinks[] = $element->getAttribute("href");
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($freeGamesLinks as $link) {
|
||||||
|
$browser->visit($link);
|
||||||
|
$this->claimCurrentGame($browser);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function claimCurrentGame(Browser $browser)
|
||||||
|
{
|
||||||
|
sleep(5);
|
||||||
|
$this->assertNotDetected($browser);
|
||||||
|
if ($this->unratedContent($browser)) {
|
||||||
|
throw new Exception("Le jeu demande un âge et datboi a la flemme de le mettre");
|
||||||
|
}
|
||||||
|
$this->waitForAndClickElementContainingText($browser, '//button', "Get", 30, true);
|
||||||
|
sleep(5);
|
||||||
|
$this->assertNotDetected($browser);
|
||||||
|
$browser->waitForText("Place Order", 30, true);
|
||||||
|
$browser->click("Place Order");
|
||||||
|
sleep(5);
|
||||||
|
$this->assertNotDetected($browser);
|
||||||
|
$browser->waitForText("Order Confirmation", 30, true);
|
||||||
|
$browser->click("Close");
|
||||||
|
sleep(5);
|
||||||
|
|
||||||
|
AllNotification::send(
|
||||||
|
new SimpleNotification($this->jobId, "Un jeu a été ajouté à votre bibliothèque", "Un jeu a été ajouté à votre bibliothèque EpicGames")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function unratedContent(Browser $browser)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$browser->waitForText("please provide your date of birth", 5, true);
|
||||||
|
return true;
|
||||||
|
} catch (Exception $_) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function removePopups(Browser $browser)
|
||||||
|
{
|
||||||
|
// $browser->script('document.querySelector("div.app-modal")[0].remove();');
|
||||||
|
// $browser->driver->executeScript('document.querySelector("div.app-modal")[0].remove();');
|
||||||
|
}
|
||||||
|
|
||||||
|
private function assertNotDetected(Browser $browser)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$browser->waitForText("One more step", 10, true);
|
||||||
|
} catch (Exception $_) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
throw new Exception("Détecté par cloudflare");
|
||||||
|
}
|
||||||
|
}
|
@@ -4,7 +4,6 @@ namespace App\Browser\Jobs\Hellcase;
|
|||||||
|
|
||||||
use App\Browser\BrowserJob;
|
use App\Browser\BrowserJob;
|
||||||
use App\Browser\Components\Hellcase\MainNav;
|
use App\Browser\Components\Hellcase\MainNav;
|
||||||
use App\Browser\JobDebugScreenshot;
|
|
||||||
use App\Browser\Jobs\Hellcase\HellcaseLoginQrCode;
|
use App\Browser\Jobs\Hellcase\HellcaseLoginQrCode;
|
||||||
use App\Models\JobArtifact;
|
use App\Models\JobArtifact;
|
||||||
use App\Models\JobRun;
|
use App\Models\JobRun;
|
||||||
@@ -12,8 +11,6 @@ use App\Notification\NotificationBody\Hellcase\HellcaseNotificationDailyFreeBody
|
|||||||
use App\Notification\NotificationBody\Hellcase\HellcaseNotificationLoginBody;
|
use App\Notification\NotificationBody\Hellcase\HellcaseNotificationLoginBody;
|
||||||
use App\Notification\Notifications\Hellcase\HellcaseNotificationDailyFree;
|
use App\Notification\Notifications\Hellcase\HellcaseNotificationDailyFree;
|
||||||
use App\Notification\Notifications\Hellcase\HellcaseNotificationLogin;
|
use App\Notification\Notifications\Hellcase\HellcaseNotificationLogin;
|
||||||
use App\Notification\Notifications\JobDebugNotification;
|
|
||||||
use App\Notification\Notifications\JobErrorNotification;
|
|
||||||
use App\Notification\Providers\AllNotification;
|
use App\Notification\Providers\AllNotification;
|
||||||
use Facebook\WebDriver\WebDriverBy;
|
use Facebook\WebDriver\WebDriverBy;
|
||||||
use Illuminate\Contracts\Queue\ShouldBeUniqueUntilProcessing;
|
use Illuminate\Contracts\Queue\ShouldBeUniqueUntilProcessing;
|
||||||
@@ -24,25 +21,26 @@ class HellcaseJob extends BrowserJob implements ShouldBeUniqueUntilProcessing
|
|||||||
{
|
{
|
||||||
private const STEAM_LOGIN_THRESHOLD = 5 * 60; // 5 minutes
|
private const STEAM_LOGIN_THRESHOLD = 5 * 60; // 5 minutes
|
||||||
private const APPROXIMATIVE_RUNNING_MINUTES = 2;
|
private const APPROXIMATIVE_RUNNING_MINUTES = 2;
|
||||||
|
private const WEBSITE_URL = "https://hellcase.com";
|
||||||
|
|
||||||
private JobRun $jobRun;
|
private JobRun $jobRun;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
Log::info("Constructing HellcaseJob");
|
Log::info("Constructing " . self::class);
|
||||||
parent::__construct(2);
|
parent::__construct(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function run(Browser $browser): ?JobRun
|
public function run(Browser $browser): ?JobRun
|
||||||
{
|
{
|
||||||
Log::info("Running HellcaseJob");
|
Log::info("Running " . self::class);
|
||||||
$this->jobRun = new JobRun([
|
$this->jobRun = new JobRun([
|
||||||
"job_id" => $this->jobId,
|
"job_id" => $this->jobId,
|
||||||
"success" => false,
|
"success" => false,
|
||||||
]);
|
]);
|
||||||
$this->jobRun->save();
|
$this->jobRun->save();
|
||||||
|
|
||||||
$browser->visit('https://hellcase.com');
|
$browser->visit(self::WEBSITE_URL);
|
||||||
$browser->waitForText("CASES", 30, true);
|
$browser->waitForText("CASES", 30, true);
|
||||||
$this->removePopups($browser);
|
$this->removePopups($browser);
|
||||||
sleep(5);
|
sleep(5);
|
||||||
@@ -53,7 +51,7 @@ class HellcaseJob extends BrowserJob implements ShouldBeUniqueUntilProcessing
|
|||||||
$this->jobRun->success = true;
|
$this->jobRun->success = true;
|
||||||
$this->jobRun->save();
|
$this->jobRun->save();
|
||||||
|
|
||||||
Log::info("HellcaseJob run ended");
|
Log::info(self::class . " run ended");
|
||||||
|
|
||||||
return $this->jobRun;
|
return $this->jobRun;
|
||||||
}
|
}
|
||||||
@@ -64,7 +62,7 @@ class HellcaseJob extends BrowserJob implements ShouldBeUniqueUntilProcessing
|
|||||||
public function runTest(Browser $browser): ?JobRun
|
public function runTest(Browser $browser): ?JobRun
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$browser->visit('https://hellcase.com');
|
$browser->visit(self::WEBSITE_URL);
|
||||||
$browser->waitForText("CASES", 30, true);
|
$browser->waitForText("CASES", 30, true);
|
||||||
$this->removePopups($browser);
|
$this->removePopups($browser);
|
||||||
sleep(2);
|
sleep(2);
|
||||||
@@ -100,14 +98,7 @@ class HellcaseJob extends BrowserJob implements ShouldBeUniqueUntilProcessing
|
|||||||
// QR CODE SCANNING
|
// QR CODE SCANNING
|
||||||
try {
|
try {
|
||||||
$browser->waitForTextIn("div", "Or sign in with QR", 30, true);
|
$browser->waitForTextIn("div", "Or sign in with QR", 30, true);
|
||||||
sleep(10);
|
$qrCode = $browser->driver->findElement(WebDriverBy::xpath('//div[./*[contains(text(), "Or sign in with QR")]]'));
|
||||||
try {
|
|
||||||
$qrCode = $browser->driver->findElement(WebDriverBy::xpath('//div[./*[contains(text(), "Or sign in with QR")]]'));
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
$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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wait to be redirected to the Steam login page, while waiting take a new screenshot every 30 seconds
|
// Wait to be redirected to the Steam login page, while waiting take a new screenshot every 30 seconds
|
||||||
$isBackOnHellcase = false;
|
$isBackOnHellcase = false;
|
||||||
@@ -132,11 +123,9 @@ class HellcaseJob extends BrowserJob implements ShouldBeUniqueUntilProcessing
|
|||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
// If the QR code is not found, we are not on the QR code page
|
// If the QR code is not found, we are not on the QR code page
|
||||||
Log::debug("Exception because qrcode not found : " . $e);
|
|
||||||
$isBackOnHellcase = true;
|
$isBackOnHellcase = true;
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
// If the QR code is not found, we are not on the QR code page
|
// If the QR code is not found, we are not on the QR code page
|
||||||
Log::debug("Exception because qrcode not found : " . $e);
|
|
||||||
$isBackOnHellcase = true;
|
$isBackOnHellcase = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -208,12 +197,9 @@ class HellcaseJob extends BrowserJob implements ShouldBeUniqueUntilProcessing
|
|||||||
if ($availibleInButton->getAttribute("disabled") == "true") {
|
if ($availibleInButton->getAttribute("disabled") == "true") {
|
||||||
$hours = $availibleInButton->getText();
|
$hours = $availibleInButton->getText();
|
||||||
// If the text is like "in 26 sec." we need to put one minute
|
// If the text is like "in 26 sec." we need to put one minute
|
||||||
if (!str_contains($hours, "hr")) {
|
if (str_contains($hours, "sec")) {
|
||||||
$browser->takeScreenshot(JobDebugScreenshot::getFileName($this->jobId));
|
$this->reschedule(1);
|
||||||
AllNotification::send(new JobDebugNotification($this->jobId, "I hate niggers"));
|
return;
|
||||||
// $this->reschedule(1);
|
|
||||||
sleep(60);
|
|
||||||
return $this->getDailyFree($browser);
|
|
||||||
}
|
}
|
||||||
$hours = explode(" ", $hours);
|
$hours = explode(" ", $hours);
|
||||||
$minutes = $hours[4];
|
$minutes = $hours[4];
|
||||||
|
@@ -4,7 +4,6 @@ namespace App\Notification;
|
|||||||
|
|
||||||
use App\Models\Job;
|
use App\Models\Job;
|
||||||
use App\Notification\Stringifiable\StringifiableSimpleText;
|
use App\Notification\Stringifiable\StringifiableSimpleText;
|
||||||
use function PHPUnit\Framework\isNull;
|
|
||||||
|
|
||||||
abstract class Notification {
|
abstract class Notification {
|
||||||
|
|
||||||
@@ -13,16 +12,10 @@ abstract class Notification {
|
|||||||
|
|
||||||
public bool $isError;
|
public bool $isError;
|
||||||
|
|
||||||
public function __construct(int $jobId, NotificationBody $body = null, bool $isError = false) {
|
public function __construct(int $jobId, NotificationBody $body, bool $isError = false) {
|
||||||
$this->job = Job::find($jobId);
|
$this->job = Job::find($jobId);
|
||||||
if (!isNull($body)) {
|
|
||||||
$this->body = $body;
|
|
||||||
}
|
|
||||||
$this->isError = $isError;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setBody(NotificationBody $body) {
|
|
||||||
$this->body = $body;
|
$this->body = $body;
|
||||||
|
$this->isError = $isError;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTitle(): Stringifiable {
|
public function getTitle(): Stringifiable {
|
||||||
|
@@ -1,53 +0,0 @@
|
|||||||
<?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();
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,31 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Notification\NotificationBody;
|
|
||||||
|
|
||||||
use App\Models\Job;
|
|
||||||
use App\Notification\NotificationBody;
|
|
||||||
use App\Notification\Stringifiable;
|
|
||||||
|
|
||||||
class JobErrorNotificationBody extends NotificationBody {
|
|
||||||
|
|
||||||
private Job $job;
|
|
||||||
private string $error;
|
|
||||||
|
|
||||||
public function __construct(Job $job, $error) {
|
|
||||||
$this->job = $job;
|
|
||||||
$this->error = $error;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @inheritDoc
|
|
||||||
*/
|
|
||||||
public function toMarkdownString(): string {
|
|
||||||
return "Le job \"{$this->job->name}\" a échoué avec l'erreur :\n ```" . $this->error . "``` \nScreenshot : ";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @inheritDoc
|
|
||||||
*/
|
|
||||||
public function toString(): string {
|
|
||||||
return "Le job \"{$this->job->name}\" a échoué avec l'erreur :\n " . $this->error;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,40 +0,0 @@
|
|||||||
<?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]);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,37 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Notification\Notifications;
|
|
||||||
|
|
||||||
use App\Browser\JobErrorScreenshot;
|
|
||||||
use App\Models\Job;
|
|
||||||
use App\Notification\Notification;
|
|
||||||
use App\Notification\NotificationBody\JobErrorNotificationBody;
|
|
||||||
use App\Notification\Stringifiable;
|
|
||||||
use App\Notification\Stringifiable\StringifiableSimpleText;
|
|
||||||
use Illuminate\Support\Facades\Log;
|
|
||||||
|
|
||||||
class JobErrorNotification extends Notification {
|
|
||||||
|
|
||||||
public function __construct(int $jobId, string $error) {
|
|
||||||
parent::__construct($jobId, isError:true);
|
|
||||||
$this->setBody(new JobErrorNotificationBody($this->job, $error));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getTitle(): Stringifiable {
|
|
||||||
return new StringifiableSimpleText("Le job {$this->job->name} a échoué");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @inheritDoc
|
|
||||||
*/
|
|
||||||
public function getImageProjectPath(): string|null {
|
|
||||||
return JobErrorScreenshot::getImgFileProjectPath($this->job->id);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @inheritDoc
|
|
||||||
*/
|
|
||||||
public function getLinkURL(): string|null {
|
|
||||||
return route('jobs.show', ['job' => $this->job->id]);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -3,6 +3,9 @@
|
|||||||
namespace App\Notification\Providers;
|
namespace App\Notification\Providers;
|
||||||
|
|
||||||
use App\Notification\NotificationProvider;
|
use App\Notification\NotificationProvider;
|
||||||
|
use App\Notification\INotificationProvider;
|
||||||
|
use App\Models\JobInfo;
|
||||||
|
use Illuminate\Support\Facades\Cache;
|
||||||
|
|
||||||
class AllNotification extends NotificationProvider {
|
class AllNotification extends NotificationProvider {
|
||||||
private const NOTIFICATIONS_PROVIDERS = [
|
private const NOTIFICATIONS_PROVIDERS = [
|
||||||
|
@@ -3,6 +3,7 @@
|
|||||||
namespace App\Notification\Providers;
|
namespace App\Notification\Providers;
|
||||||
|
|
||||||
use App\Notification\NotificationProvider;
|
use App\Notification\NotificationProvider;
|
||||||
|
use App\Notification\INotificationProvider;
|
||||||
use App\Models\JobInfo;
|
use App\Models\JobInfo;
|
||||||
use Illuminate\Support\Facades\Cache;
|
use Illuminate\Support\Facades\Cache;
|
||||||
|
|
||||||
|
@@ -13,7 +13,7 @@
|
|||||||
"erusev/parsedown": "^1.7",
|
"erusev/parsedown": "^1.7",
|
||||||
"inertiajs/inertia-laravel": "^2.0",
|
"inertiajs/inertia-laravel": "^2.0",
|
||||||
"laravel/dusk": "^8.2",
|
"laravel/dusk": "^8.2",
|
||||||
"laravel/framework": "^12.0",
|
"laravel/framework": "^11.31",
|
||||||
"laravel/reverb": "^1.0",
|
"laravel/reverb": "^1.0",
|
||||||
"laravel/sanctum": "^4.0",
|
"laravel/sanctum": "^4.0",
|
||||||
"laravel/telescope": "^5.5",
|
"laravel/telescope": "^5.5",
|
||||||
|
44
database/migrations/2025_02_27_180246_add_epic_games_job.php
Normal file
44
database/migrations/2025_02_27_180246_add_epic_games_job.php
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration {
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
$jobId = 3;
|
||||||
|
\App\Models\Job::forcecreate([
|
||||||
|
'id' => $jobId,
|
||||||
|
'name' => 'Jeu gratuit Epic Games',
|
||||||
|
'description' => 'Prends le jeu gratuit Epic games. Tourne tous les jours.',
|
||||||
|
]);
|
||||||
|
\App\Models\JobInfo::forceCreate([
|
||||||
|
"key" => "epicgames_account_email",
|
||||||
|
"name" => "E-mail",
|
||||||
|
"description" => "L'adresse e-mail utilisée pour votre compte Epic Games.",
|
||||||
|
"job_info_type_id" => 2,
|
||||||
|
"job_id" => $jobId,
|
||||||
|
], );
|
||||||
|
\App\Models\JobInfo::forceCreate([
|
||||||
|
"key" => "epicgames_account_password",
|
||||||
|
"name" => "Mot de passe",
|
||||||
|
"description" => "Le mot de passe utilisé pour votre compte Epic Games.",
|
||||||
|
"job_info_type_id" => 3,
|
||||||
|
"job_id" => $jobId,
|
||||||
|
]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
\App\Models\Job::find(3)->delete();
|
||||||
|
\App\Models\JobInfo::where('job_id', 3)->delete();
|
||||||
|
}
|
||||||
|
};
|
@@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use App\Browser\Jobs\EpicGames\EpicGamesJob;
|
||||||
use App\Browser\Jobs\Hellcase\HellcaseJob;
|
use App\Browser\Jobs\Hellcase\HellcaseJob;
|
||||||
use App\Jobs\PruneOldJobRuns;
|
use App\Jobs\PruneOldJobRuns;
|
||||||
use App\Services\BrowserJobsInstances;
|
use App\Services\BrowserJobsInstances;
|
||||||
@@ -21,3 +22,6 @@ Schedule::job(new PruneOldJobRuns)->monthly()->onOneServer()->withoutOverlapping
|
|||||||
// Jobs
|
// Jobs
|
||||||
Schedule::job(new HellcaseJob)->daily()->onOneServer()->withoutOverlapping()->name('hellcase')->description('Hellcase job');
|
Schedule::job(new HellcaseJob)->daily()->onOneServer()->withoutOverlapping()->name('hellcase')->description('Hellcase job');
|
||||||
// Schedule::job(new HellcaseJob)->everyMinute()->onOneServer()->withoutOverlapping()->name('hellcase')->description('Hellcase job');
|
// Schedule::job(new HellcaseJob)->everyMinute()->onOneServer()->withoutOverlapping()->name('hellcase')->description('Hellcase job');
|
||||||
|
|
||||||
|
Schedule::job(new EpicGamesJob())->daily()->onOneServer()->withoutOverlapping()->name('epic-games')->description('Epic Games job');
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user