-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.php
68 lines (59 loc) · 1.82 KB
/
index.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
<?php
require __DIR__ . "/src/classes/Job.php";
require __DIR__ . "/src/classes/Queue.php";
require __DIR__ . "/src/classes/Queueworker.php";
// For composer
@include_once __DIR__ . '/vendor/autoload.php';
Kirby::plugin('bvdputte/kirbyqueue', [
'options' => [
'root' => 'queues',
'worker.route' => 'kqueueworker-supersecreturlkey',
'poormanscron' => false,
'poormanscron.interval' => 60, // in seconds
'queues' => []
],
'routes' => function ($kirby) {
return [
[
'pattern' => $kirby->option("bvdputte.kirbyqueue.worker.route"),
'action' => function () {
bvdputte\kirbyQueue\Queueworker::work();
exit();
}
]
];
}
]);
/*
A little Kirby helper function to create a Queue and a Job
*/
if (! function_exists("kqQueue")) {
function kqQueue($name) {
$queues = kirby()->option("bvdputte.kirbyqueue.queues");
if( array_key_exists($name, $queues) ) {
$kirbyQueue = new bvdputte\kirbyQueue\Queue($name, $queues[$name]);
}
return $kirbyQueue;
}
}
if (! function_exists("kqJob")) {
function kqJob($data) {
$job = new bvdputte\kirbyQueue\Job();
$job->data($data);
return $job;
}
}
/*
For servers without cron, enable "poormanscron"
*/
if (option("bvdputte.kirbyqueue.poormanscron")) {
$root = kirby()->roots()->site() . '/' . option("bvdputte.kirbyqueue.root");
$pmcFile = $root . "/.pmc";
if (!f::exists($pmcFile)) f::write($pmcFile, time());
$nextRun = f::read($pmcFile) + option("bvdputte.kirbyqueue.poormanscron.interval");
if( $nextRun < time() ) {
// Work the queue
bvdputte\kirbyQueue\Queueworker::work();
f::write($pmcFile, time());
}
}