承接 sunvalley-technologies/php-task-manager-symfony-bundle 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

sunvalley-technologies/php-task-manager-symfony-bundle

Composer 安装命令:

composer require sunvalley-technologies/php-task-manager-symfony-bundle

包简介

Symfony bundle for PHP Task Manager

README 文档

README

Build Status

See main repository for base usage

This bundle integrates the task manager to Symfony. Supports Symfony ^3.0 and ^4.0.

Installing

composer require sunvalley-technologies/php-task-manager-symfony-bundle

Make sure to add the bundle to your Kernel's bundles.

Configuration

Complete configuration looks like following:

php_task_manager:
    task_queue: redis://127.0.0.1:6379
    task_storage: redis://127.0.0.1:6379
    pool:
        minimum_processes: 1
        maximum_processes: 10
        time_to_live: 60
        max_jobs_per_process: 10

From which task_queue is the only required configuration parameter.

task_storage is optional and if given is used to store task information.

If you have a non-standard Kernel have a look and replace the SunValley\TaskManager\Symfony\Task\TaskEnvironment class and AbstractSymfonyTask to provide a proper Kernel for your tasks.

Generating and Submitting Tasks

It is necessary to generate tasks to control exactly what each task is doing. This can be thought like generating controllers.

All kernel dependent classes should extend AbstractSymfonyTask and they are synchronous tasks by default.

Here is a sample task that persist a doctrine entity:

<?php

class ExampleTask extends \SunValley\TaskManager\Symfony\Task\AbstractSymfonyTask {
    


    protected function __run(\SunValley\TaskManager\ProgressReporter $reporter,\Symfony\Component\DependencyInjection\ContainerInterface $container){
        $data = $this->getOptions()['data'];
        $entityManager = $container->get('entity_manager');
        $entity = $entityManager->find('\Some\Entity');
        $entity->setData($data);
        $entityManager->persist($entity);
        $entityManager->flush();

        return 'Task Completed'; // will be passed as $result to $reporter->finishTask($result) if it is not called or failed before 
    }

    public function buildOptionsResolver() : \Symfony\Component\OptionsResolver\OptionsResolver{
        $resolver = new Symfony\Component\OptionsResolver\OptionsResolver();
        $resolver->setRequired('data');
        return $resolver;
    }

}

class MyService {
    use \Symfony\Component\DependencyInjection\ContainerAwareTrait;

    public function changeDataOnBackground($data) {
        $task = new ExampleTask(uniqid('', true), ['data' => $data]); // this can throw an exception if options are invalid
        $this->container->get('php_task_manager_client')->submitTaskSync($task);
    }
}

class MyAsyncService {

    /** @var \SunValley\TaskManager\Symfony\Task\TaskManagerFactory */
    private $taskManagerFactory;

    public function __construct($taskManagerFactory) { $this->taskManagerFactory = $taskManagerFactory; }

    public function changeDataOnBackground($data): \React\Promise\PromiseInterface {
        $task = new ExampleTask(uniqid('', true), ['data' => $data]); // this can throw an exception if options are invalid

        return $this->taskManagerFactory->generate()->submitTask($task);
    }
}

The call to finishTask or failTask is optional unlike on plain task manager tasks. Any exception that is thrown however is caught and reported back with failTask($error).

To submit a task, the task should be constructed and then it can be submitted with the client as on the example service above.

Task constructors should never block otherwise the main task manager loop can also get blocked.

Starting task manager

Console command task:manager can be used to start the task manager.

In order to attach to your running loops that you also started with Symfony there is a factory for task manager SunValley\TaskManager\Symfony\Task\TaskManagerFactory.

Task manager uses the loop php_task_manager_loop defined in its configuration by default.

Many of these can be changed with a compiler pass in case a customization is necessary.

Other Topics

Doctrine Entity Repository Task

\SunValley\TaskManager\Symfony\Doctrine\EntityRepositoryTask task can be used to offload synchronous doctrine calls to background for async apps. This task does not make sense for usual work queues but can be useful for async apps that partially depend on doctrine for ORM access.

sunvalley-technologies/php-task-manager-symfony-bundle 适用场景与选型建议

sunvalley-technologies/php-task-manager-symfony-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7.78k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 11 月 18 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 sunvalley-technologies/php-task-manager-symfony-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 sunvalley-technologies/php-task-manager-symfony-bundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 sunvalley-technologies/php-task-manager-symfony-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 7.78k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-11-18