根据给定起止时间,完成下载任务(大概类似于日历日程这种)

来源:互联网 发布:北京海量数据离职 编辑:程序博客网 时间:2024/06/06 08:40
//指定下载 for emergency, like power off//TODO: file nam e need  to bue modifyvoid GridImgDownloadMgr::DesignateDownLoad( UtilsSystem::PosixTime beginTime , UtilsSystem::PosixTime endTime ){// Assign begin time and end time for missing image.if (beginTime >= endTime){return;}// Correct BETime according timezone.UtilsSystem::TimeDuration backSpan(TIME_DIFFERENCE, 0, 0);beginTime -= backSpan;endTime -= backSpan;// Independent from GridImg Appliation.Need read config.if (!m_bStart){m_pAccount = m_pConfig->Read("DownLoad", "user");m_pPassword = m_pConfig->Read("DownLoad", "passwd");m_pThreadPool = UtilsSystem::ThreadpoolPtr(new UtilsSystem::Threadpool(24));m_pThread = boost::make_shared<UtilsSystem::Thread>(boost::bind(&boost::asio::io_service::run, m_pIOService));if ( !m_httpClient.Initialize()){LOG4CXX_ERROR(m_pLogger, "HTTP client initial fail.");}GridImgActorMangerSingleton::GetMutableInstance()->SetLogger(m_pLogger);GridImgActorMangerSingleton::GetMutableInstance()->SetConfiguration(m_pConfig);GridImgActorMangerSingleton::GetMutableInstance()->Initialize();LOG4CXX_INFO(m_pLogger, "Grib image download manager start wihtout app.");}int bHour = UtilsSystem::DateTimeUtils::GetDateTimeUnit(beginTime, HOUR);int bDay = UtilsSystem::DateTimeUtils::GetDateTimeUnit(beginTime, DAY);int bMonth = UtilsSystem::DateTimeUtils::GetDateTimeUnit(beginTime, MONTH);int bYear = UtilsSystem::DateTimeUtils::GetDateTimeUnit(beginTime, YEAR);int eHour = UtilsSystem::DateTimeUtils::GetDateTimeUnit(endTime, HOUR);int eDay = UtilsSystem::DateTimeUtils::GetDateTimeUnit(endTime, DAY);int eMonth = UtilsSystem::DateTimeUtils::GetDateTimeUnit(endTime, MONTH);int eYear = UtilsSystem::DateTimeUtils::GetDateTimeUnit(endTime, YEAR);int dayList[13] = {0,31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};int y = bYear;int m = bMonth;int d = bDay;int h = bHour;bool flagY = true;bool flagM = true;bool flagD = true;bool flagH = true;//-- logicdo{flagM = true;if (y%4 == 0){dayList[2] = 29;}else{dayList[2] = 28;}do{flagD = true;do{flagH = true;do{std::string urlFrmtStr = m_pConfig->Read("Download", "download_url");boost::format frmt(urlFrmtStr);frmt %y %m %d %(h*100) %y %m %d %(h*100);std::string urlStr = str(frmt);// Save path string.std::string filePathStr = m_pConfig->Read("SaveDir","orig_dir");boost::filesystem::path filePath(filePathStr);boost::format fileFrmt(PIC_NAME_FORMAT);fileFrmt %y %m %d %(h*100);std::string fileStr;fileStr = str(fileFrmt);filePath.append(fileStr + PIC_SUFFIX);m_pThreadPool->schedule(boost::bind(&GridImgDownloadMgr::DownloadGribImg, this, urlStr, filePath.string()));if ( y==eYear&m==eMonth&d==eDay&&h>=eHour || h++>=23){flagH = false;}}while (flagH);h = 0;if ( y==eYear&m==eMonth&d==eDay || d++>=dayList[m] ){flagD = false;}}while(flagD);d = 1;if ( y==eYear&m==eMonth || m++>=12){flagM = false;}}while(flagM);m = 1;if ( y++ >= eYear ){flagY = false;}}while (flagY);//--logicreturn;}
忽略了2000,2400这种不是闰年的情况,因为根本用不上。
原创粉丝点击