forked from REBELinBLUE/deployer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathServerLog.php
80 lines (70 loc) · 1.79 KB
/
ServerLog.php
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
namespace REBELinBLUE\Deployer;
use Illuminate\Database\Eloquent\Model;
use McCool\LaravelAutoPresenter\HasPresenter;
use REBELinBLUE\Deployer\View\Presenters\RuntimeInterface;
use REBELinBLUE\Deployer\View\Presenters\ServerLogPresenter;
/**
* Server log model.
*/
class ServerLog extends Model implements HasPresenter, RuntimeInterface
{
const COMPLETED = 0;
const PENDING = 1;
const RUNNING = 2;
const FAILED = 3;
const CANCELLED = 4;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = ['server_id', 'deploy_step_id'];
/**
* The attributes that should be casted to native types.
*
* @var array
*/
protected $casts = [
'id' => 'integer',
'server_id' => 'integer',
'deploy_step_id' => 'integer',
'status' => 'integer',
];
/**
* The fields which should be treated as Carbon instances.
*
* @var array
*/
protected $dates = ['started_at', 'finished_at'];
/**
* Belongs to association.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function server()
{
return $this->belongsTo(Server::class);
}
/**
* Calculates how long the commands were running on the server for.
*
* @return false|int Returns false if the command has not yet finished or the runtime in seconds
*/
public function runtime()
{
if (!$this->finished_at) {
return false;
}
return $this->started_at->diffInSeconds($this->finished_at);
}
/**
* Gets the view presenter.
*
* @return string
*/
public function getPresenterClass()
{
return ServerLogPresenter::class;
}
}