Skip to content
This repository was archived by the owner on Nov 25, 2020. It is now read-only.

Commit 0a3c1f2

Browse files
committed
Fix the way scheduler handle the "*" users to make it less consuming (not necessary to load whole user objects, jst their ID.). Always use queue mechanism.
1 parent b983ee8 commit 0a3c1f2

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

core/src/plugins/action.scheduler/class.AjxpScheduler.php

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,16 @@ public function runTask($taskId, $status = null, &$currentlyRunning = -1, $force
175175
$queued = false;
176176
}
177177
if ( ( $res >= $lastExec && $res < $now && !$alreadyRunning ) || $queued || $forceStart) {
178-
if ($data["user_id"] == "*") {
179-
$data["user_id"] = implode(",", array_keys(AuthService::listUsers()));
180-
} else if ($data["user_id"] == "*/*") {
178+
if ($data["user_id"] == "*/*" || $data["user_id"] == "*") {
181179
// Recurse all groups and put them into a queue file
182180
$allUsers = array();
183-
$this->gatherUsers($allUsers, "/");
181+
if($data["user_id"] == "*"){
182+
$allUsers = $this->listUsersIds();
183+
}else{
184+
$this->gatherUsers($allUsers, "/");
185+
}
184186
$tmpQueue = AJXP_CACHE_DIR."/cmd_outputs/queue_".$taskId."";
187+
echo "Queuing ".count($allUsers)." users in file ".$tmpQueue."\n";
185188
file_put_contents($tmpQueue, implode(",", $allUsers));
186189
$data["user_id"] = "queue:".$tmpQueue;
187190
}
@@ -205,10 +208,16 @@ public function runTask($taskId, $status = null, &$currentlyRunning = -1, $force
205208
return false;
206209
}
207210

211+
protected function listUsersIds($baseGroup = "/"){
212+
$authDriver = ConfService::getAuthDriverImpl();
213+
$pairs = $authDriver->listUsers($baseGroup);
214+
return array_keys($pairs);
215+
}
216+
208217
protected function gatherUsers(&$users, $startGroup="/")
209218
{
210-
$u = AuthService::listUsers($startGroup);
211-
$users = array_merge($users, array_keys($u));
219+
$u = $this->listUsersIds($startGroup);
220+
$users = array_merge($users, $u);
212221
$g = AuthService::listChildrenGroups($startGroup);
213222
if (count($g)) {
214223
foreach ($g as $gName => $gLabel) {
@@ -505,9 +514,9 @@ public function handleTasks($action, $httpVars, $fileVars)
505514
public function fakeLongTask($action, $httpVars, $fileVars)
506515
{
507516
$minutes = (isSet($httpVars["time_length"])?intval($httpVars["time_length"]):2);
508-
$this->logDebug("Running Fake task on ".AuthService::getLoggedUser()->getId());
517+
$this->logInfo(__FUNCTION__, "Running Fake task on ".AuthService::getLoggedUser()->getId());
509518
print('STARTING FAKE TASK');
510-
sleep($minutes * 60);
519+
sleep($minutes * 30);
511520
print('ENDIND FAKE TASK');
512521
}
513522

0 commit comments

Comments
 (0)