1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Schema definitions install/update/uninstall hooks.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Implements hook_schema().
|
10
|
*/
|
11
|
function job_scheduler_schema() {
|
12
|
$schema = array();
|
13
|
$schema['job_schedule'] = array(
|
14
|
'description' => 'Schedule of jobs to be executed.',
|
15
|
'fields' => array(
|
16
|
'item_id' => array(
|
17
|
'type' => 'serial',
|
18
|
'unsigned' => TRUE,
|
19
|
'not null' => TRUE,
|
20
|
'description' => 'Primary Key: Unique item ID.',
|
21
|
),
|
22
|
'name' => array(
|
23
|
'type' => 'varchar',
|
24
|
'length' => 128,
|
25
|
'not null' => TRUE,
|
26
|
'default' => '',
|
27
|
'description' => 'Name of the schedule.',
|
28
|
),
|
29
|
'type' => array(
|
30
|
'type' => 'varchar',
|
31
|
'length' => 128,
|
32
|
'not null' => TRUE,
|
33
|
'default' => '',
|
34
|
'description' => 'Type identifier of the job.',
|
35
|
),
|
36
|
'id' => array(
|
37
|
'type' => 'int',
|
38
|
'not null' => TRUE,
|
39
|
'default' => 0,
|
40
|
'unsigned' => TRUE,
|
41
|
'description' => 'Numeric identifier of the job.',
|
42
|
),
|
43
|
'period' => array(
|
44
|
'type' => 'int',
|
45
|
'unsigned' => TRUE,
|
46
|
'default' => 0,
|
47
|
'not null' => TRUE,
|
48
|
'description' => 'Time period after which job is to be executed.',
|
49
|
),
|
50
|
'crontab' => array(
|
51
|
'type' => 'varchar',
|
52
|
'length' => 255,
|
53
|
'not null' => TRUE,
|
54
|
'default' => '',
|
55
|
'description' => 'Crontab line in *NIX format.',
|
56
|
),
|
57
|
'data' => array(
|
58
|
'type' => 'blob',
|
59
|
'not null' => FALSE,
|
60
|
'size' => 'big',
|
61
|
'serialize' => TRUE,
|
62
|
'description' => 'The arbitrary data for the item.',
|
63
|
),
|
64
|
'expire' => array(
|
65
|
'type' => 'int',
|
66
|
'not null' => TRUE,
|
67
|
'default' => 0,
|
68
|
'description' => 'Timestamp when job expires.',
|
69
|
),
|
70
|
'created' => array(
|
71
|
'type' => 'int',
|
72
|
'not null' => TRUE,
|
73
|
'default' => 0,
|
74
|
'description' => 'Timestamp when the item was created.',
|
75
|
),
|
76
|
'last' => array(
|
77
|
'type' => 'int',
|
78
|
'unsigned' => TRUE,
|
79
|
'default' => 0,
|
80
|
'not null' => TRUE,
|
81
|
'description' => 'Timestamp when a job was last executed.',
|
82
|
),
|
83
|
'periodic' => array(
|
84
|
'type' => 'int',
|
85
|
'size' => 'small',
|
86
|
'unsigned' => TRUE,
|
87
|
'default' => 0,
|
88
|
'not null' => TRUE,
|
89
|
'description' => 'If true job will be automatically rescheduled.',
|
90
|
),
|
91
|
'next' => array(
|
92
|
'type' => 'int',
|
93
|
'unsigned' => TRUE,
|
94
|
'default' => 0,
|
95
|
'not null' => TRUE,
|
96
|
'description' => 'Timestamp when a job is to be executed (next = last + period), used for fast ordering.',
|
97
|
),
|
98
|
'scheduled' => array(
|
99
|
'type' => 'int',
|
100
|
'unsigned' => TRUE,
|
101
|
'default' => 0,
|
102
|
'not null' => TRUE,
|
103
|
'description' => 'Timestamp when a job was scheduled. 0 if a job is currently not scheduled.',
|
104
|
),
|
105
|
),
|
106
|
'primary key' => array('item_id'),
|
107
|
'indexes' => array(
|
108
|
'name_type_id' => array('name', 'type', 'id'),
|
109
|
'name_type' => array('name', 'type'),
|
110
|
'next' => array('next'),
|
111
|
'scheduled' => array('scheduled'),
|
112
|
),
|
113
|
);
|
114
|
return $schema;
|
115
|
}
|
116
|
|
117
|
/**
|
118
|
* Fix indexes on next.
|
119
|
*/
|
120
|
function job_scheduler_update_6101() {
|
121
|
$ret = array();
|
122
|
db_drop_index($ret, 'job_schedule', 'last_period');
|
123
|
db_drop_index($ret, 'job_schedule', 'periodic');
|
124
|
db_add_index($ret, 'job_schedule', 'next', array('next'));
|
125
|
return $ret;
|
126
|
}
|
127
|
|
128
|
/**
|
129
|
* Rename 'callback' to 'name' field.
|
130
|
*/
|
131
|
function job_scheduler_update_7100() {
|
132
|
db_drop_index('job_schedule', 'callback_type_id');
|
133
|
db_drop_index('job_schedule', 'callback_type');
|
134
|
$spec = array(
|
135
|
'type' => 'varchar',
|
136
|
'length' => 128,
|
137
|
'not null' => TRUE,
|
138
|
'default' => '',
|
139
|
'description' => 'Name of the schedule.',
|
140
|
);
|
141
|
db_change_field('job_schedule', 'callback', 'name', $spec);
|
142
|
db_add_index('job_schedule', 'name_type_id', array('name', 'type', 'id'));
|
143
|
db_add_index('job_schedule', 'name_type', array('name', 'type'));
|
144
|
}
|
145
|
|
146
|
/**
|
147
|
* Add fields: item_id, crontab, data, expire
|
148
|
*/
|
149
|
function job_scheduler_update_7101() {
|
150
|
$spec = array(
|
151
|
'type' => 'varchar',
|
152
|
'length' => 255,
|
153
|
'not null' => TRUE,
|
154
|
'default' => '',
|
155
|
'description' => 'Crontab line in *NIX format.',
|
156
|
);
|
157
|
db_add_field('job_schedule', 'crontab', $spec);
|
158
|
$spec = array(
|
159
|
'type' => 'blob',
|
160
|
'not null' => FALSE,
|
161
|
'size' => 'big',
|
162
|
'serialize' => TRUE,
|
163
|
'description' => 'The arbitrary data for the item.',
|
164
|
);
|
165
|
db_add_field('job_schedule', 'data', $spec);
|
166
|
$spec = array(
|
167
|
'type' => 'int',
|
168
|
'not null' => TRUE,
|
169
|
'default' => 0,
|
170
|
'description' => 'Timestamp when job expires.',
|
171
|
);
|
172
|
db_add_field('job_schedule', 'expire', $spec);
|
173
|
$spec = array(
|
174
|
'type' => 'serial',
|
175
|
'unsigned' => TRUE,
|
176
|
'not null' => TRUE,
|
177
|
'description' => 'Primary Key: Unique item ID.',
|
178
|
);
|
179
|
db_add_field('job_schedule', 'item_id', $spec, array('primary key' => array('item_id')));
|
180
|
}
|