Subversion-Projekte lars-tiefland.laravel_shop

Revision

Zur aktuellen Revision | Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Illuminate\Console\Scheduling;
4
 
5
use Illuminate\Console\Command;
6
use Illuminate\Support\Carbon;
7
use Symfony\Component\Console\Attribute\AsCommand;
8
use Symfony\Component\Process\Process;
9
 
10
#[AsCommand(name: 'schedule:work')]
11
class ScheduleWorkCommand extends Command
12
{
13
    /**
14
     * The console command name.
15
     *
16
     * @var string
17
     */
18
    protected $name = 'schedule:work';
19
 
20
    /**
21
     * The name of the console command.
22
     *
23
     * This name is used to identify the command during lazy loading.
24
     *
25
     * @var string|null
26
     *
27
     * @deprecated
28
     */
29
    protected static $defaultName = 'schedule:work';
30
 
31
    /**
32
     * The console command description.
33
     *
34
     * @var string
35
     */
36
    protected $description = 'Start the schedule worker';
37
 
38
    /**
39
     * Execute the console command.
40
     *
41
     * @return void
42
     */
43
    public function handle()
44
    {
45
        $this->components->info('Running schedule tasks every minute.');
46
 
47
        [$lastExecutionStartedAt, $executions] = [null, []];
48
 
49
        while (true) {
50
            usleep(100 * 1000);
51
 
52
            if (Carbon::now()->second === 0 &&
53
                ! Carbon::now()->startOfMinute()->equalTo($lastExecutionStartedAt)) {
54
                $executions[] = $execution = new Process([
55
                    PHP_BINARY,
56
                    defined('ARTISAN_BINARY') ? ARTISAN_BINARY : 'artisan',
57
                    'schedule:run',
58
                ]);
59
 
60
                $execution->start();
61
 
62
                $lastExecutionStartedAt = Carbon::now()->startOfMinute();
63
            }
64
 
65
            foreach ($executions as $key => $execution) {
66
                $output = $execution->getIncrementalOutput().
67
                          $execution->getIncrementalErrorOutput();
68
 
69
                $this->output->write(ltrim($output, "\n"));
70
 
71
                if (! $execution->isRunning()) {
72
                    unset($executions[$key]);
73
                }
74
            }
75
        }
76
    }
77
}