public function AgentAdd($jobId, $uploadId, &$errorMsg, $dependencies = array(), $arguments = null) { $jobQueueId = \IsAlreadyScheduled($jobId, $this->AgentName, $uploadId); if ($jobQueueId != 0) { return $jobQueueId; } return $this->doAgentAdd($jobId, $uploadId, $errorMsg, $dependencies, $uploadId, ''); }
/** * @overwrite * @param int $jobId * @param int $uploadId * @param string $errorMsg * @param array $dependencies * @param type $conflictStrategyId */ public function AgentAdd($jobId, $uploadId, &$errorMsg, $dependencies = array(), $conflictStrategyId = null) { $dependencies[] = "agent_adj2nest"; $jobQueueId = \IsAlreadyScheduled($jobId, $this->AgentName, $uploadId); if ($jobQueueId != 0) { return $jobQueueId; } $args = $conflictStrategyId !== null ? $this::CONFLICT_STRATEGY_FLAG . $conflictStrategyId : ''; return $this->doAgentAdd($jobId, $uploadId, $errorMsg, $dependencies, $uploadId, $args); }
/** * @param int $jobId * @param int $uploadId * @param &string $errorMsg - error message on failure * @param array $dependencies - array of plugin names representing dependencies. * @param mixed $arguments (ignored if not a string) * @returns int * * jqId Successfully queued * * 0 Not queued, latest version of agent has previously run successfully * * -1 Not queued, error, error string in $ErrorMsg **/ public function AgentAdd($jobId, $uploadId, &$errorMsg, $dependencies = array(), $arguments = null) { $dependencies[] = "agent_adj2nest"; if ($this->AgentHasResults($uploadId) == 1) { return 0; } $jobQueueId = \IsAlreadyScheduled($jobId, $this->AgentName, $uploadId); if ($jobQueueId != 0) { return $jobQueueId; } $args = is_array($arguments) ? '' : $arguments; return $this->doAgentAdd($jobId, $uploadId, $errorMsg, $dependencies, $uploadId, $args); }
/** * \brief Queue an agent. This is a simple version of AgentAdd() that can be * used by multiple plugins that only use upload_pk as jqargs. * Before queuing, check if agent needs to be queued. It doesn't need to be queued if: * - It is already queued * - It has already been run by the latest agent version * * \param $plugin caller plugin object * \param $job_pk * \param $upload_pk * \param $ErrorMsg - error message on failure * \param $Dependencies - array of named dependencies. Each array element is the plugin name. * For example, array(agent_adj2nest, agent_pkgagent). * Typically, this will just be array(agent_adj2nest). * \param $jqargs (optional) jobqueue.jq_args * * \returns * - jq_pk Successfully queued * - 0 Not queued, latest version of agent has previously run successfully * - -1 Not queued, error, error string in $ErrorMsg **/ function CommonAgentAdd($plugin, $job_pk, $upload_pk, &$ErrorMsg, $Dependencies, $jqargs = "", $jq_cmd_args = NULL) { global $Plugins; $Deps = array(); $DependsEmpty = array(); /* check if the latest agent has already been run */ if ($plugin->AgentHasResults($upload_pk) == 1) { return 0; } /* if it is already scheduled, then return success */ if (($jq_pk = IsAlreadyScheduled($job_pk, $plugin->AgentName, $upload_pk)) != 0) { return $jq_pk; } /* queue up dependencies */ foreach ($Dependencies as $Dependency) { if (is_array($Dependency)) { $PluginName = $Dependency['name']; $DepArgs = $Dependency['args']; } else { $PluginName = $Dependency; $DepArgs = null; } $DepPlugin = plugin_find($PluginName); if ($DepPlugin === null) { $ErrorMsg = "Invalid plugin name: {$PluginName}, (CommonAgentAdd())"; return -1; } if (($Deps[] = $DepPlugin->AgentAdd($job_pk, $upload_pk, $ErrorMsg, $DependsEmpty, $DepArgs)) == -1) { return -1; } } /* schedule AgentName */ if (empty($jqargs)) { $jqargs = $upload_pk; } $jq_pk = JobQueueAdd($job_pk, $plugin->AgentName, $jqargs, "", $Deps, NULL, $jq_cmd_args); if (empty($jq_pk)) { $ErrorMsg = _("Failed to insert agent {$plugin->AgentName} into job queue. jqargs: {$jqargs}"); return -1; } /* Tell the scheduler to check the queue. */ $success = fo_communicate_with_scheduler("database", $output, $error_msg); if (!$success) { $ErrorMsg = $error_msg . "\n" . $output; } return $jq_pk; }