*/
namespace Friendica\Core;
-use Friendica\App;
-use Friendica\Core\System;
+use Friendica\Core\Addon;
use Friendica\Core\Config;
-use Friendica\Core\Worker;
+use Friendica\Core\System;
use Friendica\Database\DBM;
+use Friendica\Model\Process;
+use Friendica\Util\DateTimeFormat;
use Friendica\Util\Lock;
-
+use Friendica\Util\Network;
use dba;
require_once 'include/dba.php';
}
// We now start the process. This is done after the load check since this could increase the load.
- $a->start_process();
+ self::startProcess();
// Kill stale processes every 5 minutes
$last_cleanup = Config::get('system', 'poller_last_cleaned', 0);
if ($age > 1) {
$stamp = (float)microtime(true);
- dba::update('workerqueue', ['executed' => datetime_convert()], ['pid' => $mypid, 'done' => false]);
+ dba::update('workerqueue', ['executed' => DateTimeFormat::utcNow()], ['pid' => $mypid, 'done' => false]);
self::$db_duration += (microtime(true) - $stamp);
}
$stamp = (float)microtime(true);
if (dba::update('workerqueue', ['done' => true], ['id' => $queue["id"]])) {
- Config::set('system', 'last_poller_execution', datetime_convert());
+ Config::set('system', 'last_poller_execution', DateTimeFormat::utcNow());
}
self::$db_duration = (microtime(true) - $stamp);
if ($age > 1) {
$stamp = (float)microtime(true);
- dba::update('workerqueue', ['executed' => datetime_convert()], ['pid' => $mypid, 'done' => false]);
+ dba::update('workerqueue', ['executed' => DateTimeFormat::utcNow()], ['pid' => $mypid, 'done' => false]);
self::$db_duration += (microtime(true) - $stamp);
}
$stamp = (float)microtime(true);
if (dba::update('workerqueue', ['done' => true], ['id' => $queue["id"]])) {
- Config::set('system', 'last_poller_execution', datetime_convert());
+ Config::set('system', 'last_poller_execution', DateTimeFormat::utcNow());
}
self::$db_duration = (microtime(true) - $stamp);
} else {
}
dba::update(
'workerqueue',
- ['executed' => NULL_DATE, 'created' => datetime_convert(), 'priority' => $new_priority, 'pid' => 0],
+ ['executed' => NULL_DATE, 'created' => DateTimeFormat::utcNow(), 'priority' => $new_priority, 'pid' => 0],
['id' => $entry["id"]]
);
} else {
if ($found) {
$condition = "`id` IN (".substr(str_repeat("?, ", count($ids)), 0, -2).") AND `pid` = 0 AND NOT `done`";
array_unshift($ids, $condition);
- dba::update('workerqueue', ['executed' => datetime_convert(), 'pid' => $mypid], $ids);
+ dba::update('workerqueue', ['executed' => DateTimeFormat::utcNow(), 'pid' => $mypid], $ids);
}
return $found;
}
$url = System::baseUrl()."/worker";
- fetch_url($url, false, $redirects, 1);
+ Network::fetchUrl($url, false, $redirects, 1);
}
/**
if (self::tooMuchWorkers()) {
// Cleaning dead processes
self::killStaleWorkers();
- get_app()->remove_inactive_processes();
+ Process::deleteInactive();
return;
}
/// @todo We should clean up the corresponding workerqueue entries as well
$condition = ["`created` < ? AND `command` = 'worker.php'",
- datetime_convert('UTC', 'UTC', "now - ".$timeout." minutes")];
+ DateTimeFormat::utc("now - ".$timeout." minutes")];
dba::delete('process', $condition);
}
$arr = ['args' => $args, 'run_cmd' => true];
- call_hooks("proc_run", $arr);
+ Addon::callHooks("proc_run", $arr);
if (!$arr['run_cmd'] || !count($args)) {
return true;
}
$priority = PRIORITY_MEDIUM;
$dont_fork = Config::get("system", "worker_dont_fork");
- $created = datetime_convert();
+ $created = DateTimeFormat::utcNow();
if (is_int($run_parameter)) {
$priority = $run_parameter;
return true;
}
+
+ /**
+ * Log active processes into the "process" table
+ *
+ * @brief Log active processes into the "process" table
+ */
+ public static function startProcess()
+ {
+ $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1);
+
+ $command = basename($trace[0]['file']);
+
+ Process::deleteInactive();
+
+ Process::insert($command);
+ }
+
+ /**
+ * Remove the active process from the "process" table
+ *
+ * @brief Remove the active process from the "process" table
+ * @return bool
+ */
+ public static function endProcess()
+ {
+ return Process::deleteByPid();
+ }
}