Modal wont close after you create a laravel Process

I've set to run a job after I submit the Action Modal. That job creates a process. After a job is created, the modal wont close automatically, and I also cant redirect (e.g. I cant visit the dashboard). How can I fix this?
Solution:
- https://laravel.com/docs/11.x/queues#driver-prerequisites - Change queue to database in the .env - php artisan queue:listen...
Jump to solution
13 Replies
LeandroFerreira
LeandroFerreira5mo ago
how are you doing this? share some code..
Matthew
MatthewOP5mo ago
// function called with the Actions' ->after()
private function commonDownloadProcess($uri): void
{
$movieSlug = $this->movie->slug;
$directoryPath = $movieSlug; // Directory relative to the disk's root

// Ensure the directory exists
if (! Storage::disk('private')->exists($directoryPath)) {
Storage::disk('private')->makeDirectory($directoryPath, 0775, true, true);
}

DownloadTest::dispatch($uri, $directoryPath, $this->movie->id);
}
// function called with the Actions' ->after()
private function commonDownloadProcess($uri): void
{
$movieSlug = $this->movie->slug;
$directoryPath = $movieSlug; // Directory relative to the disk's root

// Ensure the directory exists
if (! Storage::disk('private')->exists($directoryPath)) {
Storage::disk('private')->makeDirectory($directoryPath, 0775, true, true);
}

DownloadTest::dispatch($uri, $directoryPath, $this->movie->id);
}
<?php

namespace App\Jobs;

// ...

class DownloadTest implements ShouldQueue
{
use Dispatchable;
use InteractsWithQueue;
use Queueable;
use SerializesModels;

protected string $uri;

protected string $directoryPath;

protected Model $movie;

public function __construct($uri, $directoryPath, $id)
{
$this->uri = $uri;
$this->directoryPath = $directoryPath;
$this->movie = Movie::find($id);
}

public function handle()
{
$uri = $this->uri;
$directoryPath = $this->directoryPath;

$command = ['aria2c', '--seed-time=0', '--allow-overwrite=true', '--summary-interval=1', $uri];
$fullDirectoryPath = Storage::disk('private')->path($directoryPath);

$process = new Process($command, $fullDirectoryPath);
$process->setTimeout(null);

try {
$process->run(function ($type, $data) {
if ($type === Process::OUT) {
// Extract progress percentage
if (preg_match('/\((\d+)%\)/', $data, $matches)) {
$progress = (int) $matches[1];
TestProgress::dispatch($progress);
} else {
TestProgress::dispatch(0);
}
}
});

$files = Storage::disk('private')->allFiles($directoryPath);
$largestFile = collect($files)->reduce(function ($carry, $file) use ($directoryPath) {
$fullPath = $directoryPath . '/' . $file;
$currentSize = Storage::disk('private')->size($fullPath);

return ($carry === null || $currentSize > $carry['size']) ? ['file' => $fullPath, 'size' => $currentSize] : $carry;
}, null);
} catch (ProcessFailedException $exception) {
// ...
}
}
}
<?php

namespace App\Jobs;

// ...

class DownloadTest implements ShouldQueue
{
use Dispatchable;
use InteractsWithQueue;
use Queueable;
use SerializesModels;

protected string $uri;

protected string $directoryPath;

protected Model $movie;

public function __construct($uri, $directoryPath, $id)
{
$this->uri = $uri;
$this->directoryPath = $directoryPath;
$this->movie = Movie::find($id);
}

public function handle()
{
$uri = $this->uri;
$directoryPath = $this->directoryPath;

$command = ['aria2c', '--seed-time=0', '--allow-overwrite=true', '--summary-interval=1', $uri];
$fullDirectoryPath = Storage::disk('private')->path($directoryPath);

$process = new Process($command, $fullDirectoryPath);
$process->setTimeout(null);

try {
$process->run(function ($type, $data) {
if ($type === Process::OUT) {
// Extract progress percentage
if (preg_match('/\((\d+)%\)/', $data, $matches)) {
$progress = (int) $matches[1];
TestProgress::dispatch($progress);
} else {
TestProgress::dispatch(0);
}
}
});

$files = Storage::disk('private')->allFiles($directoryPath);
$largestFile = collect($files)->reduce(function ($carry, $file) use ($directoryPath) {
$fullPath = $directoryPath . '/' . $file;
$currentSize = Storage::disk('private')->size($fullPath);

return ($carry === null || $currentSize > $carry['size']) ? ['file' => $fullPath, 'size' => $currentSize] : $carry;
}, null);
} catch (ProcessFailedException $exception) {
// ...
}
}
}
LeandroFerreira
LeandroFerreira5mo ago
where is the action?
Matthew
MatthewOP5mo ago
Oops, sorry, I forgot to add it
// This function is called from blade
public function testAction(): Action
{
return Action::make('test')
->steps([
// ...
])
->after(function ($record, $data) {
$this->commonDownloadProcess('...');
});
}
// This function is called from blade
public function testAction(): Action
{
return Action::make('test')
->steps([
// ...
])
->after(function ($record, $data) {
$this->commonDownloadProcess('...');
});
}
<button wire:click="mountAction('test', { id: 12345 })"
class="h-10 w-full bg-green-700 font-bold hover:bg-green-800">Test Function
</button>
<button wire:click="mountAction('test', { id: 12345 })"
class="h-10 w-full bg-green-700 font-bold hover:bg-green-800">Test Function
</button>
LeandroFerreira
LeandroFerreira5mo ago
did you add the ->action(function() { } ) method?
Matthew
MatthewOP5mo ago
Nope. Just steps() and after(). You think its better if I add it there?
LeandroFerreira
LeandroFerreira5mo ago
try this
Matthew
MatthewOP5mo ago
I tried action(), and its the same It seems that no request is processed until the process I created is completed
LeandroFerreira
LeandroFerreira5mo ago
not related, but why aren't you rendering the action using this?
{{ ($this->testAction)(['id' => 12345]) }}
{{ ($this->testAction)(['id' => 12345]) }}
https://filamentphp.com/docs/3.x/actions/adding-an-action-to-a-livewire-component#passing-action-arguments
Matthew
MatthewOP5mo ago
Ah, because I want to use my custom button for it I dont want the default button
Solution
Matthew
Matthew5mo ago
- https://laravel.com/docs/11.x/queues#driver-prerequisites - Change queue to database in the .env - php artisan queue:listen
Matthew
MatthewOP5mo ago
This solved it!
Matthew
MatthewOP5mo ago
Not a filament issue after all 🤷‍♂️
Want results from more Discord servers?
Add your server