Skip to content

Commit

Permalink
Run cronjob in docker compose
Browse files Browse the repository at this point in the history
The cronjob will be executed in the docker container if no studip directory exists on the host.
  • Loading branch information
dennis531 committed Dec 12, 2024
1 parent e98f7a8 commit 3191024
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions tests/_support/Helper/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,16 @@ public function seeVideoIsProcessed($id): bool {
*/
public function runCronjob(string $cronjob)
{
$studip_cli = self::STUDIP_DIR . "cli/studip";
exec(
"php $studip_cli cronjobs:execute $(php $studip_cli cronjobs:list | grep '$cronjob' | awk '{print $1}')",
$output,
$result_code
);
if (is_dir(self::STUDIP_DIR)) {
// Run cronjob on host if studip code exist
$studip_cli = self::STUDIP_DIR . "cli/studip";
$command = "php $studip_cli cronjobs:execute $(php $studip_cli cronjobs:list | grep '$cronjob' | awk '{print $1}')";
} else {
// Run cronjob in docker container
$compose_file = __DIR__ . '/../../../.github/docker/docker-compose.yml';
$command = "docker compose -f $compose_file exec studip bash -c \"php ./cli/studip cronjobs:execute \\$(php ./cli/studip cronjobs:list | grep '$cronjob' | awk '{print \\$1}')\"";
}
exec($command, $output, $result_code);

$this->assertEquals(0, $result_code, 'Cronjob run successful');
}
Expand Down

0 comments on commit 3191024

Please sign in to comment.