tigron/skeleton-transaction

Background tasks for skeleton

Installs: 16 413

Dependents: 1

Suggesters: 0

Security: 0

Stars: 0

Watchers: 4

Forks: 1

Open Issues: 2

pkg:composer/tigron/skeleton-transaction

v6.0.0 2025-10-08 09:10 UTC

README

Description

Transactions for Skeleton. Transactions are used to perform background tasks.

Installation

Installation via composer:

composer require tigron/skeleton-transaction

Howto setup

Run the initial migrations

Create transactions

Transactions should all extend from \Skeleton\Transaction\Transaction and should implement the run() method:

<?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();
    }
}

Schedule your transaction

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

Manage the daemon

Start the transaction daemon with the skeleton binary:

skeleton transaction:daemon start

Stop the transaction daemon

skeleton transaction:daemon stop

Get the status of the daemon

skeleton transaction:daemon status

Interact with transactions

Get a list of all scheduled transactions

skeleton transaction:list

Run a transaction

skeleton transaction:run <transaction_id>

Show the log of a transaction

skeleton transaction:log <transaction_id_or_classname>

Transaction concurrency

By default, a transaction will be running with pool set to null. All transactions with pool null will run concurrently and as soon as a slot becomes available.

Sometimes, however, transactions should not be run at the same time as another transaction, for example because it is using a resource of which there is only one. This can be fixed by assigning both of these transactions to run in the same pool. Transactions with a non-null pool will run sequentially within their pool.

To assign your transaction to a pool, override the get_pool() method:

public function get_pool(): string {
    return 'mypool';
}

Transaction priority

Some transactions are more important than others. You can (de-)prioritise a transaction by modifying its weight. A lower weight will make the transaction float higher up in the queue with a higher priority, a higher weight will push it down and de-prioritise. The default weight is set to 10.

public function get_weight(): int {
    return 42;
}

Monitor the daemon with Nagios

Skeleton Transaction Daemon can be monitored via its status file. The status file is updated every 5 seconds and can be configured via Config:

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

To monitor the daemon via Nagios, a \Skeleton\Core\Web\Module is provided which will read the status file and return an appropiate response.

To enable Nagios monitoring, make sure to create a module in your application that will handle the monitoring request:

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

Optionally, an authentication header can be configured:

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

Nagios configuration

In Nagios, you should configure a command to call the service. We will use the built-in check_http command as a starting point:

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

Your service definition could then look like this:

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