void Scheduler::DoWork() { SetIsStarted(); while (true) { // Check if there are any tasks to run. RunTasks_(); // Wait one minute. try { boost::this_thread::sleep_for(boost::chrono::minutes(1)); } catch (const boost::thread_interrupted&) { boost::this_thread::disable_interruption disabled; boost::lock_guard<boost::recursive_mutex> guard(mutex_); scheduled_tasks_.clear(); return; } } }
void ExternalFetchManager::DoWork() //---------------------------------------------------------------------------() // DESCRIPTION: // Responsible for creating threads that downloads messages from external // servers. //---------------------------------------------------------------------------() { SetIsStarted(); Logger::Instance()->LogDebug("ExternalFetchManager::Start()"); PersistentFetchAccount::UnlockAll(); fetch_accounts_ = std::shared_ptr<FetchAccounts> (new FetchAccounts(0)); while (1) { fetch_accounts_->RefreshPendingList(); std::vector<std::shared_ptr<FetchAccount> > &vecAccounts = fetch_accounts_->GetVector(); auto iterFA = vecAccounts.begin(); while (iterFA != vecAccounts.end()) { // Create a fetch task that will do the actual work, and // add this task to the queue. std::shared_ptr<FetchAccount> pFA = (*iterFA); if (FetchIsAllowed_(pFA)) { // We're allowed to fetch. Lock fetchaccount and start the fetcher. PersistentFetchAccount::Lock(pFA->GetID()); std::shared_ptr<ExternalFetchTask> pTask = std::shared_ptr<ExternalFetchTask>(new ExternalFetchTask(pFA)); WorkQueueManager::Instance()->AddTask(queue_id_, pTask); } else { // We should not fetch for this account now. Update // fetch account. PersistentFetchAccount::SetNextTryTime(pFA); } iterFA++; } // We are currently not fetching anything // Sit here and wait a minute check_now_.WaitFor(boost::chrono::minutes(1)); } }