• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tempestphp / tempest-framework / 14024978163

23 Mar 2025 05:55PM UTC coverage: 79.391% (-0.05%) from 79.441%
14024978163

push

github

web-flow
feat(view): cache Blade and Twig templates in internal storage (#1061)

2 of 2 new or added lines in 2 files covered. (100.0%)

912 existing lines in 110 files now uncovered.

10478 of 13198 relevant lines covered (79.39%)

91.09 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Tempest/CommandBus/src/MonitorAsyncCommands.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Tempest\CommandBus;
6

7
use DateTimeImmutable;
8
use Symfony\Component\Process\Process;
9
use Tempest\Console\Console;
10
use Tempest\Console\ConsoleCommand;
11
use Tempest\Console\HasConsole;
12
use Tempest\Console\Input\ConsoleArgumentBag;
13

14
use function Tempest\Support\arr;
15

16
final readonly class MonitorAsyncCommands
17
{
18
    use HasConsole;
19

UNCOV
20
    public function __construct(
×
21
        private CommandRepository $repository,
22
        private ConsoleArgumentBag $argumentBag,
23
        private Console $console,
24
    ) {
UNCOV
25
    }
×
26

UNCOV
27
    #[ConsoleCommand(name: 'command:monitor', description: 'Monitors and executes pending async commands')]
×
28
    public function __invoke(): void
29
    {
UNCOV
30
        $this->info('Monitoring for new commands. Press <em>Ctrl+C</em> to stop.');
×
UNCOV
31
        $this->writeln();
×
32

33
        /** @var \Symfony\Component\Process\Process[] $processes */
34
        $processes = [];
×
35

36
        while (true) { // @phpstan-ignore-line
×
UNCOV
37
            foreach ($processes as $uuid => $process) {
×
38
                if ($process->isTerminated()) {
×
39
                    if ($process->isSuccessful()) {
×
40
                        $this->console->keyValue(
×
UNCOV
41
                            key: "<style='fg-gray'>{$uuid}</style>",
×
42
                            value: "<style='fg-green bold'>SUCCESS</style>",
×
UNCOV
43
                        );
×
44
                    } else {
45
                        $this->console->keyValue(
×
46
                            key: "<style='fg-gray'>{$uuid}</style>",
×
UNCOV
47
                            value: "<style='fg-red bold'>FAILED</style>",
×
UNCOV
48
                        );
×
49
                    }
50

UNCOV
51
                    if ($output = trim($process->getOutput())) {
×
UNCOV
52
                        $this->writeln($output);
×
53
                    }
54

UNCOV
55
                    if ($errorOutput = trim($process->getErrorOutput())) {
×
UNCOV
56
                        $this->writeln($errorOutput);
×
57
                    }
58

UNCOV
59
                    unset($processes[$uuid]);
×
60
                }
61
            }
62

63
            $availableCommands = arr($this->repository->getPendingCommands())
×
UNCOV
64
                ->filter(fn (object $_, string $uuid) => ! array_key_exists($uuid, $processes));
×
65

66
            if (count($processes) === 5) {
×
67
                $this->sleep(0.5);
×
68

69
                continue;
×
70
            }
71

UNCOV
72
            if ($availableCommands->isEmpty()) {
×
73
                $this->sleep(0.5);
×
74

75
                continue;
×
76
            }
77

78
            // Start a task
79
            $uuid = $availableCommands->keys()->first();
×
80

81
            $time = new DateTimeImmutable();
×
82
            $this->console->keyValue(
×
83
                key: $uuid,
×
UNCOV
84
                value: "<style='fg-gray'>{$time->format('Y-m-d H:i:s')}</style>",
×
85
            );
×
86

87
            $process = new Process([
×
UNCOV
88
                $this->argumentBag->getBinaryPath(),
×
UNCOV
89
                $this->argumentBag->getCliName(),
×
UNCOV
90
                'command:handle',
×
91
                $uuid,
×
UNCOV
92
            ], getcwd());
×
93

UNCOV
94
            $process->start();
×
95

UNCOV
96
            $processes[$uuid] = $process;
×
97
        }
98
    }
99

UNCOV
100
    private function sleep(float $seconds): void
×
101
    {
UNCOV
102
        usleep((int) ($seconds * 1_000_000));
×
103
    }
104
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc