apacheborys/re-try-php
Composer 安装命令:
composer require apacheborys/re-try-php
包简介
Library to operate retries in your php application
README 文档
README
That library still in development phase. Please don't use it until first release
With this library you will be able to introduce re-try approach in simple way:
- Create configuration
- When your application start, please add next 2 rows in the begining:
$factory = new \ApacheBorys\Retry\HandlerFactory($config); $retry = $factory->createExceptionHandler($yourContainer);
- Start by another process code like that:
$factory = new \ApacheBorys\Retry\HandlerFactory($config); $worker = $factory->createMessageHandler($yourContainer); while (true) { $worker->processRetries(); sleep(1); }
Config example:
{
/**
* here we can define declarator what should register exception handling callback function, if you are plan to use
* standard php function set_exception_handler - you can ignore that section. StandardHandlerExceptionDeclarator is default
**/
"handlerExceptionDeclarator": {
"class": "ApacheBorys\\Retry\\HandlerExceptionDefiner\\StandardHandlerExceptionDeclarator",
"arguments": []
},
"items": {
/* name of retry */
"test": {
/* what type of Exception we would like to retry */
"exception": "ApacheBorys\\Retry\\Tests\\Functional\\Exceptions\\Mock",
/* how many tries we should do */
"maxRetries": 4,
/* here we are describing formula, how next execution time should be calculated. Calculated amount will be added to current time */
"formula": [
{
/* here available *, -, + and / operators */
"operator": "+",
/* you can use QTY_TRIES operator or any integer value */
"argument": "QTY_TRIES"
},
{
"operator": "*",
"argument": "5"
}
],
/* here you should define, what kind of transport you would use to deliver re-try messages to worker. Please pay your attention to https://github.com/apacheborys/re-try-php-basics-lib */
"transport": {
"class": "ApacheBorys\\Retry\\Tests\\Functional\\Transport\\FileTransportForTests",
/* each specific transport could have own arguments in constructor. Here you should define it */
"arguments": [
"tests\/transport.data"
]
},
/* here you should define, what kind of executor you would use to perform re-try action */
"executor": {
"class": "ApacheBorys\\Retry\\Tests\\Functional\\Executor\\Runtime",
/* each specific executor could have own arguments in constructor. Here you should define it */
"arguments": []
}
}
}
}
The notice about handlerExceptionDeclarator, transport and executor:
As second argument for constructor of ApacheBorys\Retry\ExceptionHandler and ApacheBorys\Retry\MessageHandler you can send ContainerInterface. In this case, you can define arguments for handlerExceptionDeclarator, transport and executor as instances from runtime. It will be fetched from this injected Container.
For example:
... "transport": { "class": "ApacheBorys\\Retry\\BasicTransport\\PdoTransport, "arguments": [ "@pdoInstanceFromYourContainer" ] }, ...
Leading @ indicates - you are trying to inject some instance from your container.
Also, if you don't want to use Container to inject some instances from runtime. But you still need to create some instances to ensure proper execution for handlerExceptionDeclarator, transport and executor, you can use next construction:
... "transport": { "class": "ApacheBorys\\Retry\\BasicTransport\\PdoTransport, "arguments": [ [ "class": "\\PDO", "arguments": [ "sqlite:/app/storage/retry-db.data'" ] ] ] }, ...
In this case, handler/declarator will try to instantiate described class with arguments. In these arguments you can use same tricks with leading @; and class, arguments constructions.
Leading @ works with class too.
apacheborys/re-try-php 适用场景与选型建议
apacheborys/re-try-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 113 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 08 月 31 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 apacheborys/re-try-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 apacheborys/re-try-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 113
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 9
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-08-31