承接 bprs/commandline-bundle 相关项目开发

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

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

bprs/commandline-bundle

Composer 安装命令:

composer require bprs/commandline-bundle

包简介

Allows command execution (jobs) in background worker. This is a blend between chrisboulton php-resque, vend/resque and additional features.

README 文档

README

Special Thanks

This bundle would not be possible if not for the great work of many developers out there. Especially The people behind the php-resque library (https://github.com/chrisboulton/php-resque) and the people from the vend/resque bundle (https://github.com/vend/php-resque)!

About

This bundle allows symfony projects to execute long running tasks (jobs) in the background (for example video encoding, transferring big files from and to cloudservices, etc). Jobs are container aware, log information with monolog and workers can be started (and stopped) from the web or commandline.

This library needs a running redis database and connection.

Installation

composer require bprs/commandline-bundle
$bundles = array(
    ...
    new Bprs\CommandLineBundle\BprsCommandLineBundle(),
    ...

You'll need redis and the redis php extension.

Configuration

# app/config/config.yml

bprs_command_line:
    php_path: #path to the php that should be used to launch a worker. default: php
    worker_queue: #the default queue for jobs and worker to use. should be unique. default: *
    redis_backend: #the connection url. default: tcp://localhost:6379

Usage

Start redis

You'll need a running redis database.

app/console bprs:commandline:start_worker QUEUENAME (--interval=5)
#starts a worker listening to the given queuename in given interval
#you can follow the log in apps/log/dev.log or prod.log

app/console bprs:commandline:stop_worker (--force)
#stops all worker after they finish the current job (graceful stop)
# --force will use kill -9

app/console bprs:commandline:add_job JOBNAME QUEUENAME argument1:arg, argument2:arg, ... argumentN:arg
#schedules a given job in a given queue with an array of given arguments
#example
app/console bprs:commandline:add_job Bprs\\CommandlineBundle\\Model\\GreetJob default name:BPRS

app/console bprs:commandline:list_jobs --queue=QUEUE
#lists all jobs in given queue. You can use the indexnumber and stop_job to remove a job from the queue

app/console bprs:commandline:list_worker
# lists all known worker. Can contain ungraceful stopped worker as well.

Advanced usage

Of course, you can manipulate all the workers with POSIX reliable signals.

app/console bprs:commandline:list_worker

lists all workers on this machine. Also lists the process id. (pid) You can now manipulate those pids

#stops a specific worker (gracefull stop)
kill -QUIT pid

#stops a specific worker. (ungracefull stop)
kill -9 pid

#see php-resque worker
pcntl_signal(SIGUSR1, array($this, 'killChild'));
pcntl_signal(SIGUSR2, array($this, 'pauseProcessing'));
pcntl_signal(SIGCONT, array($this, 'unPauseProcessing'));
pcntl_signal(SIGPIPE, array($this, 'reestablishRedisConnection'));

Write your own Job

normal job

Write your class. You can access all arguments given with the add_job command with the associative array "args"

namespace Your\Cool\Namespace;

use Bprs\CommandlineBundle\Resque\AbstractJob;


class YourJob extends AbstractJob {
    public function perform()
    {
        echo sprintf("your task to perform");
        echo sprintf("your argument:%s", $this->args["yourKey"]);
    }
}

To get this up and running, do

# start an worker for the queue defaultQueue
app/console bprs:commandline:start_worker defaultQueue

# add your job with your arguments to the defaultQueue
app/console bprs:commandline:add_job Your\\Cool\\Namespace\\YourJob defaultQueue yourKey:yourArgument

Or use the service


    $this->get('bprs_jobservice')->addJob(
        "Your\\Cool\\Namespace\\YourJob", //your job class
        ["your" => "arguments"],          //your payload arguments
        $onTopOfTheQueue,                 //if you want to enqueue as next job (skip list)
        $monitorMe                        //if you want detailed information for this job (more soon)
    );

If everything worked as expected, you should find in the log (app/logs/dev.log or prod.log)

...
[2017-04-12 15:37:50] app.NOTICE: Registered signals [] []
[2017-04-12 15:37:50] app.DEBUG: Registering worker yourmachine:5191:yourqueue [] []
[2017-04-12 15:37:50] app.DEBUG: Attempting to reserve job from YOURQUEUE {"queues":"yourqueues"} []
...

container aware job

You can also extend Bprs\CommandLineBundle\Model\BprsContainerAwareJob and get the service container with

$this->getContainer()

in your job.

bprs/commandline-bundle 适用场景与选型建议

bprs/commandline-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 132 次下载、GitHub Stars 达 0, 最近一次更新时间为 2015 年 07 月 09 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 bprs/commandline-bundle 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 132
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 24
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: 未知许可证
  • 更新时间: 2015-07-09