tigron/skeleton-transaction

骨架的后台任务

v4.0.1 2023-10-06 13:50 UTC

README

描述

骨架的事务。事务用于执行后台任务。

安装

通过composer安装

composer require tigron/skeleton-transaction

如何设置

运行初始迁移

创建事务

所有事务都应扩展自 \Skeleton\Transaction\Transaction 并实现 run() 方法

<?php
/**
 * Transaction_Test
 *
 * @author Christophe Gosiau <christophe@tigron.be>
 */
class Transaction_Test extends \Skeleton\Transaction\Transaction {

    /**
     * Run
     *
     * @access public
     */
    public function run() {
        // Do your thing
        $data = $this->get_data();
    }
}

安排事务

$transaction = new Transaction_Email_Order_Canceled();
$data = [ 'some_data' => 'some_value ];
$transaction->data = $data;
$transaction->schedule();

管理守护进程

使用骨架二进制文件启动事务守护进程

skeleton transaction:daemon start

停止事务守护进程

skeleton transaction:daemon stop

获取守护进程状态

skeleton transaction:daemon status

与事务交互

获取所有已安排事务的列表

skeleton transaction:list

运行事务

skeleton transaction:run <transaction_id>

显示事务日志

skeleton transaction:log <transaction_id_or_classname>

使用Nagios监控守护进程

Skeleton Transaction Daemon可以通过其状态文件进行监控。状态文件每5秒更新一次,可以通过配置进行配置。

\Skeleton\Transaction\Config::$monitor_file = '/tmp/skeleton-transaction.status';

要使用Nagios监控守护进程,提供了一个 \Skeleton\Core\Web\Module,该模块将读取状态文件并返回适当的响应。

要启用Nagios监控,请确保在应用程序中创建一个处理监控请求的模块

<?php
/**
  * Module monitor
  *
  * @author Christophe Gosiau <christophe@tigron.be>
  */
class Web_Module_Monitor extends \Skeleton\Transaction\Web\Module\Monitor {
}

可选地,可以配置身份验证头

\Skeleton\Transaction\Config::$monitor_authentication = 'YOUR_SECRET_STRING';

Nagios配置

在Nagios中,您应该配置一个 command 来调用服务。我们将使用内置的 check_http 命令作为起点

define command {
    command_name	check_skeleton_http
    command_line	/usr/lib/nagios/plugins/check_http -H $ARG1$ -u $ARG2$ -k 'X-Authentication: $ARG3$'
}

您的服务定义可能如下所示

define service {
    use                             generic-service
    host_name                       hostname.example.com
    service_description             SKELETON
    check_command                   check_skeleton_http!app.hostname.example.com!/monitor!AuThEnTiCaTiOnStRiNg
}