-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
243 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace Aternos\Taskmaster\Task; | ||
|
||
/** | ||
* Class CloneTaskFactory | ||
* | ||
* The CloneTaskFactory creates clones of a task. | ||
* | ||
* @package Aternos\Taskmaster\Task | ||
*/ | ||
class CloneTaskFactory extends TaskFactory | ||
{ | ||
protected int $count = 0; | ||
|
||
/** | ||
* @param TaskInterface $task | ||
* @param int|null $limit | ||
*/ | ||
public function __construct(protected TaskInterface $task, protected ?int $limit = null) | ||
{ | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function createNextTask(?string $group): ?TaskInterface | ||
{ | ||
if ($this->limit !== null && $this->count >= $this->limit) { | ||
return null; | ||
} | ||
$this->count++; | ||
return clone $this->task; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace Aternos\Taskmaster\Task; | ||
|
||
use Aternos\Taskmaster\Task\TaskFactory; | ||
|
||
/** | ||
* Class InstanceTaskFactory | ||
* | ||
* The InstanceTaskFactory creates instances of a task class. | ||
* | ||
* @package Aternos\Taskmaster\Task | ||
*/ | ||
class InstanceTaskFactory extends TaskFactory | ||
{ | ||
protected int $count = 0; | ||
|
||
/** | ||
* @param class-string<TaskInterface> $taskClass | ||
* @param int|null $limit | ||
*/ | ||
public function __construct(protected string $taskClass, protected ?int $limit = null) | ||
{ | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function createNextTask(?string $group): ?TaskInterface | ||
{ | ||
if ($this->limit !== null && $this->count >= $this->limit) { | ||
return null; | ||
} | ||
$this->count++; | ||
return new $this->taskClass(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace Aternos\Taskmaster\Test\Util\Task; | ||
|
||
use Aternos\Taskmaster\Task\OnChild; | ||
use Aternos\Taskmaster\Task\Task; | ||
|
||
class InitTask extends Task | ||
{ | ||
public static bool $initialized = false; | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
#[OnChild] | ||
public function run(): void | ||
{ | ||
static::$initialized = true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace Aternos\Taskmaster\Test\Util\Task; | ||
|
||
use Aternos\Taskmaster\Task\OnChild; | ||
use Aternos\Taskmaster\Task\Task; | ||
|
||
class InitValidateTask extends Task | ||
{ | ||
/** | ||
* @inheritDoc | ||
*/ | ||
#[OnChild] | ||
public function run(): bool | ||
{ | ||
return InitTask::$initialized; | ||
} | ||
} |