Skip to main content

Infrastructure

Forge Queue Worker Card code

Copy the implementation or inspect every file that belongs to this component unit.

resources/views/components/ui/forge-queue-worker-card.blade.php

@props([
    'connection' => 'redis',
    'queue' => 'default',
    'processes' => 1,
    'php' => null,
    'status' => 'Running',
    'statusVariant' => 'green',
    'memory' => null,
    'timeout' => null,
    'tries' => null,
    'sleep' => null,
    'command' => null,
])

@php
    /*
    | Laravel queue worker summary card. Surfaces Supervisor state and the key
    | queue:work options Forge users expect to inspect before restarting workers.
    |
    | Usage:
    |   <x-ui.forge-queue-worker-card connection="redis" queue="emails,default" :processes="2" />
    */
    $settings = array_filter([
        'PHP' => $php,
        'Memory' => $memory,
        'Timeout' => $timeout,
        'Tries' => $tries,
        'Sleep' => $sleep,
    ], fn ($value): bool => filled($value));

    $highlightShell = function (string $line): \Illuminate\Support\HtmlString {
        $escaped = e($line);
        $escaped = preg_replace('/(&quot;.*?&quot;|&#039;.*?&#039;)/', '<span class="tok-str">$1</span>', $escaped) ?? $escaped;
        $escaped = preg_replace('/(\$[A-Z_]+(?:\(\))?)/', '<span class="tok-var">$1</span>', $escaped) ?? $escaped;
        $escaped = preg_replace('/(^|\s)(php|composer|npm|git|sudo|cd|echo|curl|forge)(?=\s|$)/', '$1<span class="tok-fn">$2</span>', $escaped) ?? $escaped;
        $escaped = preg_replace('/(\s--?[A-Za-z0-9][A-Za-z0-9-]*)/', '<span class="tok-key">$1</span>', $escaped) ?? $escaped;
        $escaped = preg_replace('/(\b\d+(?:\.\d+)?\b)/', '<span class="tok-num">$1</span>', $escaped) ?? $escaped;

        return new \Illuminate\Support\HtmlString($escaped);
    };
@endphp

<article {{ $attributes->merge(['class' => 'min-w-0 rounded-xl border border-gray-200 bg-white p-5 shadow-sm dark:border-gray-800 dark:bg-gray-900']) }}>
    <div class="flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between sm:gap-4">
        <div class="min-w-0">
            <p class="truncate text-sm font-semibold text-gray-900 dark:text-white">Queue worker</p>
            <p class="mt-1 truncate font-mono text-xs text-gray-500 dark:text-gray-400">{{ $connection }}:{{ $queue }}</p>
        </div>

        <x-ui.badge :variant="$statusVariant" size="sm" dot>{{ $status }}</x-ui.badge>
    </div>

    <dl class="mt-5 grid gap-3 sm:grid-cols-2">
        <div class="rounded-lg bg-gray-50 p-3 dark:bg-gray-950/40">
            <dt class="text-xs text-gray-500 dark:text-gray-400">Processes</dt>
            <dd class="mt-1 text-sm font-semibold tabular-nums text-gray-900 dark:text-white">{{ $processes }}</dd>
        </div>

        @foreach ($settings as $label => $item)
            <div class="min-w-0 rounded-lg bg-gray-50 p-3 dark:bg-gray-950/40">
                <dt class="text-xs text-gray-500 dark:text-gray-400">{{ $label }}</dt>
                <dd class="mt-1 truncate text-sm font-semibold text-gray-900 dark:text-white">{{ $item }}</dd>
            </div>
        @endforeach
    </dl>

    @if ($command)
        <pre class="mt-4 max-w-full overflow-x-auto rounded-lg bg-gray-950 px-3 py-2 font-mono text-xs leading-6 text-gray-200 [&_.tok-key]:text-brand-300 [&_.tok-fn]:text-amber-300 [&_.tok-str]:text-green-300 [&_.tok-num]:text-amber-200 [&_.tok-var]:text-gray-100"><code>{!! $highlightShell($command) !!}</code></pre>
    @endif
</article>