37 require_once(dirname(dirname(__FILE__)).
"/common-cli.php");
43 define(
"ALARM_SECS", 30);
122 $this->agentVersion = $version;
124 $this->agentRev = $version.
".".$revision;
125 $this->agentArs = strtolower(
$agentName ) .
"_ars";
128 $GLOBALS[
'processed'] = 0;
129 $GLOBALS[
'alive'] =
false;
136 $this->
dbManager = $container->get(
'db.manager');
137 $this->agentDao = $container->get(
'dao.agent');
139 $this->agentId = $this->agentDao->getCurrentAgentId($this->agentName, $this->agentDesc, $this->agentRev);
152 $schedulerHandledOpts =
"c:";
153 $schedulerHandledLongOpts = array(
"userID:",
"groupID:",
"jobId:",
"scheduler_start",
'config:');
155 $longOpts = array_merge($schedulerHandledLongOpts, $this->agentSpecifLongOptions);
158 $args = getopt($shortOpts, $longOpts);
162 $this->userId =
$args[
'userID'];
163 $this->groupId =
$args[
'groupID'];
166 unset (
$args[
'jobId']);
167 unset (
$args[
'userID']);
168 unset (
$args[
'groupID']);
175 pcntl_signal(SIGALRM,
function($signo)
200 echo
"HEART: $processed ".($alive ?
'1' :
'0').
"\n";
220 $processed += $newProcessed;
223 pcntl_signal_dispatch();
234 debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
236 throw new \Exception(
'agent fail in '.__FILE__.
':'.__LINE__,$exitvalue);
251 echo
"BYE $exitvalue\n";
262 echo
"VERSION: ".$this->agentVersion.
"\n";
271 if (!$this->agentDao->arsTableExists($this->agentName)) {
272 $this->agentDao->createArsTable($this->agentName);
296 ($line = fgets(STDIN));
297 if (
"CLOSE\n" === $line) {
300 if (
"END\n" === $line) {
326 $uploadId = intval($line);
327 if ($uploadId <= 0) {
331 $arsId = $this->agentDao->writeArsRecord($this->agentName, $this->agentId, $uploadId);
333 print
"cannot insert ars record";
340 print
"Caught exception while processing uploadId=$uploadId: ".$e->getMessage();
341 print $e->getTraceAsString();
345 $this->agentDao->writeArsRecord($this->agentName, $this->agentId, $uploadId, $arsId, $success);
348 print
"agent failed on uploadId=$uploadId";
__construct($agentName, $version, $revision)
scheduler_disconnect($exitvalue)
Closes connection from scheduler.
heartbeat($newProcessed)
Send hear beat to the scheduler.
static heartbeat_handler($signo)
Function to handle hear beats from the agent and send them to the scheduler from STDOUT.
initArsTable()
Initialize ARS table.
Structure of an Agent with all required parameters.
bail($exitvalue)
Bail the agent, print the stack and disconnect from scheduler.
int jobId
The id of the job.
run_scheduler_event_loop()
Runs a loop to read commands from scheduler and process them.
cli_Init()
Initialize the fossology environment for CLI use. This routine loads the plugins so they can be use b...
scheduler_connect()
Connect with scheduler and initialize options.
scheduler_greet()
Greet the scheduler at the beginning of connection.
processUploadId($uploadId)
Given an upload ID, process the items in it.
fo_dbManager * dbManager
fo_dbManager object
scheduler_current()
Read the commands from scheduler.