Skip to content

Commit

Permalink
fix minor
Browse files Browse the repository at this point in the history
  • Loading branch information
kuaukutsu committed Dec 13, 2023
1 parent 0518bae commit e39ba19
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 18 deletions.
48 changes: 31 additions & 17 deletions src/processing/TaskProcessReady.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

namespace kuaukutsu\poc\task\processing;

use kuaukutsu\poc\task\state\TaskCommand;
use RuntimeException;
use SplQueue;
use kuaukutsu\poc\task\dto\StageModel;
use kuaukutsu\poc\task\dto\StageModelState;
use kuaukutsu\poc\task\state\TaskCommand;
use kuaukutsu\poc\task\state\TaskStateMessage;
use kuaukutsu\poc\task\state\TaskStateReady;
use kuaukutsu\poc\task\state\TaskStateRunning;
Expand Down Expand Up @@ -61,15 +61,17 @@ public function pushStageOnPause(EntityTask $task): bool
?? $this->query->findReadyByTask($uuid);

if ($stage === null) {
$this->enqueue($task, TaskCommand::stop()->toValue());
$this->enqueueCommand($task, TaskCommand::stop());
return false;
}

return $this->enqueue(
$this->enqueue(
$task,
$this->processRun($stage->uuid)->uuid,
$this->query->findPreviousCompletedByTask($uuid, $stage->order)?->uuid,
);

return true;
}

/**
Expand All @@ -80,14 +82,16 @@ public function pushStageOnReady(EntityTask $task): bool
$uuid = new EntityUuid($task->getUuid());
$stage = $this->query->findReadyByTask($uuid);
if ($stage === null) {
$this->enqueue($task, TaskCommand::stop()->toValue());
$this->enqueueCommand($task, TaskCommand::stop());
return false;
}

return $this->enqueue(
$this->enqueue(
$task,
$this->processRun($stage->uuid)->uuid,
);

return true;
}

/**
Expand All @@ -98,15 +102,17 @@ public function pushStageOnForgotten(EntityTask $task): bool
$uuid = new EntityUuid($task->getUuid());
$stage = $this->query->findForgottenByTask($uuid);
if ($stage === null) {
$this->enqueue($task, TaskCommand::stop()->toValue());
$this->enqueueCommand($task, TaskCommand::stop());
return false;
}

return $this->enqueue(
$this->enqueue(
$task,
$this->processRun($stage->uuid)->uuid,
$this->query->findPreviousCompletedByTask($uuid, $stage->order)?->uuid,
);

return true;
}

/**
Expand All @@ -120,29 +126,28 @@ public function pushStageNext(EntityTask $task, string $previous): bool
?? $this->query->findReadyByTask($uuid);

if ($stage === null) {
$this->enqueue($task, TaskCommand::stop()->toValue());
$this->enqueueCommand($task, TaskCommand::stop());
return false;
}

return $this->enqueue(
$this->enqueue(
$task,
$this->processRun($stage->uuid)->uuid,
$previous,
);

return true;
}

/**
* @throws RuntimeException Ошибка выполнения комманды
*/
public function pushStagePromise(EntityTask $task, int $limit): bool
{
$index = $this->query->indexReadyByTask(
new EntityUuid($task->getUuid()),
$limit,
);

$uuid = new EntityUuid($task->getUuid());
$index = $this->query->indexReadyByTask($uuid, $limit);
if ($index === []) {
$this->enqueue($task, TaskCommand::stop()->toValue());
$this->enqueueCommand($task, TaskCommand::stop());
return false;
}

Expand Down Expand Up @@ -173,7 +178,7 @@ public function terminate(): array
* @param non-empty-string $stage
* @param non-empty-string|null $previous
*/
private function enqueue(EntityTask $task, string $stage, ?string $previous = null): bool
private function enqueue(EntityTask $task, string $stage, ?string $previous = null): void
{
$this->queue->enqueue(
new TaskProcessContext(
Expand All @@ -183,8 +188,17 @@ private function enqueue(EntityTask $task, string $stage, ?string $previous = nu
previous: $previous,
)
);
}

return true;
private function enqueueCommand(EntityTask $task, TaskCommand $command): void
{
$this->queue->enqueue(
new TaskProcessContext(
task: $task->getUuid(),
stage: $command->toValue(),
options: $task->getOptions(),
)
);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/state/TaskCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ final class TaskCommand
/**
* @param non-empty-string $command
*/
public function __construct(private readonly string $command = '00000000-0000-0000-0000-000000000000')
public function __construct(private readonly string $command = self::COMMAND_NULL)
{
}

Expand Down

0 comments on commit e39ba19

Please sign in to comment.