Skip to content

Commit

Permalink
Merge pull request #11 from adrolli/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
adrolli authored Sep 14, 2023
2 parents 2589b22 + 2607bb9 commit b186a79
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

.DS_Store
11 changes: 11 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

use Adrolli\FilamentJobManager\Controllers\QueueController;
use Illuminate\Support\Facades\Route;

// queue:work control features
//Route::middleware(['auth'])->group(function () {
Route::get('queue/status', [QueueController::class, 'queueStatus']);
Route::get('queue/start', [QueueController::class, 'startQueue']);
Route::get('queue/stop', [QueueController::class, 'stopQueue']);
//});
49 changes: 49 additions & 0 deletions src/Controllers/QueueController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace Adrolli\FilamentJobManager\Controllers;

use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Queue;

class QueueController extends Controller
{
public function queueStatus()
{
$isRunning = Queue::isRunning('default');
dd($isRunning);
}

public function startQueue()
{
// Start the queue worker
Artisan::call('queue:work', ['--daemon' => true]);

$this->queueStatus();
}

public function stopQueue()
{
// Stop the queue worker
// Find the queue worker process ID
// $pidFilePath = storage_path('app/queue_worker.pid');
$pidFilePath = base_path('storage/app/queue_worker.pid');

$pid = file_get_contents($pidFilePath);

if ($pid) {
posix_kill($pid, SIGTERM);

// Wait for the process to exit
while (posix_kill($pid, 0)) {
usleep(100000); // Sleep for 0.1 seconds
}

$this->info("Queue worker with PID $pid has stopped.");
} else {
$this->info('No queue worker process found.');
}

$this->queueStatus();
}
}
4 changes: 2 additions & 2 deletions src/FilamentJobManagerServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public function configurePackage(Package $package): void
$package->name('filament-job-manager')
->hasConfigFile()
->hasTranslations()
->hasMigration('create_filament-job-manager_table');

->hasMigration('create_filament-job-manager_table')
->hasRoutes('web');
}
}
2 changes: 2 additions & 0 deletions src/Resources/JobsResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public static function form(Form $form): Form
public static function table(Table $table): Table
{
return $table
->poll('5s')
->deferLoading()
->columns([
TextColumn::make('status')
->badge()
Expand Down

0 comments on commit b186a79

Please sign in to comment.