forked from forceworkbench/forceworkbench
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathasync_worker.php
More file actions
43 lines (38 loc) · 1.23 KB
/
Copy pathasync_worker.php
File metadata and controls
43 lines (38 loc) · 1.23 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
<?php
require_once 'shared.php';
require_once 'config/constants.php';
require_once 'config/WorkbenchConfig.php';
require_once 'context/WorkbenchContext.php';
require_once 'soxl/QueryObjects.php';
foreach (scandir('async') as $f) {
if ($f == "." || $f == "..") continue;
require_once "async/$f";
}
// block direct web access
if (php_sapi_name() != 'cli') {
httpError(404, "Not Found");
}
$_SERVER['REMOTE_ADDR'] = 'CLI-' . getmypid();
$_SERVER['REQUEST_METHOD'] = 'ASYNC';
// future result gc
$frKeys = redis()->keys(FutureResult::RESULT . "*");
foreach ($frKeys as $frKey) {
$asyncId = substr($frKey, strlen(FutureResult::RESULT));
if (!redis()->exists(FUTURE_LOCK . $asyncId)) {
redis()->del($frKey);
workbenchLog(LOG_INFO, "FutureResultGC", array("async_id" => $asyncId, "measure.async.gc.result" => 1 . "result"));
}
}
workbenchLog(LOG_INFO, "FutureTaskQueueDepth", array("measure.async.queue_depth" => redis()->llen(FutureTask::QUEUE) . "task"));
while (true) {
try {
$job = FutureTask::dequeue(30);
set_time_limit(WorkbenchConfig::get()->value('asyncTimeoutSeconds'));
$job->execute();
} catch (TimeoutException $e) {
continue;
}
redis()->close();
exit();
}
?>