Added job artifacts, dealing with cancelled battle & fixed and improved notification
All checks were successful
Push image to registry / build-image (push) Successful in 4m29s
All checks were successful
Push image to registry / build-image (push) Successful in 4m29s
This commit is contained in:
@ -6,6 +6,7 @@ use App\Browser\JobDebugScreenshot;
|
||||
use App\Browser\Jobs\Hellcase\HellcaseJob;
|
||||
use App\Models\HellcaseBattle;
|
||||
use App\Models\Job;
|
||||
use App\Models\JobArtifact;
|
||||
use App\Models\JobRun;
|
||||
use App\Notification\Notifications\JobDebugNotification;
|
||||
use App\Notification\Providers\AllNotification;
|
||||
@ -21,6 +22,7 @@ class HellcaseBattlesJob extends HellcaseJob implements ShouldBeUniqueUntilProce
|
||||
{
|
||||
private Collection $jobInfos;
|
||||
private array $battlesToAdd = [];
|
||||
private array $battlesSent = [];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
@ -48,8 +50,16 @@ class HellcaseBattlesJob extends HellcaseJob implements ShouldBeUniqueUntilProce
|
||||
|
||||
$this->sendFinishedBattles($browser);
|
||||
|
||||
$this->jobRun->addArtifact(new JobArtifact([
|
||||
"name" => count($this->battlesSent) . " battailles envoyées",
|
||||
]));
|
||||
|
||||
$this->createNewBattles();
|
||||
|
||||
$this->jobRun->addArtifact(new JobArtifact([
|
||||
"name" => count($this->battlesToAdd) . " nouvelles battailles ajoutées pour surveillage",
|
||||
]));
|
||||
|
||||
$this->jobRun->success = true;
|
||||
$this->jobRun->save();
|
||||
|
||||
@ -103,9 +113,13 @@ class HellcaseBattlesJob extends HellcaseJob implements ShouldBeUniqueUntilProce
|
||||
$battleLinkButton = $battle->findElement(WebDriverBy::xpath('./div//button[text() = "watch"]'));
|
||||
$battleLinkButton->sendKeys("\n");
|
||||
sleep(3);
|
||||
$battleLink = $browser->driver->getCurrentURL();
|
||||
try { // If we still are on the casebattle page, it means the battle was cancelled or something else
|
||||
$browser->waitForLocation("https://hellcase.com/casebattle/", 3);
|
||||
} catch (Exception $e) {
|
||||
$battleLink = $browser->driver->getCurrentURL();
|
||||
|
||||
$this->battlesToAdd[$battleLink] = $battleValue;
|
||||
$this->battlesToAdd[$battleLink] = $battleValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -115,11 +129,12 @@ class HellcaseBattlesJob extends HellcaseJob implements ShouldBeUniqueUntilProce
|
||||
if (!array_key_exists($battle->getUrl(), $this->battlesToAdd)) {
|
||||
$browser->visit($battle->getUrl());
|
||||
|
||||
try {
|
||||
$browser->waitForText("Started at");
|
||||
sleep(2);
|
||||
$browser->waitForText("Case Battle");
|
||||
|
||||
if ($this->findElementContainingText($browser, "Started at:") != null) { // battle is finished
|
||||
// Send the battle
|
||||
$this->sendBattle($browser, $battle);
|
||||
} catch (Exception $e) { // Battle is not finished or error (like battle cancelled)
|
||||
}
|
||||
|
||||
$battle->delete();
|
||||
@ -128,7 +143,16 @@ class HellcaseBattlesJob extends HellcaseJob implements ShouldBeUniqueUntilProce
|
||||
}
|
||||
|
||||
private function sendBattle(Browser $browser, HellcaseBattle $battle) {
|
||||
AllNotification::send(new JobDebugNotification($this->jobId, "Battle sent" . $battle->getUrl(), screenshotProjectPath:null));
|
||||
try {
|
||||
$battleHeader = $browser->driver->findElement(WebDriverBy::xpath("//*[contains(@class, 'case-battle-game__header')]"));
|
||||
sleep(2); // Wait for the animations to finish
|
||||
$battleHeader->takeElementScreenshot(HellcaseBattleScreenshot::getImgFileAbsolutePath());
|
||||
} catch (Exception $e) {
|
||||
$browser->screenshot(JobDebugScreenshot::getFileName($this->jobId));
|
||||
AllNotification::send(new JobDebugNotification($this->jobId, "Failed to screenshot battle"));
|
||||
}
|
||||
$this->battlesSent[$battle->getUrl()] = $battle->value;
|
||||
AllNotification::send(new HellcaseBattlesNofication($this->jobId, $battle));
|
||||
}
|
||||
|
||||
private function createNewBattles() {
|
||||
|
Reference in New Issue
Block a user