Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
SchedulerJobExecutionModel
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 2
6
0.00% covered (danger)
0.00%
0 / 1
 start
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
2
 finish
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace App\Modules\SchedulerModule\Models;
4
5use CodeIgniter\Model;
6use App\Modules\SchedulerModule\Entities\SchedulerJobExecutionEntity;
7
8class SchedulerJobExecutionModel extends Model
9{
10    protected $table      = 'scheduler_job_execution';
11    protected $primaryKey = 'id';
12
13    protected $returnType = SchedulerJobExecutionEntity::class;
14
15    protected $allowedFields = [
16        'job_id',
17        'provider',
18        'status',
19        'message',
20        'processed',
21        'failed',
22        'started_at',
23        'finished_at',
24        'created_at',
25    ];
26
27    protected $useTimestamps = true;
28
29    public function start(int $jobId, string $provider): int
30    {
31        return $this->insert([
32            'job_id'     => $jobId,
33            'provider'   => $provider,
34            'status'     => 'running',
35            'started_at' => date('Y-m-d H:i:s'),
36        ]);
37    }
38
39    public function finish(int $id, string $status, array $stats = [], ?string $message = null): void
40    {
41        $this->update($id, array_merge([
42            'status'      => $status,
43            'message'     => $message,
44            'finished_at' => date('Y-m-d H:i:s'),
45        ], $stats));
46    }
47}