-
Notifications
You must be signed in to change notification settings - Fork 7
/
ultimate_cron.install
executable file
·213 lines (199 loc) · 5.37 KB
/
ultimate_cron.install
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
<?php
/**
* @file
* Installation file for Ultimate Cron
*/
use Drupal\Core\Url;
use Drupal\ultimate_cron\Entity\CronJob;
/**
* Implements hook_schema().
*/
function ultimate_cron_schema() {
$schema = array();
$schema['ultimate_cron_log'] = array(
'description' => 'Logs',
'fields' => array(
'lid' => array(
'description' => 'Lock ID',
'type' => 'varchar',
'length' => 176,
'not null' => TRUE,
),
'name' => array(
'description' => 'Name',
'type' => 'varchar',
'length' => 166,
'not null' => TRUE,
),
'log_type' => array(
'description' => 'Log type',
'type' => 'int',
'size' => 'normal',
'not null' => TRUE,
'default' => 0,
),
'start_time' => array(
'description' => 'Timestamp of execution start',
'type' => 'float',
'size' => 'big',
'not null' => TRUE,
'default' => 0,
),
'end_time' => array(
'description' => 'Timestamp of execution end',
'type' => 'float',
'size' => 'big',
'not null' => TRUE,
'default' => 0,
),
'uid' => array(
'description' => 'User ID',
'type' => 'int',
'size' => 'normal',
'not null' => TRUE,
'default' => 0,
),
'init_message' => array(
'description' => 'Initial message',
'type' => 'text',
'not null' => FALSE,
),
'message' => array(
'description' => 'Message',
'type' => 'text',
'not null' => FALSE,
),
'severity' => array(
'description' => 'Max severity level of the execution',
'type' => 'int',
'size' => 'normal',
'not null' => FALSE,
'default' => -1,
),
),
'primary key' => array('lid'),
'indexes' => array(
'idx_last' => array(
array('name', 80),
'start_time',
'end_time',
'log_type',
),
),
);
$schema['ultimate_cron_lock'] = array(
'description' => 'Locks',
'fields' => array(
'lid' => array(
'description' => 'Lock ID',
'type' => 'serial',
'size' => 'big',
'not null' => TRUE,
),
'name' => array(
'description' => 'Name',
'type' => 'varchar',
'length' => 166,
'not null' => TRUE,
),
'current' => array(
'description' => 'Current lock',
'type' => 'int',
'size' => 'big',
'not null' => TRUE,
'default' => 0,
),
'expire' => array(
'description' => 'Expiration time of lock',
'type' => 'float',
'size' => 'big',
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array('lid'),
'unique keys' => array(
'idx_name' => array('name', 'current'),
),
);
$schema['ultimate_cron_signal'] = array(
'description' => 'Signals',
'fields' => array(
'job_name' => array(
'description' => 'Name of job',
'type' => 'varchar',
'length' => 166,
'not null' => TRUE,
),
'signal_name' => array(
'description' => 'Name of signal',
'type' => 'varchar',
'length' => 166,
'not null' => TRUE,
),
'claimed' => array(
'description' => 'Is signal claimed',
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array('job_name', 'signal_name'),
);
return $schema;
}
/**
* Implements hook_install().
*/
function ultimate_cron_install() {
\Drupal::service('ultimate_cron.discovery')->discoverCronJobs();
}
/**
* Implements hook_requirements().
*/
function ultimate_cron_requirements($phase) {
$requirements = array();
switch ($phase) {
case 'install':
return $requirements;
case 'runtime':
$requirements['title'] = 'Ultimate Cron';
$requirements['value'] = array();
$requirements['description'] = array();
$requirements['severity'] = REQUIREMENT_OK;
// @todo: port this
// Check if any jobs are behind.
$jobs_behind = 0;
$jobs = CronJob::loadMultiple();
foreach ($jobs as $job) {
if ($job->isBehindSchedule()) {
$jobs_behind++;
}
}
if ($jobs_behind) {
$requirements['severity'] = $requirements['severity'] > REQUIREMENT_ERROR ? $requirements['severity'] : REQUIREMENT_ERROR;
$requirements['value'][] = \Drupal::translation()->formatPlural(
$jobs_behind,
'@count job is behind schedule',
'@count jobs are behind schedule'
);
$requirements['description'][] = t(
'Some jobs are behind their schedule. Please check if @link is running properly.', array(
'@link' => \Drupal::l(t('Cron'), Url::fromRoute('system.cron', ['key' => \Drupal::state()->get('system.cron_key')])),
));
}
// Compose result.
if (empty($requirements['value'])) {
$requirements['value'] = t('Cron is running properly.');
$requirements['description'] = '';
}
else {
$requirements['value'] = implode(', ', $requirements['value']);
$requirements['description'] = implode('<br/>', $requirements['description']);
}
$result = array();
$result['ultimate_cron'] = $requirements;
return $result;
}
}