/** * execute * * Main entry point, TaskManagerExecutor run this method * * @access public * @author bartek@wikia * @author eloy@wikia * * @param mixed $params default null: task params from wikia_tasks table * * @return boolean: status of operation, true = success, false = failure */ function execute($params = null) { global $wgWikiaLocalSettingsPath; $this->mTaskID = $params->task_id; $this->mParams = $params; $task_arguments = unserialize($params->task_arguments); $this->mSourceTaskId = $task_arguments["source-task-id"]; $this->mTargetWikiId = $task_arguments["target-wiki-id"]; #--- get data for previous task $oPreviousTask = BatchTask::newFromID($this->mSourceTaskId); if (is_null($oPreviousTask)) { $this->addLog("Previous task nr {$this->mSourceTaskId} doesn't exist in database"); return false; } $sWorkDir = $oPreviousTask->getTaskDirectory(); $this->addLog("Opennig {$sWorkDir} directory"); $i = 0; while (file_exists(sprintf("%s/%03d_dump.xml", $sWorkDir, $i))) { $phpFile = "php"; $importDumpFile = $GLOBALS["IP"] . "/maintenance/importDump.php"; $command = sprintf("SERVER_ID=%s %s %s --conf %s %s/%03d_dump.xml", $this->mTargetWikiId, $phpFile, $importDumpFile, $wgWikiaLocalSettingsPath, $sWorkDir, $i); $this->addLog("Running: {$command}"); $out = wfShellExec($command, $retval); $this->addLog($out); $i++; } if (empty($i)) { $this->addLog("Nothing was imported. There is no dump file to process"); } return true; }
/** * execute * * main entry point * * @author Inez Korczynski (inez@wikia.com) * @access publiic * * @param array $params: task params * * @return boolean: true if success, false otherwise */ function execute($params = null) { global $wgExternalSharedDB; $aArgs = unserialize($params->task_arguments); $this->mTaskID = $params->task_id; $this->mSourceTaskId = $aArgs["source-task-id"]; $dbr = wfGetDB(DB_MASTER, array(), $wgExternalSharedDB); $oRes = $dbr->select("wikia_tasks", "task_arguments", array("task_id" => $this->mSourceTaskId), __METHOD__); $oRow = $dbr->fetchObject($oRes); $aArgsSource = unserialize($oRow->task_arguments); $this->mSourceUrl = $aArgsSource["source-wiki-url"]; $oPreviousTask = BatchTask::newFromID($this->mSourceTaskId); $this->mPrevWorkDir = $oPreviousTask->getTaskDirectory(); $this->addLog("Opening previous task directory {$this->mWorkDir}"); $this->mWorkDir = $this->getTaskDirectory(); $this->mSourceWikiUrl = $this->mSourceUrl; if ($this->exportPageList()) { return true; } return false; }
/** * checkTTL * * check grace period time for task type i.e. how long task can live * if time to live is longer that TTL value finish it with ERROR status * * @access public * @author eloy@wikia-inc.com * * @param array $ids: identifiers of running tasks * * @return nothing */ public function checkTTL($ids) { if (is_array($ids)) { foreach ($ids as $taskid) { $oTask = BatchTask::newFromID($taskid); if ($oTask && !empty($oTask->getData()->task_started)) { $ttl = $oTask->getTTL(); $run = wfTimestamp(TS_UNIX, $oTask->getData()->task_started); $now = wfTimestamp(); if ($now - $run > $ttl) { #--- kill him! $oTask->addLog("TTL exceeded. Finished by task manager"); $oTask->closeTask(false); /** * alarm mail to ops */ $this->alarmMail($oTask); } else { wfDebugLog("taskmanager", sprintf("Task %d (%s) live %ds, need %ds to kill.", $oTask->getData()->task_id, $oTask->getData()->task_type, $now - $run, $ttl), true); } } else { wfDebugLog("taskmanager", "strange error happen, in running task starting time is empty", true); } } } }
/** * formatValue * * @param string $field field name * @param mixed $value value of field * * @return string HTML code for row */ function formatValue($field, $value) { global $wgRequest; switch ($field) { case "task_status": $taskId = $this->mCurrentRow->task_id; $name = BatchTask::getStatusName($value); $offset = $wgRequest->getVal("offset", 0); $return = sprintf("<a href=\"%s\">%s</a>", $this->mTitle->getLocalUrl("action=log&id={$taskId}&offset={$offset}"), $name); // also, stuff to make a link for restore task as per #2478 $taskType = $this->mCurrentRow->task_type; if (TASK_FINISHED_SUCCESS == $value && 'multidelete' == $taskType) { $return .= sprintf("<br /><a href=\"%s\">undo</a>", $this->mTitle->getLocalUrl("action=undo&id={$taskId}")); } return $return; break; case "task_actions": $iTaskID = $this->mCurrentRow->task_id; $iTaskStatus = $this->mCurrentRow->task_status; $sRetval = ""; global $wgUser; if (!$wgUser->isAllowed('taskmanager-action')) { return ""; } $offset = $wgRequest->getVal("offset", ""); if ($offset !== "") { $offset = "&offset={$offset}"; } switch ($iTaskStatus) { case TASK_WAITING: $sRetval .= sprintf("<a href=\"%s\">\n\t\t\t\t\t\t\t\t<img src=\"/skins/common/images/media-playback-start.png\" title=\"Start\" />\n\t\t\t\t\t\t\t</a>", $this->mTitle->getLocalUrl("action=start&id={$iTaskID}{$offset}")); break; case TASK_STARTED: $sRetval .= sprintf("<a href=\"%s\">\n\t\t\t\t\t\t\t<img src=\"/skins/common/images/media-playback-stop.png\" title=\"Stop\" />\n\t\t\t\t\t\t</a>", $this->mTitle->getLocalUrl("action=finish&id={$iTaskID}{$offset}")); break; case TASK_QUEUED: $sRetval .= sprintf("<a href=\"%s\">\n\t\t\t\t\t\t\t<img src=\"/skins/common/images/media-playback-pause.png\" title=\"Stop\" />\n\t\t\t\t\t\t</a>", $this->mTitle->getLocalUrl("action=stop&id={$iTaskID}{$offset}")); break; case TASK_FINISHED_SUCCESS: break; case TASK_FINISHED_ERROR: break; case TASK_FINISHED_UNDO: break; } $sRetval .= sprintf("<a href=\"%s\">\n\t\t\t\t\t\t<img src=\"/skins/common/images/process-stop.png\" title=\"Remove\" />\n\t\t\t\t\t</a>", $this->mTitle->getLocalUrl("action=remove&id={$iTaskID}{$offset}")); return $sRetval; break; case "task_added": case "task_started": case "task_finished": if (empty($value)) { return "<em>not yet</em>"; } else { return wfTimestamp(TS_EXIF, $value); } break; case "task_type": $Task = BatchTask::newFromID($this->mCurrentRow->task_id); if (is_null($Task)) { $description = Xml::element("span", null, "Unknown type"); } else { $description = "<span>" . $Task->getDescription() . "</span>"; } return $description; break; case "task_user_id": if ($value) { $oUser = User::newFromId($value); $label = sprintf("<a href=\"%s\">%s</a>", $oUser->getUserPage()->getLocalUrl(), $oUser->getName()); } else { $label = "<b>Anonymous</b>"; } return $label; break; default: return $value; } }
/** * getPreviousTaskDirectory * * get proper folder for previous task * * @author bartek@wikia * @author eloy@wikia * * @return mixed: path to directory or null if not defined */ public function getPreviousTaskDirectory() { $oPreviousTask = BatchTask::newFromID($this->mGrabberID); return $oPreviousTask->getTaskDirectory(); }