Async status

Hi, I have a list of servers in my filament application, and I would like to create an action that connects to each of those servers and displays whether each server is responding or not. I know how to implement the logic to check if the servers are up or down. However, I'm unsure about how to update the list of servers with their statuses asynchronously. In other words, I don't want to wait for all servers to be checked before displaying the page. I'm thinking of something like making an AJAX call for each server individually. Could you please provide me with some guidance or ideas on how I can achieve this? Thank you!
3 Replies
JoseBravo
JoseBravoOP14mo ago
Any help will be really appreciated
3rgo
3rgo14mo ago
Is it on a list ? If so, you can maybe - have a data array with the status of each server, and initialized to null values - display the array in a column using the formatState function, - make the action check the status and update the data array, it should refresh the table Not sure this would work, but that's how I would try it
JoseBravo
JoseBravoOP14mo ago
But I don't know where I should define the data array, in the Resource where I have the table method? Or in the ListRecords page? formatStateUsing is a method that I can use within the $table->columns() function in my Resource. I assume that the data array should be an attribute of the ListRecord page, because the conent of this array should be manipulated by the action (which is other function/method) Nevermind, I think this will work like this: ->formatStateUsing(fn (string $state, Page $livewire): string => isset($livewire->states[$state]) ? $livewire->states[$state] : "Checking..." ) @3rgo the problem with this solution is that it won't update the table until the action is done. Actions\CreateAction::make(), Actions\Action::make("check_status") ->label("Check SSH status") ->action(function (array $data): void { foreach ($this->getTableRecords() as $record) { $record->sshStatus=true; sleep(1); } })

Did you find this page helpful?