xs/queue.xs

filter: Statementstmt 90.9% 171 / 188 Branchbran 62.3% 121 / 194 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 76.4% 292 / 382 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« include/pq_tkr.h ↑ Summary include/pq_super.h »
1 MODULE = Punk::Queue PACKAGE = Punk::Queue
2  
3 # The front object. Every method here resolves the backend and delegates;
4 # nothing about a particular database appears in this file.
5  
6 SV *
7 new(class, ...)
8 SV *class
9 PREINIT:
10 HV *opts, *self;
11 SV *bclass, *backend, *rv;
12 int i;
13 CODE:
14 {
15 212 ▶ if ((items - 1) % 2)
Branch: 1 branch
BranchTrueFalseTotal
if ((items - 1) % 2) 0 212 212
16 0 croak("Punk::Queue->new: odd number of options");
17  
18 212 opts = newHV();
19 429 ▶ for (i = 1; i < items; i += 2)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 1; i < items; i += 2) 217 212 429
20 217 (void)hv_store_ent(opts, ST(i), newSVsv(ST(i + 1)), 0);
21  
22 /* An externally supplied handle is a legitimate way in - a test
23 * fixture, or an app that already manages its own connection. It
24 * still needs a backend class, so infer one from the driver. */
25 212 ▶ if (!pq_get(aTHX_ opts, "dsn") && !pq_get(aTHX_ opts, "backend")) {
Branch: 2 branches
BranchTrueFalseTotal
if (!pq_get(aTHX_ opts, "dsn") && !pq_get(aTHX_ opts, "backend")) { 0 212 212
if (!pq_get(aTHX_ opts, "dsn") && !pq_get(aTHX_ opts, "backend")) { 0 0 0
26 0 SV *dbh = pq_get(aTHX_ opts, "dbh");
27 0 ▶ if (dbh && SvROK(dbh)) {
Branch: 2 branches
BranchTrueFalseTotal
if (dbh && SvROK(dbh)) { 0 0 0
if (dbh && SvROK(dbh)) { 0 0 0
28 0 ▶ if (pq_driver_is(aTHX_ dbh, "SQLite"))
Branch: 1 branch
BranchTrueFalseTotal
if (pq_driver_is(aTHX_ dbh, "SQLite")) 0 0 0
29 0 (void)hv_stores(opts, "backend", newSVpvs("SQLite"));
30 0 ▶ else if (pq_driver_is(aTHX_ dbh, "Pg"))
Branch: 1 branch
BranchTrueFalseTotal
else if (pq_driver_is(aTHX_ dbh, "Pg")) 0 0 0
31 0 (void)hv_stores(opts, "backend", newSVpvs("Pg"));
32 }
33 }
34  
35 212 bclass = pq_backend_class(aTHX_ opts);
36 212 backend = pq_backend_construct(aTHX_ bclass, opts);
37  
38 212 self = newHV();
39 212 (void)hv_stores(self, "backend", backend);
40 212 (void)hv_stores(self, "tasks", newRV_noinc((SV *)newHV()));
41 212 (void)hv_stores(self, "opts", newRV_noinc((SV *)opts));
42  
43 212 rv = newRV_noinc((SV *)self);
44 212 ▶ sv_bless(rv, gv_stashsv(SvROK(class) ? SvRV(class) : class, GV_ADD));
Branch: 1 branch
BranchTrueFalseTotal
sv_bless(rv, gv_stashsv(SvROK(class) ? SvRV(class) : class, GV_ADD)); 0 212 212
45 212 RETVAL = rv;
46 }
47 OUTPUT:
48 RETVAL
49  
50 SV *
51 backend(self)
52 SV *self
53 CODE:
54 33 RETVAL = newSVsv(pq_backend_of(aTHX_ self));
55 OUTPUT:
56 RETVAL
57  
58 SV *
59 dbh(self)
60 SV *self
61 CODE:
62 66 RETVAL = newSVsv(pq_dbh(aTHX_ pq_backend_of(aTHX_ self)));
63 OUTPUT:
64 RETVAL
65  
66 IV
67 migrate(self, to = 0)
68 SV *self
69 IV to
70 CODE:
71 153 RETVAL = pq_migrate(aTHX_ pq_backend_of(aTHX_ self), to);
72 OUTPUT:
73 RETVAL
74  
75 IV
76 schema_version(self)
77 SV *self
78 CODE:
79 13 RETVAL = pq_schema_version(aTHX_ pq_backend_of(aTHX_ self));
80 OUTPUT:
81 RETVAL
82  
83 # task NAME => sub {...} - register a body. With one argument, look one up.
84 SV *
85 task(self, name, body = NULL)
86 SV *self
87 SV *name
88 SV *body
89 PREINIT:
90 HV *tasks;
91 CODE:
92 {
93 171 pq_name_check(aTHX_ name, "task");
94 171 tasks = pq_tasks(aTHX_ self);
95 171 ▶ if (body) {
Branch: 1 branch
BranchTrueFalseTotal
if (body) { 163 8 171
96 163 ▶ if (!(SvROK(body) && SvTYPE(SvRV(body)) == SVt_PVCV))
Branch: 2 branches
BranchTrueFalseTotal
if (!(SvROK(body) && SvTYPE(SvRV(body)) == SVt_PVCV)) 163 0 163
if (!(SvROK(body) && SvTYPE(SvRV(body)) == SVt_PVCV)) 0 163 163
97 0 croak("Punk::Queue: task '%s' needs a code reference",
98 SvPV_nolen(name));
99 163 (void)hv_store_ent(tasks, name, newSVsv(body), 0);
100 163 RETVAL = newSVsv(self); /* chainable */
101 }
102 else {
103 8 SV *found = pq_task_body(aTHX_ self, name);
104 8 ▶ RETVAL = found ? newSVsv(found) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = found ? newSVsv(found) : &PL_sv_undef; 8 0 8
105 8 ▶ if (!found) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!found) XSRETURN_UNDEF; 0 8 8
106 }
107 }
108 OUTPUT:
109 RETVAL
110  
111 void
112 tasks(self)
113 SV *self
114 PPCODE:
115 {
116 0 HV *t = pq_tasks(aTHX_ self);
117 HE *he;
118 0 hv_iterinit(t);
119 0 ▶ while ((he = hv_iternext(t)))
Branch: 1 branch
BranchTrueFalseTotal
while ((he = hv_iternext(t))) 0 0 0
120 0 ▶ XPUSHs(sv_2mortal(newSVsv(HeSVKEY_force(he))));
Branch: 3 branches
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVsv(HeSVKEY_force(he)))); 0 0 0
XPUSHs(sv_2mortal(newSVsv(HeSVKEY_force(he)))); 0 0 0
XPUSHs(sv_2mortal(newSVsv(HeSVKEY_force(he)))); 0 0 0
121 }
122  
123 # Per-queue and per-task defaults, merged into enqueue options at a fixed
124 # precedence: explicit, task, queue, built-in. Set with a hashref, read
125 # without one. Application configuration - lives on this object, not in
126 # the database.
127 SV *
128 queue_defaults(self, name, defaults = NULL)
129 SV *self
130 SV *name
131 SV *defaults
132 ALIAS:
133 task_defaults = 1
134 PREINIT:
135 HV *slot;
136 HE *he;
137 CODE:
138 {
139 4 ▶ pq_name_check(aTHX_ name, ix == 1 ? "task" : "queue");
Branch: 1 branch
BranchTrueFalseTotal
pq_name_check(aTHX_ name, ix == 1 ? "task" : "queue"); 1 3 4
140 4 ▶ slot = pq_defaults_slot(aTHX_ self,
Branch: 1 branch
BranchTrueFalseTotal
slot = pq_defaults_slot(aTHX_ self, 1 3 4
141 ix == 1 ? "task_defaults" : "queue_defaults");
142 4 ▶ if (defaults) {
Branch: 1 branch
BranchTrueFalseTotal
if (defaults) { 3 1 4
143 3 ▶ if (!(SvROK(defaults) && SvTYPE(SvRV(defaults)) == SVt_PVHV))
Branch: 2 branches
BranchTrueFalseTotal
if (!(SvROK(defaults) && SvTYPE(SvRV(defaults)) == SVt_PVHV)) 3 0 3
if (!(SvROK(defaults) && SvTYPE(SvRV(defaults)) == SVt_PVHV)) 0 3 3
144 0 croak("Punk::Queue: defaults must be a hash reference");
145 3 (void)hv_store_ent(slot, name, newSVsv(defaults), 0);
146 3 RETVAL = newSVsv(self); /* chainable */
147 }
148 else {
149 1 he = hv_fetch_ent(slot, name, 0, 0);
150 1 ▶ if (!he) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!he) XSRETURN_UNDEF; 0 1 1
151 1 RETVAL = newSVsv(HeVAL(he));
152 }
153 }
154 OUTPUT:
155 RETVAL
156  
157 IV
158 enqueue(self, task, args = NULL, ...)
159 SV *self
160 SV *task
161 SV *args
162 PREINIT:
163 HV *opts;
164 int i;
165 CODE:
166 {
167 /* items is 2 when args was defaulted away, so guard the subtraction
168 * before taking the modulus - C's % keeps the sign of a negative
169 * left operand, and (2 - 3) % 2 is -1, not 1. */
170 992 ▶ if (items > 3 && (items - 3) % 2)
Branch: 2 branches
BranchTrueFalseTotal
if (items > 3 && (items - 3) % 2) 81 911 992
if (items > 3 && (items - 3) % 2) 1 80 81
171 1 croak("Punk::Queue->enqueue: odd number of options");
172 991 ▶ if (args && SvOK(args)
Branch: 2 branches
BranchTrueFalseTotal
if (args && SvOK(args) 704 287 991
if (args && SvOK(args) 704 0 704
173 704 ▶ && !(SvROK(args) && SvTYPE(SvRV(args)) == SVt_PVAV))
Branch: 2 branches
BranchTrueFalseTotal
&& !(SvROK(args) && SvTYPE(SvRV(args)) == SVt_PVAV)) 704 0 704
&& !(SvROK(args) && SvTYPE(SvRV(args)) == SVt_PVAV)) 1 703 704
174 1 croak("Punk::Queue->enqueue: args must be an array reference");
175  
176 990 opts = (HV *)sv_2mortal((SV *)newHV());
177 1102 ▶ for (i = 3; i < items; i += 2)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 3; i < items; i += 2) 112 990 1102
178 112 (void)hv_store_ent(opts, ST(i), newSVsv(ST(i + 1)), 0);
179  
180 990 pq_merge_defaults(aTHX_ self, task, opts);
181 990 pq_ensure_migrated(aTHX_ self);
182 990 RETVAL = pq_enqueue(aTHX_ pq_backend_of(aTHX_ self), task, args, opts);
183 }
184 OUTPUT:
185 RETVAL
186  
187 # Claim one job. Returns a Punk::Queue::Job, or undef when nothing is ready.
188 SV *
189 dequeue(self, ...)
190 SV *self
191 PREINIT:
192 HV *opts;
193 SV *backend, *row;
194 AV *queues, *tasks;
195 200 IV worker_id = 0;
196 int i;
197 CODE:
198 {
199 200 ▶ if ((items - 1) % 2)
Branch: 1 branch
BranchTrueFalseTotal
if ((items - 1) % 2) 0 200 200
200 0 croak("Punk::Queue->dequeue: odd number of options");
201 200 opts = (HV *)sv_2mortal((SV *)newHV());
202 332 ▶ for (i = 1; i < items; i += 2)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 1; i < items; i += 2) 132 200 332
203 132 (void)hv_store_ent(opts, ST(i), newSVsv(ST(i + 1)), 0);
204  
205 {
206 200 SV *w = pq_get(aTHX_ opts, "worker");
207 200 ▶ if (w && SvOK(w)) worker_id = SvIV(w);
Branch: 2 branches
BranchTrueFalseTotal
if (w && SvOK(w)) worker_id = SvIV(w); 109 91 200
if (w && SvOK(w)) worker_id = SvIV(w); 109 0 109
208 }
209  
210 200 queues = pq_sql_list(aTHX_ pq_get(aTHX_ opts, "queues"));
211 200 ▶ if (av_len(queues) < 0) av_push(queues, newSVpvs("default"));
Branch: 1 branch
BranchTrueFalseTotal
if (av_len(queues) < 0) av_push(queues, newSVpvs("default")); 183 17 200
212 200 tasks = pq_sql_list(aTHX_ pq_get(aTHX_ opts, "tasks"));
213  
214 200 pq_ensure_migrated(aTHX_ self);
215 200 backend = pq_backend_of(aTHX_ self);
216 200 row = pq_dequeue(aTHX_ backend, worker_id, queues, tasks);
217 200 ▶ if (!row) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!row) XSRETURN_UNDEF; 21 179 200
218  
219 179 RETVAL = pq_job_new(aTHX_ self, (HV *)SvRV(row));
220 179 SvREFCNT_dec(row);
221 }
222 OUTPUT:
223 RETVAL
224  
225 SV *
226 job_info(self, id)
227 SV *self
228 IV id
229 PREINIT:
230 SV *info;
231 CODE:
232 228 pq_ensure_migrated(aTHX_ self);
233 228 info = pq_job_info(aTHX_ pq_backend_of(aTHX_ self), id);
234 228 ▶ if (!info) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!info) XSRETURN_UNDEF; 11 217 228
235 217 RETVAL = info;
236 OUTPUT:
237 RETVAL
238  
239 SV *
240 job_log(self, id)
241 SV *self
242 IV id
243 CODE:
244 9 pq_ensure_migrated(aTHX_ self);
245 9 RETVAL = newRV_noinc((SV *)pq_job_log_rows(aTHX_
246 pq_backend_of(aTHX_ self), id));
247 OUTPUT:
248 RETVAL
249  
250 IV
251 finish_job(self, id, retries, result = NULL)
252 SV *self
253 IV id
254 IV retries
255 SV *result
256 CODE:
257 12 RETVAL = pq_finish_job(aTHX_ pq_backend_of(aTHX_ self), id, retries,
258 result);
259 OUTPUT:
260 RETVAL
261  
262 IV
263 fail_job(self, id, retries, err = NULL)
264 SV *self
265 IV id
266 IV retries
267 SV *err
268 CODE:
269 3 RETVAL = pq_fail_job(aTHX_ pq_backend_of(aTHX_ self), id, retries, err);
270 OUTPUT:
271 RETVAL
272  
273 # Run one claimed job to completion: look up the body, call it, settle the
274 # row. Returns true when the job finished, false when it failed.
275 IV
276 perform(self, job)
277 SV *self
278 SV *job
279 CODE:
280 66 ▶ RETVAL = pq_perform(aTHX_ self, job);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = pq_perform(aTHX_ self, job); 9 50 59
281 OUTPUT:
282 RETVAL
283  
284 # The worker's claim entry: positional, no option parsing, G_EVAL-called
285 # from C so a raised claim never unwinds the loop. Takes what the worker
286 # already holds (id, queues arrayref, tasks arrayref) and returns a Job,
287 # or nothing. Not documented API; the keyword form above is.
288 SV *
289 dequeue_ref(self, worker_id, queues, tasks)
290 SV *self
291 IV worker_id
292 SV *queues
293 SV *tasks
294 PREINIT:
295 AV *q, *t;
296 SV *row;
297 CODE:
298 {
299 37 q = pq_sql_list(aTHX_ queues);
300 37 ▶ if (av_len(q) < 0) av_push(q, newSVpvs("default"));
Branch: 1 branch
BranchTrueFalseTotal
if (av_len(q) < 0) av_push(q, newSVpvs("default")); 0 37 37
301 37 t = pq_sql_list(aTHX_ tasks);
302 37 pq_ensure_migrated(aTHX_ self);
303 37 row = pq_dequeue(aTHX_ pq_backend_of(aTHX_ self), worker_id, q, t);
304 37 ▶ if (!row) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!row) XSRETURN_UNDEF; 16 21 37
305 21 RETVAL = pq_job_new(aTHX_ self, (HV *)SvRV(row));
306 21 SvREFCNT_dec(row);
307 }
308 OUTPUT:
309 RETVAL
310  
311 # Front delegators for the management surface, so the CLI and the phase-8
312 # plugin never reach around the queue object to its backend.
313  
314 IV
315 retry_job(self, id, retries, opts = NULL)
316 SV *self
317 IV id
318 IV retries
319 SV *opts
320 PREINIT:
321 12 ▶ HV *o = NULL;
Branch: 1 branch
BranchTrueFalseTotal
HV *o = NULL; 12 0 12
322 CODE:
323 12 ▶ if (opts && SvROK(opts) && SvTYPE(SvRV(opts)) == SVt_PVHV)
Branch: 3 branches
BranchTrueFalseTotal
if (opts && SvROK(opts) && SvTYPE(SvRV(opts)) == SVt_PVHV) 5 7 12
if (opts && SvROK(opts) && SvTYPE(SvRV(opts)) == SVt_PVHV) 5 0 5
if (opts && SvROK(opts) && SvTYPE(SvRV(opts)) == SVt_PVHV) 5 0 5
324 5 o = (HV *)SvRV(opts);
325 12 pq_ensure_migrated(aTHX_ self);
326 12 RETVAL = pq_retry_job(aTHX_ pq_backend_of(aTHX_ self), id, retries, o);
327 OUTPUT:
328 RETVAL
329  
330 IV
331 remove_job(self, id)
332 SV *self
333 IV id
334 CODE:
335 13 pq_ensure_migrated(aTHX_ self);
336 13 RETVAL = pq_remove_job(aTHX_ pq_backend_of(aTHX_ self), id);
337 OUTPUT:
338 RETVAL
339  
340 SV *
341 list_jobs(self, offset = 0, limit = 0, filter = NULL, sort_col = NULL, sort_dir = NULL)
342 SV *self
343 IV offset
344 IV limit
345 SV *filter
346 SV *sort_col
347 SV *sort_dir
348 PREINIT:
349 55 ▶ HV *f = NULL;
Branch: 1 branch
BranchTrueFalseTotal
HV *f = NULL; 2 53 55
350 CODE:
351 55 ▶ if (filter && SvROK(filter) && SvTYPE(SvRV(filter)) == SVt_PVHV)
Branch: 3 branches
BranchTrueFalseTotal
if (filter && SvROK(filter) && SvTYPE(SvRV(filter)) == SVt_PVHV) 52 3 55
if (filter && SvROK(filter) && SvTYPE(SvRV(filter)) == SVt_PVHV) 52 0 52
if (filter && SvROK(filter) && SvTYPE(SvRV(filter)) == SVt_PVHV) 52 0 52
352 52 f = (HV *)SvRV(filter);
353 55 pq_ensure_migrated(aTHX_ self);
354 55 RETVAL = pq_list_jobs(aTHX_ pq_backend_of(aTHX_ self), offset, limit, f, sort_col, sort_dir);
355 OUTPUT:
356 RETVAL
357  
358 SV *
359 list_workers(self, offset = 0, limit = 0, filter = NULL)
360 SV *self
361 IV offset
362 IV limit
363 SV *filter
364 PREINIT:
365 124 ▶ HV *f = NULL;
Branch: 1 branch
BranchTrueFalseTotal
HV *f = NULL; 116 8 124
366 CODE:
367 124 ▶ if (filter && SvROK(filter) && SvTYPE(SvRV(filter)) == SVt_PVHV)
Branch: 3 branches
BranchTrueFalseTotal
if (filter && SvROK(filter) && SvTYPE(SvRV(filter)) == SVt_PVHV) 8 116 124
if (filter && SvROK(filter) && SvTYPE(SvRV(filter)) == SVt_PVHV) 7 1 8
if (filter && SvROK(filter) && SvTYPE(SvRV(filter)) == SVt_PVHV) 7 0 7
368 7 f = (HV *)SvRV(filter);
369 124 pq_ensure_migrated(aTHX_ self);
370 124 RETVAL = pq_list_workers(aTHX_ pq_backend_of(aTHX_ self), offset,
371 limit, f);
372 OUTPUT:
373 RETVAL
374  
375 SV *
376 stats(self)
377 SV *self
378 CODE:
379 97 pq_ensure_migrated(aTHX_ self);
380 97 RETVAL = pq_stats(aTHX_ pq_backend_of(aTHX_ self));
381 OUTPUT:
382 RETVAL
383  
384 void
385 reset(self)
386 SV *self
387 CODE:
388 2 pq_ensure_migrated(aTHX_ self);
389 2 pq_reset(aTHX_ pq_backend_of(aTHX_ self));
390  
391 SV *
392 repair(self, ...)
393 SV *self
394 PREINIT:
395 HV *opts;
396 SV *v;
397 5 int i, deep = 0;
398 CODE:
399 {
400 5 ▶ if ((items - 1) % 2)
Branch: 1 branch
BranchTrueFalseTotal
if ((items - 1) % 2) 0 5 5
401 0 croak("Punk::Queue->repair: odd number of options");
402 5 opts = (HV *)sv_2mortal((SV *)newHV());
403 7 ▶ for (i = 1; i < items; i += 2)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 1; i < items; i += 2) 2 5 7
404 2 (void)hv_store_ent(opts, ST(i), newSVsv(ST(i + 1)), 0);
405 5 ▶ if ((v = pq_get(aTHX_ opts, "deep")) && SvTRUE(v)) deep = 1;
Branch: 2 branches
BranchTrueFalseTotal
if ((v = pq_get(aTHX_ opts, "deep")) && SvTRUE(v)) deep = 1; 2 3 5
if ((v = pq_get(aTHX_ opts, "deep")) && SvTRUE(v)) deep = 1; 2 0 2
406 5 pq_ensure_migrated(aTHX_ self);
407 5 RETVAL = pq_repair(aTHX_ pq_backend_of(aTHX_ self), deep);
408 }
409 OUTPUT:
410 RETVAL
411  
412 SV *
413 history(self)
414 SV *self
415 CODE:
416 2 pq_ensure_migrated(aTHX_ self);
417 2 RETVAL = pq_history(aTHX_ pq_backend_of(aTHX_ self));
418 OUTPUT:
419 RETVAL
420  
421 SV *
422 list_locks(self, offset = 0, limit = 0, filter = NULL)
423 SV *self
424 IV offset
425 IV limit
426 SV *filter
427 PREINIT:
428 10 ▶ HV *f = NULL;
Branch: 1 branch
BranchTrueFalseTotal
HV *f = NULL; 0 10 10
429 CODE:
430 10 ▶ if (filter && SvROK(filter) && SvTYPE(SvRV(filter)) == SVt_PVHV)
Branch: 3 branches
BranchTrueFalseTotal
if (filter && SvROK(filter) && SvTYPE(SvRV(filter)) == SVt_PVHV) 10 0 10
if (filter && SvROK(filter) && SvTYPE(SvRV(filter)) == SVt_PVHV) 10 0 10
if (filter && SvROK(filter) && SvTYPE(SvRV(filter)) == SVt_PVHV) 10 0 10
431 10 f = (HV *)SvRV(filter);
432 10 pq_ensure_migrated(aTHX_ self);
433 10 RETVAL = pq_list_locks(aTHX_ pq_backend_of(aTHX_ self), offset,
434 limit, f);
435 OUTPUT:
436 RETVAL
437  
438 IV
439 lock(self, name, duration, ...)
440 SV *self
441 SV *name
442 NV duration
443 PREINIT:
444 HV *opts;
445 SV *v;
446 int i;
447 13 ▶ IV limit = 1, owner = 0;
Branch: 1 branch
BranchTrueFalseTotal
IV limit = 1, owner = 0; 13 0 13
448 CODE:
449 {
450 13 ▶ if ((items - 3) % 2 && items > 3)
Branch: 2 branches
BranchTrueFalseTotal
if ((items - 3) % 2 && items > 3) 0 13 13
if ((items - 3) % 2 && items > 3) 0 0 0
451 0 croak("Punk::Queue->lock: odd number of options");
452 13 opts = (HV *)sv_2mortal((SV *)newHV());
453 22 ▶ for (i = 3; i < items; i += 2)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 3; i < items; i += 2) 9 13 22
454 9 (void)hv_store_ent(opts, ST(i), newSVsv(ST(i + 1)), 0);
455 13 ▶ if ((v = pq_get(aTHX_ opts, "limit")) && SvOK(v)) limit = SvIV(v);
Branch: 2 branches
BranchTrueFalseTotal
if ((v = pq_get(aTHX_ opts, "limit")) && SvOK(v)) limit = SvIV(v); 6 7 13
if ((v = pq_get(aTHX_ opts, "limit")) && SvOK(v)) limit = SvIV(v); 6 0 6
456 13 ▶ if ((v = pq_get(aTHX_ opts, "owner")) && SvOK(v)) owner = SvIV(v);
Branch: 2 branches
BranchTrueFalseTotal
if ((v = pq_get(aTHX_ opts, "owner")) && SvOK(v)) owner = SvIV(v); 3 10 13
if ((v = pq_get(aTHX_ opts, "owner")) && SvOK(v)) owner = SvIV(v); 3 0 3
457 13 pq_ensure_migrated(aTHX_ self);
458 13 RETVAL = pq_lock(aTHX_ pq_backend_of(aTHX_ self), name, duration,
459 limit, owner);
460 }
461 OUTPUT:
462 RETVAL
463  
464 IV
465 unlock(self, name, owner = NULL)
466 SV *self
467 SV *name
468 SV *owner
469 CODE:
470 3 pq_ensure_migrated(aTHX_ self);
471 7 ▶ RETVAL = pq_unlock(aTHX_ pq_backend_of(aTHX_ self), name,
Branch: 2 branches
BranchTrueFalseTotal
RETVAL = pq_unlock(aTHX_ pq_backend_of(aTHX_ self), name, 2 1 3
RETVAL = pq_unlock(aTHX_ pq_backend_of(aTHX_ self), name, 2 1 3
472 2 ▶ (owner && SvOK(owner)) ? SvIV(owner) : 0,
Branch: 1 branch
BranchTrueFalseTotal
(owner && SvOK(owner)) ? SvIV(owner) : 0, 2 0 2
473 2 ▶ (owner && SvOK(owner)) ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
(owner && SvOK(owner)) ? 1 : 0); 2 0 2
474 OUTPUT:
475 RETVAL
476  
477 IV
478 renew_lock(self, name, owner, duration)
479 SV *self
480 SV *name
481 IV owner
482 NV duration
483 CODE:
484 3 pq_ensure_migrated(aTHX_ self);
485 3 RETVAL = pq_renew_lock(aTHX_ pq_backend_of(aTHX_ self), name,
486 owner, duration);
487 OUTPUT:
488 RETVAL
489  
490 IV
491 broadcast(self, cmd, args = NULL, ids = NULL)
492 SV *self
493 SV *cmd
494 SV *args
495 SV *ids
496 PREINIT:
497 6 ▶ AV *a = NULL, *w = NULL;
Branch: 1 branch
BranchTrueFalseTotal
AV *a = NULL, *w = NULL; 6 0 6
498 CODE:
499 6 ▶ if (args && SvROK(args) && SvTYPE(SvRV(args)) == SVt_PVAV)
Branch: 3 branches
BranchTrueFalseTotal
if (args && SvROK(args) && SvTYPE(SvRV(args)) == SVt_PVAV) 5 1 6
if (args && SvROK(args) && SvTYPE(SvRV(args)) == SVt_PVAV) 5 0 5
if (args && SvROK(args) && SvTYPE(SvRV(args)) == SVt_PVAV) 5 0 5
500 5 a = (AV *)SvRV(args);
501 6 ▶ if (ids && SvROK(ids) && SvTYPE(SvRV(ids)) == SVt_PVAV)
Branch: 3 branches
BranchTrueFalseTotal
if (ids && SvROK(ids) && SvTYPE(SvRV(ids)) == SVt_PVAV) 5 1 6
if (ids && SvROK(ids) && SvTYPE(SvRV(ids)) == SVt_PVAV) 5 0 5
if (ids && SvROK(ids) && SvTYPE(SvRV(ids)) == SVt_PVAV) 5 0 5
502 5 w = (AV *)SvRV(ids);
503 6 pq_ensure_migrated(aTHX_ self);
504 6 RETVAL = pq_broadcast(aTHX_ pq_backend_of(aTHX_ self), cmd, a, w);
505 OUTPUT:
506 RETVAL
507  
508 # A worker bound to this queue: $q->worker(%opts)->run. Options are the
509 # worker's (queues, tasks, interval, heartbeat_interval, max_jobs).
510 SV *
511 worker(self, ...)
512 SV *self
513 PREINIT:
514 HV *opts, *w;
515 SV *rv;
516 int i;
517 CODE:
518 {
519 14 ▶ if ((items - 1) % 2)
Branch: 1 branch
BranchTrueFalseTotal
if ((items - 1) % 2) 0 14 14
520 0 croak("Punk::Queue->worker: odd number of options");
521 14 opts = newHV();
522 18 ▶ for (i = 1; i < items; i += 2)
Branch: 1 branch
BranchTrueFalseTotal
for (i = 1; i < items; i += 2) 4 14 18
523 4 (void)hv_store_ent(opts, ST(i), newSVsv(ST(i + 1)), 0);
524  
525 14 w = newHV();
526 14 (void)hv_stores(w, "queue", newSVsv(self));
527 14 (void)hv_stores(w, "opts", newRV_noinc((SV *)opts));
528 14 rv = newRV_noinc((SV *)w);
529 14 sv_bless(rv, gv_stashpvs("Punk::Queue::Worker", GV_ADD));
530 14 RETVAL = rv;
531 }
532 OUTPUT:
533 RETVAL
534  
535 # The in-server attach seam: called once per web-worker process from the
536 # plugin's lazy before_dispatch hook. Returns true when armed, false when
537 # there is no live Hyperman loop - in-server is an enhancement, never a
538 # requirement. (This internal XSUB is what replaced the deferred ABI's
539 # worker_new for the same-dist consumer.)
540 IV
541 _inserver_attach(queue, opts = NULL)
542 SV *queue
543 SV *opts
544 PREINIT:
545 3 ▶ HV *o = NULL;
Branch: 1 branch
BranchTrueFalseTotal
HV *o = NULL; 3 0 3
546 CODE:
547 3 ▶ if (opts && SvROK(opts) && SvTYPE(SvRV(opts)) == SVt_PVHV)
Branch: 3 branches
BranchTrueFalseTotal
if (opts && SvROK(opts) && SvTYPE(SvRV(opts)) == SVt_PVHV) 3 0 3
if (opts && SvROK(opts) && SvTYPE(SvRV(opts)) == SVt_PVHV) 3 0 3
if (opts && SvROK(opts) && SvTYPE(SvRV(opts)) == SVt_PVHV) 3 0 3
548 3 o = (HV *)SvRV(opts);
549 3 ▶ RETVAL = pq_inserver_attach(aTHX_ queue, o);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = pq_inserver_attach(aTHX_ queue, o); 0 3 3
550 OUTPUT:
551 RETVAL
552  
553 # Front delegators for the cron surface.
554  
555 IV
556 upsert_cron(self, def)
557 SV *self
558 SV *def
559 PREINIT:
560 29 ▶ HV *d = NULL;
Branch: 1 branch
BranchTrueFalseTotal
HV *d = NULL; 29 0 29
561 CODE:
562 29 ▶ if (def && SvROK(def) && SvTYPE(SvRV(def)) == SVt_PVHV)
Branch: 3 branches
BranchTrueFalseTotal
if (def && SvROK(def) && SvTYPE(SvRV(def)) == SVt_PVHV) 29 0 29
if (def && SvROK(def) && SvTYPE(SvRV(def)) == SVt_PVHV) 29 0 29
if (def && SvROK(def) && SvTYPE(SvRV(def)) == SVt_PVHV) 29 0 29
563 29 d = (HV *)SvRV(def);
564 29 ▶ if (!d) croak("Punk::Queue: upsert_cron needs a hash reference");
Branch: 1 branch
BranchTrueFalseTotal
if (!d) croak("Punk::Queue: upsert_cron needs a hash reference"); 0 29 29
565 29 pq_ensure_migrated(aTHX_ self);
566 29 RETVAL = pq_upsert_cron(aTHX_ pq_backend_of(aTHX_ self), d);
567 OUTPUT:
568 RETVAL
569  
570 IV
571 disable_missing_crons(self, names = NULL)
572 SV *self
573 SV *names
574 PREINIT:
575 20 ▶ AV *n = NULL;
Branch: 1 branch
BranchTrueFalseTotal
AV *n = NULL; 20 0 20
576 CODE:
577 20 ▶ if (names && SvROK(names) && SvTYPE(SvRV(names)) == SVt_PVAV)
Branch: 3 branches
BranchTrueFalseTotal
if (names && SvROK(names) && SvTYPE(SvRV(names)) == SVt_PVAV) 20 0 20
if (names && SvROK(names) && SvTYPE(SvRV(names)) == SVt_PVAV) 20 0 20
if (names && SvROK(names) && SvTYPE(SvRV(names)) == SVt_PVAV) 20 0 20
578 20 n = (AV *)SvRV(names);
579 20 pq_ensure_migrated(aTHX_ self);
580 20 RETVAL = pq_disable_missing_crons(aTHX_ pq_backend_of(aTHX_ self), n);
581 OUTPUT:
582 RETVAL
583  
584 IV
585 enable_cron(self, name, on = 1)
586 SV *self
587 SV *name
588 IV on
589 CODE:
590 8 pq_ensure_migrated(aTHX_ self);
591 8 RETVAL = pq_enable_cron(aTHX_ pq_backend_of(aTHX_ self), name,
592 on ? 1 : 0);
593 OUTPUT:
594 RETVAL
595  
596 SV *
597 cron_info(self, name)
598 SV *self
599 SV *name
600 PREINIT:
601 SV *info;
602 CODE:
603 33 pq_ensure_migrated(aTHX_ self);
604 33 info = pq_cron_info(aTHX_ pq_backend_of(aTHX_ self), name);
605 33 ▶ if (!info) XSRETURN_UNDEF;
Branch: 1 branch
BranchTrueFalseTotal
if (!info) XSRETURN_UNDEF; 3 30 33
606 30 RETVAL = info;
607 OUTPUT:
608 RETVAL
609  
610 SV *
611 list_crons(self, offset = 0, limit = 0)
612 SV *self
613 IV offset
614 IV limit
615 CODE:
616 6 pq_ensure_migrated(aTHX_ self);
617 6 RETVAL = pq_list_crons(aTHX_ pq_backend_of(aTHX_ self), offset,
618 limit);
619 OUTPUT:
620 RETVAL
« include/pq_tkr.h ↑ Summary include/pq_super.h »