Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
2.3.0
=====

* (improvement) Always show key of task in queue tasks command.
* (feature) Add `DispatchAfterRunTask` to be able to redispatch tasks after the given run. You can use it in the Scheduler to reliably redispatch tasks.


2.2.0
=====

Expand Down
6 changes: 5 additions & 1 deletion src/Command/QueueTasksCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ private function formatTaskLabel (Task $task) : string
);
}

return $metaData->label;
return \sprintf(
"%s (<fg=yellow>%s</>)",
$metaData->label,
$metaData->getKey(),
);
}
}
34 changes: 34 additions & 0 deletions src/Task/DispatchAfterRunTask/DispatchAfterRunTask.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php declare(strict_types=1);

namespace Torr\TaskManager\Task\DispatchAfterRunTask;

use Torr\TaskManager\Task\Task;
use Torr\TaskManager\Task\TaskMetaData;

/**
* This task takes another task and puts it into the queue.
*
* This task is supposed to be worked on synchronously, as it is pretty lightweight and only
* redispatches the given task.
*/
readonly class DispatchAfterRunTask extends Task
{
public function __construct (
public Task $task,
public array|string $transportNames = [],
)
{
parent::__construct();
}

/**
*
*/
#[\Override]
public function getMetaData () : TaskMetaData
{
return new TaskMetaData(
\sprintf("Redispatch task '%s' after the current run", $this->task->getMetaData()->label),
);
}
}
32 changes: 32 additions & 0 deletions src/Task/DispatchAfterRunTask/DispatchAfterRunTaskHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php declare(strict_types=1);

namespace Torr\TaskManager\Task\DispatchAfterRunTask;

use Symfony\Component\Messenger\Attribute\AsMessageHandler;
use Symfony\Component\Messenger\Stamp\TransportNamesStamp;
use Torr\TaskManager\Manager\TaskManager;

/**
* @final
*/
readonly class DispatchAfterRunTaskHandler
{
/**
*/
public function __construct (
private TaskManager $taskManager,
) {}

/**
*
*/
#[AsMessageHandler]
public function onDispatchAfterRunTask (DispatchAfterRunTask $task) : void
{
$stamps = !empty($task->transportNames)
? [new TransportNamesStamp($task->transportNames)]
: [];

$this->taskManager->enqueue($task->task, $stamps);
}
}