mortenscheel/task-flow
Composer 安装命令:
composer require mortenscheel/task-flow
包简介
Pipeline for nested console tasks
README 文档
README
Task Flow
Build dynamic nested console workflows with ease.
Installation
You can install the package via composer:
composer require mortenscheel/task-flow
Getting started
Example flow
Laravel example
use Scheel\TaskFlow\Context; use Scheel\TaskFlow\Facades\TaskFlow; use Scheel\TaskFlow\Task; TaskFlow::run([ Task::make('Closure', function (Context $context) { // Do stuff usleep(500000); // Set context data for future tasks $context->set('foo', true); }), Task::make('Conditional', function (Context $context) { // Read context data from previous tasks if ($context->get('foo')) { // Skip current task, including child tasks $context->skip(); } }), // Task action can be an invokable class Task::make('Invokable', new SomeInvokable), Task::make('Nested tasks', children: [ Task::make('Subtask 1', $this->classMethod(...)), Task::make('Subtask 2', children: [ Task::make('Subtask 2.1', children: [ Task::make('Subtask 2.1.1', fn () => sleep(1)), Task::make('Subtask 2.1.2', fn () => sleep(1)), ]), Task::make('Subtask 2.2', fn () => sleep(1)), ]), ]), Task::make('Final task', fn () => sleep(1)), ]);
Standalone example
use Scheel\TaskFlow\Renderer\ConsoleRenderer; use Scheel\TaskFlow\Task; use Scheel\TaskFlow\TaskManager; use Symfony\Component\Console\Output\ConsoleOutput; // The TaskManager has to be constructed manually $manager = new TaskManager(new ConsoleRenderer(new ConsoleOutput())); // But the rest of the API is the same, whether you use Laravel or not $manager->run([ Task::make('Task 1', fn (): null => null), Task::make('Task 2', children: [ Task::make('Task 2.1', fn (): null => null), Task::make('Task 2.2', children: [ Task::make('Task 2.2.1', fn () => fn(): null => null), ]), ]), Task::make('Task 3', fn (): null => null), ]);
Configuration
The default configuration is as follows:
[
'indent' => 2,
'symbols' => [
'pending' => '…',
'running' => '▶',
'completed' => '✓',
'skipped' => '⏭',
'failed' => '✗',
],
'colors' => [
'pending' => 'gray',
'running' => 'bright-white',
'completed' => 'green',
'skipped' => 'yellow',
'failed' => 'red',
],
]
Laravel
You can publish the config file with:
php artisan vendor:publish --provider="Scheel\TaskFlow\TaskFlowServiceProvider" --tag="config"
Standalone
You can pass a custom configuration array to the ConsoleRenderer constructor:
$manager = new TaskManager(new ConsoleRenderer(new ConsoleOutput(), [ 'symbols' => [ 'pending' => '💤', 'running' => '🏃♂️️', 'completed' => '🎉', 'failed' => '😭', 'skipped' => '⏩', ] ]));
Task Context
The Context is a shared object, which is passed to all task actions.
set(string $key, mixed $value): void- Set a value in the context for use by future tasks.get(string $key): mixed- Get a value from the context, provided by previous tasks.has(string $key): bool- Check if a key exists in the context.increment(string $key, int $amount = 1): void- Increment a value in the context.skip(): void- Skip the current task, including all child tasks.updateTitle(string $title): void- Update the title of the current task.abort(): void- Abort the entire task flow. This has the same effect as throwing an exception.interactive(callable $callback): mixed- Allows for user interaction, without interfering with the task flow status output.
mortenscheel/task-flow 适用场景与选型建议
mortenscheel/task-flow 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3 次下载、GitHub Stars 达 8, 最近一次更新时间为 2024 年 12 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「console」 「renderer」 「pipeline」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 mortenscheel/task-flow 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mortenscheel/task-flow 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 mortenscheel/task-flow 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This class provides you with an easy-to-use interface to progress bars.
A Laravel package to retrieve data from Google Search Console
Additional artisan commands for Laravel
Bootstraps errors and handles them via reporters and renderers
A table generator class for the PHP CLI.
Extremely simple and standard compliant view implementation of MVC pattern
统计信息
- 总下载量: 3
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 8
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-12-29
