Merhaba,
Uzun uğraşlar sonunda kilit altına alınmış dataları listeleyebildik.
Aşağıdaki ekran görüntüsünü sağlayabilmek için yapmanız gerekenler:
class ScheduleList extends Command
{
protected $signature = 'schedule:sha1List';
protected $description = 'List when scheduled commands are executed.';
/**
* @var Schedule
*/
/**
* ScheduleList constructor.
*
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*/
public function handle(Schedule $schedule)
{
$events = array_map(function ($event) {
$event->command = str_replace('php-cgi', 'php', static::fixupCommand($event->command));
return [
'cron' => $event->expression,
'command' => $event->command,
'sha1' => $event->mutexName(),
'status' => $event->mutex->exists($event)
];
}, $schedule->events());
$json = json_encode($events);
$this->line($json);
}
/**
* If it's an artisan command, strip off the PHP
*
* @param $command
* @return string
*/
protected static function fixupCommand($command): string
{
$parts = explode(' ', $command);
if (count($parts) > 2 && (strstr('artisan', $parts[1]))) {
array_shift($parts);
}
return implode(' ', $parts);
}
}
class ScheduleList extends Component
{
public function render(): Factory|View|Application
{
Artisan::call('schedule:sha1List');
$events = json_decode(Artisan::output());
$eventCounter = count($events);
for ($j = 0; $j < $eventCounter; $j++) {
$events[$j]->command = trim(explode('artisan', $events[$j]->command)[1]);
if (str_starts_with($events[$j]->command, '"') || str_starts_with($events[$j]->command, "'")) {
$events[$j]->command = trim(substr($events[$j]->command, 1, strlen($events[$j]->command)));
}
$events[$j]->statusColor = $events[$j]->status ? 'green' : 'red' ;
$events[$j]->status = $events[$j]->status ? 'Var' : 'Yok' ;
}
return view('livewire.developer.schedule-list')->with([
'events' => $events
]);
}
}
<div>
<section class="panel">
<header class="panel-heading">
Schedule Kontrol Paneli
<span class="tools pull-right">
</span>
</header>
<div class="panel-body">
<form>
<table class="table table-striped custom-table table-hover" id="token-list">
<thead>
<tr>
<th>cron</th>
<th>command</th>
<th>sha1</th>
<th>durum</th>
</tr>
</thead>
<tbody>
@foreach ($events as $event)
<tr>
<td>{{ $event->cron }}</td>
<td>{{ $event->command }}</td>
<td>{{ $event->sha1 }}</td>
<td style="text-align:center;
background-color: {{$event->statusColor }};
color: white"> {{$event->status }}</td>
</tr>
@endforeach
</tbody>
</table>
</form>
</div>
</section>
<script>
$(document).ready(function () {
$('#token-list').DataTable({
'bDestroy': true,
'processing': true,
'responsive': true,
'paging': true,
'searching': true,
'searchDelay': 1000,
'stateSave': true,
'lengthChange': true,
'lengthMenu': [[10, 25, 50, 100, -1], [10, 25, 50, 100, 'Tümü']],
'displayStart': 0,
'iDisplayStart': 0,
'iDisplayLength': 10,
'language': {
'sSearchPlaceholder': 'Ara',
'sProcessing': 'İşleniyor...',
'sLengthMenu': 'Sayfada _MENU_ Kayıt Göster',
'sZeroRecords': 'Eşleşen Kayıt Bulunmadı',
'sInfo': ' _TOTAL_ Kayıttan _START_ - _END_ Arası Kayıtlar',
'sInfoEmpty': 'Kayıt Yok',
'sInfoFiltered': '( _MAX_ Kayıt)',
'sInfoPostFix': '',
'sSearch': '',
'sUrl': '',
'oPaginate': {
'sFirst': '<i class="fa fa-angle-double-left" aria-hidden="true"></i>',
'sPrevious': '<i class="fa fa-angle-left" aria-hidden="true"></i>',
'sNext': '<i class="fa fa-angle-right" aria-hidden="true"></i>',
'sLast': '<i class="fa fa-angle-double-right" aria-hidden="true"></i>'
}
}
});
});
</script>
</div>