Skip to content

Commit

Permalink
tec: Execute Cleaner job at 01:00 AM
Browse files Browse the repository at this point in the history
The jobs have been reset during the last refactor.
The Cleaner job was mean't to be executed at 1:00 AM, but it wasn't done
correctly.
  • Loading branch information
marienfressinaud committed Aug 3, 2023
1 parent 40a62c3 commit 1f53340
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/jobs/scheduled/Cleaner.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ public static function install(): void
$cleaner_job = new self();

if (!\Minz\Job::existsBy(['name' => $cleaner_job->name])) {
$cleaner_job->performAsap();
$perform_at = \Minz\Time::relative('tomorrow 1:00');
$cleaner_job->performLater($perform_at);
}
}

public function __construct()
{
parent::__construct();
$this->perform_at = \Minz\Time::relative('tomorrow 1:00');
$this->frequency = '+1 day';
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace flusio\migrations;

class Migration202308030001UpdatePerformAtOfCleanerJob
{
public function migrate(): bool
{
$database = \Minz\Database::get();

$statement = $database->prepare(<<<'SQL'
UPDATE jobs
SET perform_at = ?
WHERE name = 'flusio\jobs\scheduled\Cleaner';
SQL);

$perform_at = \Minz\Time::relative('tomorrow 1:00');
$statement->execute([
$perform_at->format(\Minz\Database\Column::DATETIME_FORMAT),
]);

return true;
}

public function rollback(): bool
{
// Do nothing on purpose
return true;
}
}
5 changes: 0 additions & 5 deletions tests/jobs/scheduled/CleanerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ public function testSchedule(): void

$cleaner_job = new Cleaner();

$expected_perform_at = \Minz\Time::relative('tomorrow 1:00');
$this->assertSame(
$expected_perform_at->getTimestamp(),
$cleaner_job->perform_at->getTimestamp()
);
$this->assertSame('+1 day', $cleaner_job->frequency);
}

Expand Down

0 comments on commit 1f53340

Please sign in to comment.