承接 apinstein/jqjobs 相关项目开发

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

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

apinstein/jqjobs

Composer 安装命令:

composer require apinstein/jqjobs

包简介

Async job manager for PHP.

关键字:

README 文档

README

JQJobs is a job queue infrastructure for PHP.

Features

  • Very light-weight and easy-to-use.
  • Supports multiple job types.
  • Supports multiple queues & binding workers to specific queues.
  • Supports jobs that proxy the work to third-party services. This allows other jobs to be worked on but tracks the status of the third-party job through JQJobs.
  • Tracks job enqueue time, start time, and finish time.
  • Priority scheduling.
  • Coalescing job support (if a job with the same coalesceId is enqueued, no duplicate job is created; the original is returned). This is basically a lightweight built-in mutex to help you prevent from creating duplicate jobs for the same "thing".
  • Tested in highly-concurrent production environment with over 3M jobs processed over 2+ years.
  • Queue store is architecturally independent of JQJobs; use our JQStore_Array or JQStore_Propel (db) or write your own.
  • Workers automatically pre-flight memory availability and gracefully restart in low-memory situations to avoid OOM's during job processing.
  • Workers automatically check all source code files in use and gracefully restart if any underlying code has been modified.
  • Workers can have their priority adjusted (ideal for background tasks on web servers for instance).
  • Logs failed job messages.
  • Workers designed to be run under runit or similar process supervisor for maintenance-free operation.
  • Auto-retry failed jobs.
  • Good test coverage.
  • Utility class JQDelayedJob makes it trivial to run php code after the script exits. This is a great way to defer things like logging to after the request is handled for a more performant application.
  • Optional jitter for high-concurrency situations
  • Robust signal handling, including graceful shutdown on SIGTERM
  • Robust autoscaler with Heroku and AWS (Auto-scaling groups) drivers.
  • Hung jobs detection (will be re-queued).
  • Built-in support for ASYNC jobs (jobs where work is sent "offsite" and will be closed out asyncronously via JQManagedJob::STATUS_WAIT_ASYNC and JQManagedJob::resolveWaitAsyncJob().

Roadmap

  • Queue admin tool (cli & gui)

The job system has only a few core parts:

  • JQJob is an interface for a class that does actual work.
  • JQManagedJob is a wrapper for JQJob's which contains metadata used to manage the job (status, priority, etc).
  • JQStore is where JQManagedJob's are persisted. The application queues jobs in a JQStore for later processing.
  • JQWorker runs jobs from the queue. It is typically run in a background process.

Additional Utilities:

  • JQAutoscaler is a utility that can manage auto-scaling your worker pool.
  • JQDelayedJob is a utility class for registering a function or job to be run after the script exits.

The JQStore manages the queue and persistence of the JQManagedJob's.

JQStore is an interface, but the job system ships with several concrete implementations. The system is architected in this manner to allow the job store to be migrated to different backing stores (memcache, db, Amazon SQS, etc). JQStore implementations are very simple.

Jobs that complete successfully are removed from the queue immediately. Jobs that fail are retried until maxAttempts is reached, and then they are marked FAILED and left in the queue. It's up to the application to cleanup failed entries.

If the application requires an audit log or archive of job history, it should implement this in run()/cleanup() for each job, or in a custom JQStore subclass.

The minimal amount of work needed to use a JQJobs is 1) create at least one job; 2) create a queuestore; 3) add jobs; 4) start a worker.

  1. Create a job

    class SampleJob implements JQJob { function __construct($info) { $this->info = $info; } function run() { print $this->description() . "\n"; } // no-op function cleanup() { print "cleanup() {$this->description()}\n"; } function statusDidChange(JQManagedJob $mJob, $oldStatus, $message) { print "SampleJob [Job {$mJob->getJobId()}] {$oldStatus} ==> {$mJob->getStatus()} {$message}\n"; } function description() { return "Sample job {$this->info}"; } }

  2. Create a queuestore

    $q = new JQStore_Array();

    // alternatively; create a db-based queue with Propel: $con = Propel::getConnection(JQStoreManagedJobPeer::DATABASE_NAME); $q = new JQStore_Propel('JQStoreManagedJob', $con);

  3. Add jobs

    foreach (range(1,10) as $i) { $q->enqueue(new SampleJob($i)); }

  4. Start a worker to run the jobs.

    declare(ticks = 1); // to have JQJobs be able to gracefully handle SIGKILL (or other immediate termination signals) // the declare(ticks=1) must be in global scope. $w = new JQWorker($q); $w->start();

  5. If you want hung jobs detection and you aren't using JQAutoscaler, you will need to schedule a task to run JQStore::detectHungJobs().

=======================

JQDelayedJob Example

JQDelayedJob::doLater(new MyJob('data'));
JQDelayedJob::doLater(function() { print "Hello, World. I am running from a delayed job after the script exits!"; });

INSTALLATION

pear install apinstein.pearfarm.org/jqjobs

See http://apinstein.pearfarm.org/apinstein/jqjobs

SOURCE

https://github.com/apinstein/jqjobs

JQStore Backends

Propel

Currently the only db-backed JQStore implememtation is for Propel ORM. All migrations needed for JQJobs/Propel to function are in the migrations/ folder which is expected to be run with mp (github.com/apinstein/mp). This could easily be adapter into a Propel plugin, but hasn't yet.

In any case, just ensure that if you are installing/upgrading your JQJobs that you copy and re-sequence the migrations as needed.

apinstein/jqjobs 适用场景与选型建议

apinstein/jqjobs 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 20.19k 次下载、GitHub Stars 达 32, 最近一次更新时间为 2013 年 01 月 17 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「queue」 「job」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 apinstein/jqjobs 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 32
  • Watchers: 5
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2013-01-17