Skip to content

Commit 5eaab23

Browse files
authored
Merge pull request #35 from 21TORR/next
Add `DispatchAfterRunTask` and improve output of queue command
2 parents 1465187 + 03616f4 commit 5eaab23

4 files changed

Lines changed: 78 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
2.3.0
2+
=====
3+
4+
* (improvement) Always show key of task in queue tasks command.
5+
* (feature) Add `DispatchAfterRunTask` to be able to redispatch tasks after the given run. You can use it in the Scheduler to reliably redispatch tasks.
6+
7+
18
2.2.0
29
=====
310

src/Command/QueueTasksCommand.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,10 @@ private function formatTaskLabel (Task $task) : string
167167
);
168168
}
169169

170-
return $metaData->label;
170+
return \sprintf(
171+
"%s (<fg=yellow>%s</>)",
172+
$metaData->label,
173+
$metaData->getKey(),
174+
);
171175
}
172176
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Torr\TaskManager\Task\DispatchAfterRunTask;
4+
5+
use Torr\TaskManager\Task\Task;
6+
use Torr\TaskManager\Task\TaskMetaData;
7+
8+
/**
9+
* This task takes another task and puts it into the queue.
10+
*
11+
* This task is supposed to be worked on synchronously, as it is pretty lightweight and only
12+
* redispatches the given task.
13+
*/
14+
readonly class DispatchAfterRunTask extends Task
15+
{
16+
public function __construct (
17+
public Task $task,
18+
public array|string $transportNames = [],
19+
)
20+
{
21+
parent::__construct();
22+
}
23+
24+
/**
25+
*
26+
*/
27+
#[\Override]
28+
public function getMetaData () : TaskMetaData
29+
{
30+
return new TaskMetaData(
31+
\sprintf("Redispatch task '%s' after the current run", $this->task->getMetaData()->label),
32+
);
33+
}
34+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Torr\TaskManager\Task\DispatchAfterRunTask;
4+
5+
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
6+
use Symfony\Component\Messenger\Stamp\TransportNamesStamp;
7+
use Torr\TaskManager\Manager\TaskManager;
8+
9+
/**
10+
* @final
11+
*/
12+
readonly class DispatchAfterRunTaskHandler
13+
{
14+
/**
15+
*/
16+
public function __construct (
17+
private TaskManager $taskManager,
18+
) {}
19+
20+
/**
21+
*
22+
*/
23+
#[AsMessageHandler]
24+
public function onDispatchAfterRunTask (DispatchAfterRunTask $task) : void
25+
{
26+
$stamps = !empty($task->transportNames)
27+
? [new TransportNamesStamp($task->transportNames)]
28+
: [];
29+
30+
$this->taskManager->enqueue($task->task, $stamps);
31+
}
32+
}

0 commit comments

Comments
 (0)