-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathProcessHistory.php
More file actions
179 lines (155 loc) · 3.41 KB
/
Copy pathProcessHistory.php
File metadata and controls
179 lines (155 loc) · 3.41 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<?php declare(strict_types=1);
/*
* This file is part of the CleverAge/ProcessBundle package.
*
* Copyright (C) 2017-2021 Clever-Age
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CleverAge\ProcessBundle\Model;
use CleverAge\ProcessBundle\Configuration\ProcessConfiguration;
/**
* Logs information about a process
*
* @deprecated not used anymore, will be removed in v4.0
*
* @author Valentin Clavreul <vclavreul@clever-age.com>
* @author Vincent Chalnot <vchalnot@clever-age.com>
*/
class ProcessHistory
{
public const STATE_STARTED = 'started';
public const STATE_SUCCESS = 'success';
public const STATE_FAILED = 'failed';
/**
* @var int
*/
protected $id;
/**
* @var string
*/
protected $processCode;
/**
* @var array
*/
protected $context;
/**
* @var \DateTime
*/
protected $startDate;
/**
* @var \DateTime
*/
protected $endDate;
/**
* @var string
*/
protected $state = self::STATE_STARTED;
/**
* @param ProcessConfiguration $processConfiguration
* @param array $context
*/
public function __construct(ProcessConfiguration $processConfiguration, array $context = [])
{
$this->id = microtime(true);
$this->processCode = $processConfiguration->getCode();
$this->startDate = new \DateTime();
$this->context = $context;
}
/**
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* @return string
*/
public function getProcessCode(): string
{
return $this->processCode;
}
/**
* @return array
*/
public function getContext(): array
{
return $this->context;
}
/**
* @return \DateTime
*/
public function getStartDate(): \DateTime
{
return $this->startDate;
}
/**
* @return \DateTime
*/
public function getEndDate()
{
return $this->endDate;
}
/**
* @return string
*/
public function getState(): string
{
return $this->state;
}
/**
* Set the process as failed
*/
public function setFailed()
{
$this->endDate = new \DateTime();
$this->state = self::STATE_FAILED;
}
/**
* Set the process as succeded
*/
public function setSuccess()
{
$this->endDate = new \DateTime();
$this->state = self::STATE_SUCCESS;
}
/**
* Is true when the process is running
*
* @return bool
*/
public function isStarted()
{
return $this->state === self::STATE_STARTED;
}
/**
* @return bool
*/
public function isFailed()
{
return $this->state === self::STATE_FAILED;
}
/**
* Get process duration in seconds
*
* @return int|null
*/
public function getDuration()
{
if ($this->getEndDate()) {
return $this->getEndDate()->getTimestamp() - $this->getStartDate()->getTimestamp();
}
return null;
}
/**
* @return string
*/
public function __toString()
{
$reference = $this->getProcessCode().'['.$this->getState().']';
$time = $this->getStartDate()->format(\DateTime::ATOM);
return $reference.': '.$time;
}
}