Feuerwehr-eppingen/app/Console/Commands/QueueCheckup.php

56 lines
1.4 KiB
PHP

<?php
/**
* Created by PhpStorm.
* User: Marco Glietsch
* Date: 10.12.2018
* Time: 16:31
*/
namespace App\Console\Commands;
use App\Helpers\PublishHelper;
use Illuminate\Console\Command;
use App\Models\User;
use Illuminate\Contracts\Mail\Mailer;
use \Carbon\Carbon;
class QueueCheckup extends command
{
protected $signature = 'queue:checkup';
protected $description = 'Überprüft, ob die Warteschlange läuft und startet sie gegebenenfalls';
public function __construct()
{
parent::__construct();
}
public function handle(Mailer $mailer)
{
$pid = "NULL";
$path = base_path();
if(file_exists($path . '/queue.pid'))
{
// Wenn der Prozess geräade läuft, wird er zuerst beendet
$pid = file_get_contents($path . '/queue.pid');
$command = "kill $pid";
$result = exec($command);
}
// Starte den Prozess neu
$command = '/usr/bin/php -c ' . $path . '/php.ini ' . $path . '/artisan queue:listen --tries=3 > /dev/null & echo $!';
$number = exec($command);
echo Carbon::now()->format('d.m.Y H:i:s').": Warteschlange alt ($pid) -> neu ($$number)\n";
file_put_contents($path . '/queue.pid', $number);
/*
$text = "Zyklus ".Carbon::now()->format('d.m.Y H:i:s')."\n";
$mailer->raw($text, function ($message){
$message->to('m.glietsch@kortec.de')
->from('mail@marco-glietsch.de')
->subject('Zyklische Skripte');
});
*/
}
}