global $queueHandler, $db; //SHUTDOWN $queueHandler->getRedisClient()->lrem(Constants_AnalysisRedisKeys::FAST_PID_LIST, 0, getmypid()); $queueHandler->getRedisClient()->disconnect(); $db->close(); $msg = str_pad(" FAST ANALYSIS " . getmypid() . " HALTED GRACEFULLY ", 50, "-", STR_PAD_BOTH); _TimeStampMsg($msg); } //START EVENTS do { /** * @var $ws Engines_MyMemory */ $ws = Engine::getInstance(1); _TimeStampMsg("Memory: " . memory_get_usage(true) / (1024 * 1024) . "MB"); $pid_list = getProjectForVolumeAnalysis('fast', 5); if (empty($pid_list)) { _TimeStampMsg("No projects: wait 3 seconds", false); sleep(3); continue; } _TimeStampMsg("Projects found: " . var_export($pid_list, true)); foreach ($pid_list as $pid_res) { $pid = $pid_res['id']; _TimeStampMsg("analyzing {$pid}, querying data..."); $segments = getSegmentsForFastVolumeAnalysys($pid); _TimeStampMsg("Memory: " . memory_get_usage(true) / (1024 * 1024) . "MB"); $num_segments = count($segments); $perform_Tms_Analysis = true; $status = Constants_ProjectStatus::STATUS_FAST_OK; if ($pid_res['id_tms'] == 0 && $pid_res['id_mt_engine'] == 0) {
/** * @param null $args */ public function main($args = null) { do { $projects_list = getProjectForVolumeAnalysis('fast', 5); if (empty($projects_list)) { self::_TimeStampMsg("No projects: wait 3 seconds."); sleep(3); continue; } self::_TimeStampMsg("Projects found: " . var_export($projects_list) . "."); foreach ($projects_list as $project_row) { $pid = $project_row['id']; self::_TimeStampMsg("Analyzing {$pid}, querying data..."); $perform_Tms_Analysis = true; $status = ProjectStatus::STATUS_FAST_OK; if ($project_row['id_tms'] == 0 && $project_row['id_mt_engine'] == 0) { /** * MyMemory disabled and MT Disabled Too * So don't perform TMS Analysis ( don't send segments in queue ), only fill segment_translation table */ $perform_Tms_Analysis = false; $status = ProjectStatus::STATUS_DONE; self::_TimeStampMsg('Perform Analysis ' . var_export($perform_Tms_Analysis, true)); } try { $fastReport = self::_fetchMyMemoryFast($pid); self::_TimeStampMsg("Fast {$pid} result: " . count($fastReport->responseData) . " segments."); } catch (Exception $e) { if ($e->getCode() == self::ERR_TOO_LARGE) { self::_updateProject($pid, ProjectStatus::STATUS_NOT_TO_ANALYZE); //next project continue; } else { $status = ProjectStatus::STATUS_DONE; } } self::_TimeStampMsg("Clean old memory cycle"); $this->segments = null; self::_TimeStampMsg("Done"); if ($fastReport->responseStatus == 200) { $fastResultData = $fastReport->responseData; } else { self::_TimeStampMsg("Pid {$pid} failed fast analysis."); $fastResultData = array(); } unset($fastReport); foreach ($fastResultData as $k => $v) { if (in_array($v['type'], array("50%-74%"))) { $fastResultData[$k]['type'] = "NO_MATCH"; } list($sid, ) = explode("-", $k); $fastResultData[$k]['id_segment'] = $sid; $fastResultData[$k]['segment_hash'] = $this->segment_hashes[$sid][0]; $fastResultData[$k]['segment'] = $this->segment_hashes[$sid][1]; $fastResultData[$k]['raw_word_count'] = $this->segment_hashes[$sid][2]; $fastResultData[$k]['source'] = $this->segment_hashes[$sid][3]; $fastResultData[$k]['target'] = $this->segment_hashes[$sid][4]; //now target holds more than one language ex: ( 80415:fr-FR,80416:it-IT ) $fastResultData[$k]['payable_rates'] = $this->segment_hashes[$sid][5]; $fastResultData[$k]['pretranslate_100'] = $project_row['pretranslate_100']; $fastResultData[$k]['tm_keys'] = $project_row['tm_keys']; $fastResultData[$k]['id_tms'] = $project_row['id_tms']; $fastResultData[$k]['id_mt_engine'] = $project_row['id_mt_engine']; $fastResultData[$k]['match_type'] = mb_strtoupper($fastResultData[$k]['type']); unset($fastResultData[$k]['type']); } unset($segment_hashes); // INSERT DATA self::_TimeStampMsg("Inserting segments..."); try { $insertReportRes = $this->_insertFastAnalysis($pid, $fastResultData, PayableRates::$DEFAULT_PAYABLE_RATES, $perform_Tms_Analysis); } catch (Exception $e) { //Logging done and email sent //set to error $insertReportRes = -1; } if ($insertReportRes < 0) { self::_TimeStampMsg("InsertFastAnalysis failed...."); self::_TimeStampMsg("Try next cycle...."); continue; } self::_TimeStampMsg("done"); // INSERT DATA unset($fastResultData); self::_updateProject($pid, $status); } } while ($this->RUNNING); self::cleanShutDown(); }