承接 robertology/todo_or_die 相关项目开发

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

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

robertology/todo_or_die

Composer 安装命令:

composer require robertology/todo_or_die

包简介

A deadly reminder for your code rot

README 文档

README

A deadly reminder for your code rot.

Replace your // @todo comments with something more actionable. This library will help put those more in your face when the time is right. Yes, "Or Die" means an exception will be thrown if your condition is met.

WHY??

I know what you're thinking: Why would anyone want to purposefully cause a failure?

The main idea is that you should hit these in your testing, not in production. But they will be in production, and there's nothing like a little fire under your seat to get things done. (but keep reading for how not to break production)

Yes, it is a bit harsh, but try a grep -ri '@todo' . | wc -l on your codebase and see how many are just sitting around being ignored. Face it, Later equals Never. No one is looking at these todos and your code is just rotting away.

Put a real, actionable deadline on those "for now"s and "after next version"s.

Installation

composer require robertology/todo_or_die

For PHP 7.4, install version 1, and read the README of that version for usage instructions.

(composer require robertology/todo_or_die:^1)

Usage

(string $todo_message, bool|Check $check, callable $callable_for_alerting = null)

Modes of Use

  1. Die
new Todo($todo_message, $check_to_die);
  1. Alert
new Todo($todo_message, $check_to_alert, $callable_for_alerting);
  1. Die or Alert
(new Todo($todo_message, $check_to_die))
  ->alertIf($check_to_alert, $callable_for_alerting);

Don't Die

Ensure the "Or Die" part never happens by setting the environment variable TODOORDIE_SKIP_DIE to a truthy value. This will cause only Alerts to be triggered. Any Die condition is ignored. (Hint: this might be a smart move for production)

putenv('TODOORDIE_SKIP_DIE=1');

Alert Throttling

To avoid saturating your alert systems, throttling is built in (for Alerts only, not for Die). Each Todo should alert only once per hour. Change that by setting the environment variable TODOORDIE_ALERT_THRESHOLD to the number of seconds desired. Disable throttling by setting this to zero.

// Once per day
putenv('TODOORDIE_ALERT_THRESHOLD=86400');
// Disabled (alert every time)
putenv('TODOORDIE_ALERT_THRESHOLD=0');

Examples

use Robertology\TodoOrDie\Todo;
use Robertology\TodoOrDie\Check\Dates as DateCheck;

// Die only
new Todo(
  'Remove after the old jobs have attritioned out',
  new DateCheck(strtotime('1 jan 2024'))
);

// Alert only
// Note the use of fromString() which gives the same result as strtotime() above
new Todo(
  'Remove after the old jobs have attritioned out',
  DateCheck::fromString('1 jan 2024'),
  [$logger, 'warning']
);

// A couple Alerts before we Die
(new Todo('Remove after the old jobs have attritioned out', DateCheck::fromString('1 jan 2024')))
  ->alertIf(DateCheck::fromString('22 dec 2023'), [$logger, 'warning'])
  ->alertIf(time() >= strtotime('27 dec 2023'), $my_slack_callable);
//           ^ the constructor and alertIf() can take a Check object or boolean

Notes

  • I used strtotime() in the examples for readability, but do not use relative dates such as strtotime('+2 months') because it will be evaluated each time and "two months from now" will never come when "now" keeps moving.

  • The Alert throttling uses a file placed in PHP's temp directory (sys_get_temp_dir()) which may be prone to garbage collection now and then, but is likely to work fine for this.

  • The name was (also) shamelessly stolen from the ruby gem searls/todo_or_die.

  • Tip o' the Hat to The Changelog (Episode 463) where I first heard of the idea.

Personal Quest

In addition to having an actual working tool, I had a few goals for myself with this project.

  1. Full TDD (Test Driven Development)
    • The tests are a mix of Behavior and Functional tests, and I'm OK with that for this small project.
    • I'm not concerned with 100% coverage, but all behavior should have a test.
  2. SOLID "To The Extreme"
    • After getting to a working version, I continued to refactor with an eye on SOLID principles.
    • Such a simple concept could have been written with a single class, but being strict here was a good exercise in defining the Single Responsibility.

License

This project is licensed under the MIT license.

robertology/todo_or_die 适用场景与选型建议

robertology/todo_or_die 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 09 月 13 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 6
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 27
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-09-13