netlogix/jobqueue-scheduled
Composer 安装命令:
composer require netlogix/jobqueue-scheduled
包简介
Allows for scheduled jobs and deduplicates
README 文档
README
This package provides a PDO based scheduler for JobQueue jobs.
There are two main goals:
- Schedule a Flowpack JobQueue job for later execution.
- Have a single job only scheduled once.
Installation
composer require netlogix/jobqueue-scheduled
Schedule jobs
The first goal of this package is to have a way to put any kind of JobQueue job on hold and mark it for later execution. In contrast to e.g. "Defer" annotated methods or default behavior of JobQueue jobs, there is a time aspect to it. Scheduled jobs are not executed immediately but at a time specified while scheduling.
Regular job queue jobs need to be serializable. That's just an implementation detail of how Flowpack FakeQueue and t3n RabbitQueue work.
To schedule an existing Flowpack job, just wrap it in a Scheduled Job and pass it to the scheduler.
use Netlogix\JobQueue\Scheduled\Domain\Model\ScheduledJob; use Netlogix\JobQueue\Scheduled\Domain\Scheduler; use Flowpack\JobQueue\Common\Job\JobInterface; assert($scheduler instanceof Scheduler); assert($jobqueueJob instanceof JobInterface); $dueDate = new \DateTimeImmutable('now + 1 minute'); $queueName = 'default'; $schedulerJob = new ScheduledJob( $jobqueueJob, $queueName, $dueDate ); $scheduler->schedule($schedulerJob);
Jobs with unique identifiers
The second goal of this package is to avoid duplicate schedules.
Certain jobs don't calculate a specific computation but just "run to the end". An example of those are the catchup jobs of the Neos.EventSourcing package. Queuing triggers the catchup call of some event listeners.
Queuing another catchup job while the first one is running is good because there might be additonal changes.
Queueing another catchup job while the previous one has is not even started is unnecessary because the first one will already catch up to the end.
use Netlogix\JobQueue\Scheduled\Domain\Model\ScheduledJob; use Netlogix\JobQueue\Scheduled\Domain\Scheduler; use Flowpack\JobQueue\Common\Job\JobInterface; assert($scheduler instanceof Scheduler); assert($jobqueueJob instanceof JobInterface); $dueDate = new \DateTimeImmutable('now + 1 minute'); $queueName = 'default'; $jobIdentifier = 'event-sourcing-catchup-' . $eventListenerName; $schedulerJob = new ScheduledJob( $jobqueueJob, $queueName, $dueDate, $jobIdentifier ); $scheduler->schedule($schedulerJob);
The "schedule" will only schedule a new job if the specified identifier is not already scheduled. If there are conflicts between the existing due date and the one provided by the new job the earliest value is taken.
Queue scheduled jobs
A scheduled job lives in the database and is not processed any further until queueing happens.
This is currently done via cronjobs.
* * * * * ./flow scheduler:queueduejobs
The internal scheduling mechanism will make sure only those jobs are passed from the scheduler to the job queue which are "due" according to their individual due date values.
Automatically schedule jobs
Some jobs originate from foreign applications. An example would be one flow app putting a job into a RabbitMQ and another flow app consuming it.
Previously the only implementation would be a regular jobqueue worker, which neither provides a way to delay execution nor a deduplication feature.
Now every job can simply implement the ScheduledJobInterface. When execute()
is triggered, it's now moved over to a scheduled jobs queue.
The job itself must provide all necessary details about how to schedule its execution.
abstract class AutoScheduledJob implements ScheduledJobInterface, JobInterface { public function getSchedulingInformation(): ?SchedulingInformation { return SchedulingInformation( '97528fab-c199-4f87-b1a5-4074f1e98749', 'default-group', new DateTimeImmutable('now') ); } }
netlogix/jobqueue-scheduled 适用场景与选型建议
netlogix/jobqueue-scheduled 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 277.45k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 05 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 netlogix/jobqueue-scheduled 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 netlogix/jobqueue-scheduled 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 277.45k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-05-13