mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-30 17:00:05 +00:00 
			
		
		
		
	Fix refresh at the start of a new UTC date
This commit is contained in:
		
							parent
							
								
									331fc84794
								
							
						
					
					
						commit
						92f2c76a70
					
				
					 1 changed files with 9 additions and 7 deletions
				
			
		|  | @ -50,6 +50,8 @@ public: | |||
|        objects_ {}, | ||||
|        objectsMutex_ {}, | ||||
|        objectDates_ {}, | ||||
|        refreshMutex_ {}, | ||||
|        refreshDate_ {}, | ||||
|        lastModified_ {}, | ||||
|        updatePeriod_ {} | ||||
|    { | ||||
|  | @ -78,6 +80,9 @@ public: | |||
|    std::shared_mutex                                             objectsMutex_; | ||||
|    std::list<std::chrono::system_clock::time_point>              objectDates_; | ||||
| 
 | ||||
|    std::mutex                            refreshMutex_; | ||||
|    std::chrono::system_clock::time_point refreshDate_; | ||||
| 
 | ||||
|    std::chrono::system_clock::time_point lastModified_; | ||||
|    std::chrono::seconds                  updatePeriod_; | ||||
| }; | ||||
|  | @ -252,27 +257,24 @@ std::pair<size_t, size_t> AwsNexradDataProvider::Refresh() | |||
| 
 | ||||
|    logger_->debug("Refresh()"); | ||||
| 
 | ||||
|    static std::mutex               refreshMutex; | ||||
|    static system_clock::time_point refreshDate {}; | ||||
| 
 | ||||
|    auto today     = floor<days>(system_clock::now()); | ||||
|    auto yesterday = today - days {1}; | ||||
| 
 | ||||
|    std::unique_lock lock(refreshMutex); | ||||
|    std::unique_lock lock(p->refreshMutex_); | ||||
| 
 | ||||
|    size_t allNewObjects   = 0; | ||||
|    size_t allTotalObjects = 0; | ||||
| 
 | ||||
|    // If we haven't gotten any objects from today, first list objects for
 | ||||
|    // yesterday, to ensure we haven't missed any objects near midnight
 | ||||
|    if (refreshDate < today) | ||||
|    if (p->refreshDate_ < today) | ||||
|    { | ||||
|       auto [newObjects, totalObjects] = ListObjects(yesterday); | ||||
|       allNewObjects                   = newObjects; | ||||
|       allTotalObjects                 = totalObjects; | ||||
|       if (totalObjects > 0) | ||||
|       { | ||||
|          refreshDate = yesterday; | ||||
|          p->refreshDate_ = yesterday; | ||||
|       } | ||||
|    } | ||||
| 
 | ||||
|  | @ -281,7 +283,7 @@ std::pair<size_t, size_t> AwsNexradDataProvider::Refresh() | |||
|    allTotalObjects += totalObjects; | ||||
|    if (totalObjects > 0) | ||||
|    { | ||||
|       refreshDate = today; | ||||
|       p->refreshDate_ = today; | ||||
|    } | ||||
| 
 | ||||
|    return std::make_pair(allNewObjects, allTotalObjects); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat