Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(console): infer binary path for scheduler #758

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Tempest/Console/src/Initializers/SchedulerInitializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Tempest\Console\Initializers;

use Tempest\Console\ConsoleApplication;
use Tempest\Console\Input\ConsoleArgumentBag;
use Tempest\Console\Scheduler;
use Tempest\Console\Scheduler\GenericScheduler;
use Tempest\Console\Scheduler\NullScheduler;
Expand All @@ -28,6 +29,7 @@ public function initialize(Container $container): Scheduler

return new GenericScheduler(
$container->get(SchedulerConfig::class),
$container->get(ConsoleArgumentBag::class),
$container->get(ShellExecutor::class),
);
}
Expand Down
8 changes: 6 additions & 2 deletions src/Tempest/Console/src/Scheduler/GenericScheduler.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Tempest\Console\Scheduler;

use DateTime;
use Tempest\Console\Input\ConsoleArgumentBag;
use Tempest\Console\Scheduler;
use Tempest\Console\ShellExecutor;
use function Tempest\event;
Expand All @@ -15,6 +16,7 @@

public function __construct(
private SchedulerConfig $config,
private ConsoleArgumentBag $argumentBag,
private ShellExecutor $executor
) {
}
Expand All @@ -41,8 +43,10 @@ private function execute(ScheduledInvocation $invocation): void

private function compileInvocation(ScheduledInvocation $invocation): string
{
return join(' ', [
'(' . $this->config->path,
$binary = $this->argumentBag->getBinaryPath() . ' ' . $this->argumentBag->getCliName();

return implode(' ', [
'(' . $binary,
$invocation->getCommandName() . ')',
$invocation->schedule->outputMode->value,
$invocation->schedule->output,
Expand Down
2 changes: 0 additions & 2 deletions src/Tempest/Console/src/Scheduler/SchedulerConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
final class SchedulerConfig
{
public function __construct(
public string $path = "php tempest",

/** @var ScheduledInvocation[] $scheduledInvocations */
public array $scheduledInvocations = [],
) {
Expand Down
20 changes: 12 additions & 8 deletions tests/Integration/Console/Scheduler/GenericSchedulerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use DateTime;
use ReflectionMethod;
use Tempest\Console\ConsoleCommand;
use Tempest\Console\Input\ConsoleArgumentBag;
use Tempest\Console\Schedule;
use Tempest\Console\Scheduler\Every;
use Tempest\Console\Scheduler\GenericScheduler;
Expand Down Expand Up @@ -40,12 +41,13 @@ public function test_scheduler_executes_handlers(): void
);

$executor = new NullShellExecutor();
$scheduler = new GenericScheduler($config, $executor);
$argumentBag = new ConsoleArgumentBag(['tempest']);
$scheduler = new GenericScheduler($config, $argumentBag, $executor);

$scheduler->run();

$this->assertSame(
'(php tempest schedule:task Tests\\\Tempest\\\Integration\\\Console\\\Scheduler\\\GenericSchedulerTest::handler) >> /dev/null &',
'(' . PHP_BINARY . ' tempest schedule:task Tests\\\Tempest\\\Integration\\\Console\\\Scheduler\\\GenericSchedulerTest::handler) >> /dev/null &',
$executor->executedCommand,
);
}
Expand All @@ -61,11 +63,12 @@ public function test_scheduler_executes_commands(): void
);

$executor = new NullShellExecutor();
$scheduler = new GenericScheduler($config, $executor);
$argumentBag = new ConsoleArgumentBag(['tempest']);
$scheduler = new GenericScheduler($config, $argumentBag, $executor);
$scheduler->run();

$this->assertSame(
'(php tempest command) >> /dev/null &',
'(' . PHP_BINARY . ' tempest command) >> /dev/null &',
$executor->executedCommand,
);
}
Expand All @@ -81,11 +84,12 @@ public function test_scheduler_only_dispatches_the_command_in_desired_times(): v
);

$executor = new NullShellExecutor();
$scheduler = new GenericScheduler($config, $executor);
$argumentBag = new ConsoleArgumentBag(['tempest']);
$scheduler = new GenericScheduler($config, $argumentBag, $executor);
$scheduler->run($at);

$this->assertSame(
'(php tempest schedule:task Tests\\\Tempest\\\Integration\\\Console\\\Scheduler\\\GenericSchedulerTest::handler) >> /dev/null &',
'(' . PHP_BINARY . ' tempest schedule:task Tests\\\Tempest\\\Integration\\\Console\\\Scheduler\\\GenericSchedulerTest::handler) >> /dev/null &',
$executor->executedCommand,
);

Expand All @@ -97,12 +101,12 @@ public function test_scheduler_only_dispatches_the_command_in_desired_times(): v

$executor = new NullShellExecutor();

$scheduler = new GenericScheduler($config, $executor);
$scheduler = new GenericScheduler($config, $argumentBag, $executor);

$scheduler->run($at->modify('+1 minute'));

$this->assertSame(
'(php tempest schedule:task Tests\\\Tempest\\\Integration\\\Console\\\Scheduler\\\GenericSchedulerTest::handler) >> /dev/null &',
'(' . PHP_BINARY . ' tempest schedule:task Tests\\\Tempest\\\Integration\\\Console\\\Scheduler\\\GenericSchedulerTest::handler) >> /dev/null &',
$executor->executedCommand,
);
}
Expand Down
Loading