aligent / async-bundle
用于扩展Oro的异步处理的包
5.0.2
2023-07-20 06:44 UTC
Requires
- oro/commerce: 5.0.*
- dev-master
- 5.0.2
- 5.0.1
- 5.0.0
- 4.2.x-dev
- 4.2.2
- 4.2.0
- 4.1.x-dev
- 4.1.1
- 4.1.0
- 3.1.x-dev
- 3.1.0
- dev-feature/CreateCustomWebhookEvent
- dev-hotfix/Oro5.0-Compatibilty_Fixes
- dev-feature/add-webhooks-and-oro-4.2-compatibility
- dev-feature/add-webhooks-and-oro-5.0-compatibility
- dev-hotfix/remove-version-from-composer-file
- dev-hotfix/replace-outdated-symfony-RegistryInterface-with-ManagerRegistry
- dev-hotfix/Update-Exception-To-Text-field
This package is auto-updated.
Last update: 2024-09-24 04:23:04 UTC
README
此包提供以下功能
-
一个抽象处理器类,可以捕获RetryableExceptions,并在3次(默认)重试失败后将失败的作业放入数据库中,以便进行审查、修复然后重新排队。
-
Webhook集成
安装说明
-
使用Composer安装此模块
composer require aligent/async-bundle
-
清除缓存
php bin/console cache:clear
-
运行迁移
php bin/console oro:migration:load --force
用法
确保您的类继承自AbstractRetryableProcessor,并在execute函数中执行正常的作业处理。
class TestJobProcessor extends AbstractRetryableProcessor
{
/**
* @param MessageInterface $message
* @return string
* @throws RetryableException
*/
public function execute(MessageInterface $message)
{
$body = JSON::decode($message->getBody());
try {
// Process the job here
$this->importSomeEntities($body);
} catch (\Exception $e) {
throw new RetryableException(
'This job failed and needs a retry',
0,
$e
);
}
}
}
默认情况下,AbstractRetryableProcessor将从RetryableException中获取传递的异常并存储跟踪信息。但是,如果您没有捕获异常,您可以直接使用RetryableException,它将存储此点的跟踪信息和消息。
class TestJobProcessor extends AbstractRetryableProcessor
{
/**
* @param MessageInterface $message
* @return string
* @throws RetryableException
*/
public function execute(MessageInterface $message)
{
$body = JSON::decode($message->getBody());
// Process the job here
$success = $this->importSomeEntities($body);
if (!$success) {
throw new RetryableException('This job failed and needs a retry');
}
}
}
您也可以通过覆盖您自己的类中的const MAX_RETRIES = 3;
来增加或减少重试次数。
设置Webhook传输
转到“系统 -> 集成 -> 管理集成”,然后点击“创建集成”。选择“Webhook”作为集成类型,并填写所有必填字段。
要启用,请将状态设置为“活动”。
完成后,您现在必须接收请求URL的webhook事件。
分发webhook事件
- EntityEventListener监听任何创建/更新/删除事件;检查是否存在相关的webhook传输并处于活动状态;如果是,则将消息推送到队列
Aligent\AsyncEventsBundle\EventListener\EntityEventListener:
lazy: true
arguments:
- '@Aligent\AsyncEventsBundle\Provider\WebhookConfigProvider'
- '@oro_message_queue.client.message_producer'
- '@logger'
tags:
- { name: doctrine.event_listener, event: onFlush }
- { name: doctrine.event_listener, event: postFlush }
- WebhookEntityProcessor构建一个有效载荷并发送一个webhook事件作为对排队消息的响应。
Aligent\AsyncEventsBundle\Async\WebhookEntityProcessor:
parent: Aligent\AsyncEventsBundle\Async\AbstractRetryableProcessor
calls:
- [setConfigProvider, ['@Aligent\AsyncEventsBundle\Provider\WebhookConfigProvider']]
- [setTransport, ['@Aligent\AsyncEventsBundle\Integration\WebhookTransport']]
- [setSerializer, ['@oro_importexport.serializer']]
tags:
- { name: 'oro_message_queue.client.message_processor' }
- 如果您需要丰富有效载荷数据(例如,为顾客用户添加地址),您可以使用OroImportExportBundle并添加一些自定义规范化程序来添加/转换有效载荷数据。
支持
如果您对此包有任何问题,请创建一个 GitHub问题。
贡献
任何贡献都备受赞赏。贡献代码的最佳方式是在GitHub上打开一个 pull request。
开发者
Adam Hall adam.hall@aligent.com.au