oniva/flow-healthstatus 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

oniva/flow-healthstatus

Composer 安装命令:

composer require oniva/flow-healthstatus

包简介

Flow Framework package to check the health status of you application

README 文档

README

Package to check the health status of a flow application.

It's extremly useful in a kubernetes environment to use with readiness and liveness probe to determine if a pod can serve traffic and if it is still alive.

Usage

To determine the current health status of your application you can check wether the app is ready or still alive.

Readiness

Simply execute the flow command ./flow app:isready.

This will execute all tests defined in the Oniva.Flow.HealthStatus.testChain of the Settings.yaml. If all tests have passed, the readyChain tasks will be executed.

After a successfully run of the readyChain an internal lock will be set to prevent repeated execution. The testChain will be executed on every run. So the readyChain should bring your application in an "ready state". Make sure to initialize everything you need. The testChain should ping all services your application depends on.

Liveness

Execute ./flow app:isalive to check if your pod is still alive.

This will execute the livenessChain.

Currently the liveness chain is empty by default and has one possible test: statusCode.

Configuration

Add all your tests in the following format in your apps Settings.yaml:

Oniva:
  Flow:
    HealthStatus:
      testChain:
        yourUniqueTestKey:
          name: 'Optional name'
          test: 'database' // shorthand for a predefined task in Oniva\Flow\HealthStatus\Test\*.Test or a full qualified class name
          options:
            key: 'value' // optional options for your test
          position: 'after otherTestKey' // optional position

After that, the check will execute the ready chain:

Oniva:
  Flow:
    HealthStatus:
      readyChain:
        yourUniqueTaskKey:
          name: 'Optional name'
          task: 'command' // shorthand for a predefined task in Oniva\Flow\HealthStatus\Task\*.Task or a full qualified class name
          options:
            key: 'value' // optional options for your task
          position: 'after otherTaskKey' / optional position
          lockName: 'mylock' // optional lock override. This will create a lock for this task only and ignore the global lock

After a successful ready chain invokation, you can call ./flow app:isalive to execute your liveness chain:

Oniva:
  Flow:
    HealthStatus:
      livenessChain:
        yourUniqueTestKey:
          name: 'Optional name'
          task: 'statusCode' // shorthand for a predefined task in Oniva\Flow\HealthStatus\LivenessTest\*.Test or a full qualified class name
          options:
            key: 'value' // optional options for your task
          position: 'after otherTaskKey' / optional position

Advanced configuration

Before each attempt to execute a ready task, the check will test the Oniva.Flow.HealthStatus.defaultReadyTaskCondition to see if the task should be executed. In the default configuration this is simply a check to see if the ready lock is not yet set.

You can override this behaviour on a per task basis:

Oniva:
  Flow:
    HealthStatus:
      readyChain:
        yourUniqueTaskKey:
          condition: '${Lock.isSet("mylock")}' // this can be any eel expression
          afterInvocation: '${Lock.set("mylock")}' // this will be executed after a successfull invocation

(the lockName setting is simply a shorthand for exactly this example)

To extend the eel context, you can provide additional helpers in Oniva.Flow.HealthStatus.defaultContext.

Health status via HTTP-Request

If you'd like to check your Application via HTTP instead of a cli command you can do so by including the Routes in your Routes.yaml:

-
  name: 'Health-Routes'
  uriPattern: '<HealthStatusSubroutes>'
  subRoutes:
    'HealthStatusSubroutes':
      package: 'Oniva.Flow.HealthStatus'
      variables:
        'healthStatusEndpoint': 'your-endpoint-name'

Afterwards there will be two new routes: /<your-endpoint-name>/ready and /<your-endpoint-name>/live Adjust the variable to your needs. Both endpoints will return a JSON formatted output. On a successful run the response has a status code 200 and if there are any errors the status code will be 500.

Example Configuration

This example could be used in your Flow package to make sure that your application pod has a ready state to serve traffic. Therefore it will always check the ping status for doctrine, redis and beanstalk. On the first run all missing database migrations will be executed, the redis cache flushed and static resources published. After a successfull run only the testChain will be executed again.

Oniva:
  Flow:
    HealthStatus:
      testChain:
        database:
          test: doctrine
          position: start
        redis:
          test: redis
          options:
            hostname: your-redis-host
        beanstalk:
          test: beanstalk
          options:
            hostname: your-beanstalk-host
      readyChain:
        migrations:
          task: command
          options:
            command: 'neos.flow:doctrine:migrate'
        flushRedis:
          name: 'Flush redis'
          position: 'start 100'
          task: redis
          options:
            hostname: your-redis-host
            command: FLUSHDB
            database: 0
        staticResources:
          name: 'Publish static resources'
          task: command
          position: 'end 20'
          lockname: staticresources
          cacheName: Oniva_FlowHealthStatus_LocalLock
          options:
            command: 'neos.flow:resource:publish'
            arguments:
              collection: static
      livenessChain:
        home:
          test: statusCode
          name: 'Homepage responds'
          options:
            url: '/'
            method: 'GET'
            statusCode: 200

Note the lockname configuration. This Configuration enables you to run tasks only once per deployment or always. By default the Oniva_FlowHealthStatus_Lock cache is used to read and write locks. Add this to your Caches.yaml and all your application pods will rely on the same lock files as they don't use the local file storage but redis. This will result in a execution once per deployment:

Oniva_FlowHealthStatus_Lock:
  backend: Neos\Cache\Backend\RedisBackend
  backendOptions:
    hostname: 'your-redis-server'
    database: 2

The staticResources task has a custom cacheName configured. To ensure that this task will be executed in each application pod set it to local file storage:

Oniva_FlowHealthStatus_LocalLock:
  frontend: Neos\Cache\Frontend\StringFrontend
  backend: Neos\Cache\Backend\FileBackend

Migration from t3n.Flow.HealthStatus

There is a code migration script to migrate your existing t3n.Flow.HealthStatus installation to Oniva.Flow.HealthStatus.

Simply run the flow command:

./flow core:migrate

Acknowledgments

This project is a fork of t3n.Flow.HealthStatus originally developed by t3n. We thank the original contributors for their foundational work.

oniva/flow-healthstatus 适用场景与选型建议

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

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

围绕 oniva/flow-healthstatus 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-09-15