Skip to content

Commit

Permalink
Merge pull request #4 from Pharaonic/executor-pool
Browse files Browse the repository at this point in the history
Feat: enable create multiple pools of executors
  • Loading branch information
MoamenEltouny authored Jul 29, 2024
2 parents c1a9c28 + f81bc93 commit 9eb72f4
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 1 deletion.
40 changes: 40 additions & 0 deletions src/Classes/ExecutorPoolClass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace Pharaonic\Laravel\Executor\Classes;

class ExecutorPoolClass
{
/**
* These paths for all pools of executors.
*/
private array $paths = [];

public function __construct()
{
$this->paths = [
base_path('executors'),
];
}

/**
* Return all pools of executors.
*
* @return array
*/
public function getPaths(): array
{
return $this->paths;
}

/**
* Add a new path to executors pools.
*
* @param string $path
*
* @return void
*/
public function addPath(string $path): void
{
array_push($this->paths, $path);
}
}
11 changes: 11 additions & 0 deletions src/ExecutorServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Pharaonic\Laravel\Executor;

use Illuminate\Support\ServiceProvider;
use Pharaonic\Laravel\Executor\Classes\ExecutorPoolClass;
use Pharaonic\Laravel\Executor\Console\ExecuteCommand;
use Pharaonic\Laravel\Executor\Console\ExecuteFreshCommand;
use Pharaonic\Laravel\Executor\Console\ExecuteMakeCommand;
Expand All @@ -11,6 +12,16 @@

class ExecutorServiceProvider extends ServiceProvider
{
/**
* Register services.
*
* @return void
*/
public function register()
{
$this->app->singleton('pharaonic.executor.executorPool', ExecutorPoolClass::class);
}

/**
* Bootstrap services.
*
Expand Down
13 changes: 13 additions & 0 deletions src/Facades/ExecutorPool.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Pharaonic\Laravel\Executor\Facades;

use Illuminate\Support\Facades\Facade;

class ExecutorPool extends Facade
{
protected static function getFacadeAccessor()
{
return 'pharaonic.executor.executorPool';
}
}
14 changes: 13 additions & 1 deletion src/Services/ExecutorService.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Pharaonic\Laravel\Executor\Services;

use Illuminate\Support\Facades\File;
use Pharaonic\Laravel\Executor\Facades\ExecutorPool;
use Pharaonic\Laravel\Executor\Models\Executor;
use ReflectionClass;

Expand Down Expand Up @@ -61,7 +62,7 @@ protected function prepareExecutors()
}
}
return $executor;
}, File::glob($this->dir . '/*')))->keyBy('name');
}, $this->collectAllPaths()))->keyBy('name');
}


Expand Down Expand Up @@ -102,4 +103,15 @@ protected function getNextBatch()
{
return (Executor::orderBy('batch', 'desc')->first()?->batch ?? 0) + 1;
}

private function collectAllPaths()
{
$collectPath = collect([]);

foreach (ExecutorPool::getPaths() as $path) {
$collectPath = $collectPath->merge(File::glob($path . '/*'));
}

return $collectPath->all();
}
}

0 comments on commit 9eb72f4

Please sign in to comment.