Skip to content

Commit

Permalink
Live update queue charts
Browse files Browse the repository at this point in the history
  • Loading branch information
jessarcher committed Oct 6, 2023
1 parent 521523b commit 078e344
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
19 changes: 18 additions & 1 deletion resources/views/livewire/queues.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,25 @@ class="h-12 mt-1"
},
}
)
Livewire.on('queues-chart-update', ({ queues }) => {
if (chart === undefined) {
return
}
if (queues['{{ $queue }}'] === undefined && chart) {
chart.destroy()
chart = undefined
return
}
chart.data.labels = queues['{{ $queue }}'].map(reading => reading.date)
chart.data.datasets[0].data = queues['{{ $queue }}'].map(reading => reading.queued)
chart.data.datasets[1].data = queues['{{ $queue }}'].map(reading => reading.processed)
chart.data.datasets[2].data = queues['{{ $queue }}'].map(reading => reading.failed)
chart.update()
})
}
// TODO: Live update chart
}"
>
<canvas x-ref="canvas" class="w-full ring-1 ring-gray-900/10 dark:ring-gray-100/10 bg-white dark:bg-gray-800 rounded-md shadow-sm"></canvas>
Expand Down
4 changes: 4 additions & 0 deletions src/Livewire/Queues.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ public function render(QueuesQuery $query): Renderable
{
[$queues, $time, $runAt] = $this->remember($query);

if (request()->hasHeader('X-Livewire')) {
$this->dispatch('queues-chart-update', queues: $queues);
}

return View::make('pulse::livewire.queues', [
'queues' => $queues,
'showConnection' => $queues->keys()->map(fn ($queue) => Str::before($queue, ':'))->unique()->count() > 1,
Expand Down

0 comments on commit 078e344

Please sign in to comment.