fivesqrd/hive
Composer 安装命令:
composer require fivesqrd/hive
包简介
Simple Job Queue Client
README 文档
README
Hive is a simple job queue library for PHP that uses DynamoDB for a backend.
Configuration
$config = [
'table' => 'My-Table-Name',
'aws' => [
'version' => '2012-08-10',
'region' => 'eu-west-1',
'credentials' => [
'key' => 'my-key',
'secret' => 'my-secret',
],
],
];
Preparing a DynamoDb table
Create a local config file say config.php
<?php
return [
'table' => 'My-Table-Name',
'aws' => [
'version' => 'latest',
'region' => 'eu-west-1',
'credentials' => [
'key' => 'my-key',
'secret' => 'my-secret',
],
],
];
Run the table create script
php vendor/fivesqrd/hive/scripts/CreateTable.php config.php
Instantiate the queue
$queue = Hive\Factory::queue(
$config, 'Welcome-Email-Notifications'
);
Add a job to the queue
$job = Hive\Job::create(
['to' => 'you@domain.com', 'subject' => 'hello']
);
/* Run as soon as possible */
$result = $queue->add($job);
/* Schedule for later */
$job = Hive\Job::create(
['to' => 'you@domain.com', 'subject' => 'hello'],
gmdate('U') + 300
);
$result = $queue->add($job);
/* Add multiple jobs as part of a batch */
$jobs = [
Hive\Job::create(['to' => 'you@domain.com', 'subject' => 'hello']),
Hive\Job::create(['to' => 'you@domain.com', 'subject' => 'hello 2']),
];
$batchId = $queue->batch($job);
Get all pending jobs from a queue
/* Receive 5 jobs and lock them for 300 seconds (FIFO) */
$jobs = $queue->receive(5, 300);
foreach ($jobs as $job) {
$payload = $job->payload();
/* Do the work */
$jobId = $job->id();
/* Mark job as done */
$queue->done($job);
}
/* Receive 5 jobs and lock them for 300 seconds (FILO) */
$jobs = $queue->receive(5, 300, false);
foreach ($jobs as $job) {
$subject = $job->payload('subject');
/* Do the work */
$jobId = $job->id();
/* Mark job as done */
$queue->done($job);
}
Queurying the contents of the queue
View the contents of current and past queue items without affecting the queue
$factory = Hive\Factory::query(
$config, 'Welcome-Email-Notifications'
);
/* Show the next 10 items waiting in the queue (FIFO) */
$items = $query->queued(10, true);
/* Show the next 10 items waiting in the queue (FILO) */
$items = $query->queued(10, true);
/* Show the 10 most recently added items (queued or not) */
$items = $query->recent(10);
/* Iterate over all the most recently added items (queued or not) */
$items = $query->recentByPage(1);
$items = $query->recentByPage(2);
$items = $query->recentByPage(3);
/* Access individual job attributes */
foreach ($items as $job) {
echo "Job id: {$job->attribute('Id')}\n";
echo "Status: {$job->attribute('Status')}\n";
echo "Created on: {$job->attribute('Timestamp')}\n";
echo "Scheduled for: {$job->attribute('Timeslot')}\n";
}
/* Dump all attrinutes */
foreach ($items as $job) {
print_r($job->attributes());
}
Cancelling a queued job
$result = $queue->cancel($job->attribute('Id'));
fivesqrd/hive 适用场景与选型建议
fivesqrd/hive 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.44k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2019 年 01 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 fivesqrd/hive 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 fivesqrd/hive 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 1.44k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2019-01-24