70 $dbManager = $container->get(
'db.manager');
72 if (empty($userId) || empty($job_name) || empty($filename) ||
73 empty($UploadMode) || empty($folder_pk)) {
77 $row = $dbManager->getSingleRow(
"INSERT INTO upload 78 (upload_desc,upload_filename,user_fk,upload_mode,upload_origin,public_perm) VALUES ($1,$2,$3,$4,$5,$6) RETURNING upload_pk",
79 array($desc,$job_name,$userId,$UploadMode,$filename, $public_perm),__METHOD__.
'.insert.upload');
80 $uploadId = $row[
'upload_pk'];
82 $dbManager->getSingleRow(
"INSERT INTO foldercontents (parent_fk,foldercontents_mode,child_id) VALUES ($1,$2,$3)",
83 array($folder_pk,FolderDao::MODE_UPLOAD,$uploadId),
'insert.foldercontents');
88 if (empty($groupId)) {
89 $usersRow = $dbManager->getSingleRow(
'SELECT * FROM users WHERE user_pk=$1',
90 array($userId), __METHOD__.
'.select.user');
91 $groupId = $usersRow[
'group_fk'];
95 $dbManager->getSingleRow(
"INSERT INTO perm_upload (perm, upload_fk, group_fk) VALUES ($1,$2,$3)",
96 array($perm_admin, $uploadId, $groupId),
'insert.perm_upload');
113 function JobAddJob($userId, $groupId, $job_name, $upload_pk=0, $priority=0)
118 $dbManager = $container->get(
'db.manager');
120 $upload_pk_val = empty($upload_pk) ? null : $upload_pk;
122 $params = array($userId, $priority, $job_name, $upload_pk_val);
123 $stmtName = __METHOD__;
124 if (empty($groupId)) {
125 $stmtName .=
"noGrp";
126 $groupPkVal =
"(SELECT group_fk FROM users WHERE user_pk = $1)";
128 $params[] = $groupId;
129 $groupPkVal =
"$". count($params);
132 $row = $dbManager->getSingleRow(
134 (job_user_fk,job_group_fk,job_queued,job_priority,job_name,job_upload_fk) VALUES 135 ($1,$groupPkVal,now(),$2,$3,$4) RETURNING job_pk",
140 return intval($row[
'job_pk']);
159 function JobQueueAdd($job_pk, $jq_type, $jq_args, $jq_runonpfile, $Depends, $host = NULL, $jq_cmd_args=NULL)
162 $jq_args = pg_escape_string($jq_args);
163 $jq_cmd_args = pg_escape_string($jq_cmd_args);
166 if (is_array($Depends)) {
167 foreach ($Depends as $Dependency) {
168 if (empty($Dependency)) {
172 $sql =
"SELECT jq_pk FROM jobqueue WHERE jq_pk = '$Dependency'";
173 $result = pg_query($PG_CONN, $sql);
175 $MissingDep = (pg_num_rows($result) == 0);
176 pg_free_result($result);
185 $result = pg_query($PG_CONN, $sqlBegin);
187 pg_free_result($result);
190 $sql =
"INSERT INTO jobqueue ";
191 $sql.=
"(jq_job_fk,jq_type,jq_args,jq_runonpfile,jq_starttime,jq_endtime,jq_end_bits,jq_host,jq_cmd_args) VALUES ";
192 $sql.=
"('$job_pk','$jq_type','$jq_args',";
193 $sql .= (empty($jq_runonpfile)) ?
"NULL" :
"'$jq_runonpfile'";
194 $sql.=
",NULL,NULL,0,";
195 $sql .= $host ?
"'$host'," :
"NULL,";
196 $sql .= $jq_cmd_args ?
"'$jq_cmd_args')" :
"NULL)";
198 $result = pg_query($PG_CONN, $sql);
200 pg_free_result($result);
203 $jq_pk =
GetLastSeq(
"jobqueue_jq_pk_seq",
"jobqueue");
206 $result = pg_query($PG_CONN, $sql);
208 pg_free_result($result);
213 if (is_array($Depends)) {
214 foreach ($Depends as $Dependency) {
215 if (empty($Dependency)) {
218 $sql =
"INSERT INTO jobdepends (jdep_jq_fk,jdep_jq_depends_fk) VALUES ('$jq_pk','$Dependency')";
219 $result = pg_query($PG_CONN, $sql);
221 pg_free_result($result);
227 $result = pg_query($PG_CONN, $sql);
229 pg_free_result($result);
250 if (empty($status)) {
253 $sql =
"SELECT jq_pk FROM jobqueue WHERE jq_endtext like '%$status%' order by jq_pk;";
254 $result = pg_query($PG_CONN, $sql);
256 $job_array = pg_fetch_all_columns($result, 0);
257 pg_free_result($result);
276 $user_pk = Auth::getUserId();
277 $group_pk = Auth::getGroupId();
279 if (empty($upload_pk_list)) {
283 $agent_count = count($agent_list);
284 foreach (explode(
",", $upload_pk_list) as $upload_pk) {
285 if (empty($upload_pk)) {
290 $where =
"where upload_pk ='$upload_pk'";
292 if (empty($UploadRec)) {
293 echo
"ERROR: unknown upload_pk: $upload_pk\n";
297 $ShortName = $UploadRec[
'upload_filename'];
300 $job_pk = JobAddJob($user_pk, $group_pk, $ShortName, $upload_pk);
304 for ($ac = 0; $ac < $agent_count; $ac ++) {
305 $agentname = $agent_list[$ac]->URI;
306 if (! empty($agentname)) {
307 $Agent = & $Plugins[plugin_find_id($agentname)];
309 $ErrorMsg =
"already queued!";
310 $agent_jq_pk = $Agent->AgentAdd($job_pk, $upload_pk, $ErrorMsg,
312 if ($agent_jq_pk <= 0) {
313 echo
"WARNING: Scheduling failed for Agent $agentname, upload_pk is: $upload_pk, job_pk is:$job_pk\n";
314 echo
"WARNING message: $ErrorMsg\n";
315 }
else if ($Verbose) {
316 $SQL =
"SELECT upload_filename FROM upload where upload_pk = $upload_pk";
317 $result = pg_query($PG_CONN, $SQL);
319 $row = pg_fetch_assoc($result);
320 pg_free_result($result);
322 "$agentname is queued to run on $upload_pk:$row[upload_filename].\n";
338 $user_pk = Auth::getUserId();
339 $group_pk = Auth::getGroupId();
341 if (! empty($upload_pk_list)) {
342 foreach (explode(
",", $upload_pk_list) as $upload_pk) {
343 if (empty($upload_pk)) {
348 $jobpk = JobAddJob($user_pk, $group_pk,
"Delete", $upload_pk);
349 if (empty($jobpk) || ($jobpk < 0)) {
350 echo
"WARNING: Failed to schedule Delagent for Upload $upload_pk";
352 $jqargs =
"DELETE UPLOAD $upload_pk";
353 $jobqueuepk =
JobQueueAdd($jobpk,
"delagent", $jqargs, NULL, NULL);
354 if (empty($jobqueuepk)) {
355 echo
"WARNING: Failed to schedule Delagent for Upload $upload_pk";
357 print
"Delagent is queued to run on Upload: $upload_pk.\n";
363 echo $error_msg .
"\n" . $output;
393 if ($AgentName ==
"ununpack" || $AgentName ==
"adj2nest") {
394 $sql =
"SELECT jq_pk FROM jobqueue, job where job_pk=jq_job_fk " .
395 "AND jq_type='$AgentName' and job_upload_fk = $upload_pk";
398 $sql =
"SELECT jq_pk FROM jobqueue, job where job_pk=jq_job_fk AND jq_type='$AgentName' and job_pk=$job_pk";
400 $result = pg_query($PG_CONN, $sql);
402 if (pg_num_rows($result) > 0) {
403 $row = pg_fetch_assoc($result);
404 $jq_pk = $row[
"jq_pk"];
406 pg_free_result($result);
435 function CommonAgentAdd($plugin, $job_pk, $upload_pk, &$ErrorMsg, $Dependencies, $jqargs =
"", $jq_cmd_args = NULL)
439 $DependsEmpty = array();
442 if ($plugin->AgentHasResults($upload_pk) == 1) {
452 foreach ($Dependencies as $Dependency) {
453 if (is_array($Dependency)) {
454 $PluginName = $Dependency[
'name'];
455 $DepArgs = $Dependency[
'args'];
457 $PluginName = $Dependency;
461 if ($DepPlugin === null) {
462 $ErrorMsg =
"Invalid plugin name: $PluginName, (CommonAgentAdd())";
465 if (($Deps[] = $DepPlugin->AgentAdd($job_pk, $upload_pk, $ErrorMsg, $DependsEmpty, $DepArgs)) == - 1) {
470 if (empty($jqargs)) {
471 $jqargs = $upload_pk;
473 $jq_pk =
JobQueueAdd($job_pk, $plugin->AgentName, $jqargs,
"", $Deps, NULL,
477 "Failed to insert agent $plugin->AgentName into job queue. jqargs: $jqargs");
483 $ErrorMsg = $error_msg .
"\n" . $output;
506 $sql =
"SELECT jq_pk FROM jobqueue INNER JOIN job ON job_pk = jq_job_fk " 507 .
"WHERE jq_type='$agentName' AND job_upload_fk = $upload_pk " 508 .
"AND jq_end_bits = 0";
509 $result = pg_query($PG_CONN, $sql);
511 if (pg_num_rows($result) > 0) {
512 $row = pg_fetch_assoc($result);
513 $jq_pk = $row[
"jq_pk"];
515 pg_free_result($result);
516 return intval($jq_pk);
IsAlreadyScheduled($job_pk, $AgentName, $upload_pk)
Check if an agent is already scheduled in a job.
CommonAgentAdd($plugin, $job_pk, $upload_pk, &$ErrorMsg, $Dependencies, $jqargs="", $jq_cmd_args=NULL)
Queue an agent. This is a simple version of AgentAdd() that can be used by multiple plugins that only...
QueueUploadsOnAgents($upload_pk_list, $agent_list, $Verbose)
Schedule agent tasks on upload ids.
JobQueueAdd($job_pk, $jq_type, $jq_args, $jq_runonpfile, $Depends, $host=NULL, $jq_cmd_args=NULL)
Insert a jobqueue + jobdepends records.
#define PERM_NONE
User has no permission (not logged in)
GetLastSeq($seqname, $tablename)
Get last sequence number.
GetSingleRec($Table, $Where="")
Retrieve a single database record.
GetJobList($status)
Gets the list of jobqueue records with the requested $status.
isAlreadyRunning($agentName, $upload_pk)
Check if an agent is already running in a job.
plugin_find($pluginName)
Given the official name of a plugin, return the $Plugins object.
fo_communicate_with_scheduler($input, &$output, &$error_msg)
Communicate with scheduler, send commands to the scheduler, then get the output.
foreach($Options as $Option=> $OptVal) if(0==$reference_flag &&0==$nomos_flag) $PG_CONN
DBCheckResult($result, $sql, $filenm, $lineno)
Check the postgres result for unexpected errors. If found, treat them as fatal.
QueueUploadsOnDelagents($upload_pk_list)
Schedule delagent on upload ids.
JobAddUpload($userId, $groupId, $job_name, $filename, $desc, $UploadMode, $folder_pk, $public_perm=Auth::PERM_NONE)
Insert a new upload record, and update the foldercontents table.
#define PERM_ADMIN
Administrator.