summaryrefslogtreecommitdiff
path: root/src/classes/Job.php
blob: 21ed1f0b8379612bcafe830f69ec8545ceb5d2b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php

abstract class Job extends model {

    // ENUM status
    const STATUS_WAITING = 'waiting';
    const STATUS_MANUAL = 'manual';
    const STATUS_ACCEPTED = 'accepted';
    const STATUS_IGNORED = 'ignored';
    const STATUS_RUNNING = 'running';
    const STATUS_DONE = 'done';

    // ENUM result
    const RESULT_OK = 'ok';
    const RESULT_FAIL = 'fail';

    const DB_TABLE = 'jobs';

    protected static $Fields = [
        'id' => model::INTEGER,
        'target' => model::STRING,
        'name' => model::STRING,
        'time_created' => model::INTEGER,
        'time_started' => model::INTEGER,
        'time_finished' => model::INTEGER,
        'status' => model::STRING, // ENUM
        'result' => model::STRING, // ENUM
        'return_code' => model::INTEGER,
        'sig' => model::STRING,
        'stdout' => model::STRING,
        'stderr' => model::STRING,
        'input' => model::SERIALIZED,
    ];

    public $id;
    public $target;
    public $name;
    public $timeCreated;
    public $timeStarted;
    public $timeFinished;
    public $status;
    public $result;
    public $returnCode;
    public $sig;
    public $stdout;
    public $stderr;
    public $input;

    abstract public function run();

    public function __construct(array $raw) {
        parent::__construct($raw);

        if (PHP_SAPI === 'cli') {
            pcntl_async_signals(true);
            pcntl_signal(SIGTERM, [$this, 'signalHandler']);
            pcntl_signal(SIGINT, [$this, 'signalHandler']);
        }
    }

    protected function signalHandler(int $signal) {}
}