Leverage common "now" value when sending emails from server
i.e. don't generate new "now" when sending an email, just use the "now" we established when starting to check the readings
This commit is contained in:
		
							parent
							
								
									71db57b2e0
								
							
						
					
					
						commit
						3aa4185de9
					
				
					 1 changed files with 3 additions and 4 deletions
				
			
		|  | @ -183,13 +183,12 @@ class TempmonServerDaemon(Daemon): | ||||||
|             return False |             return False | ||||||
| 
 | 
 | ||||||
|     def update_status(self, probe, status, reading=None): |     def update_status(self, probe, status, reading=None): | ||||||
|         now = localtime(self.config) |  | ||||||
|         data = { |         data = { | ||||||
|             'probe': probe, |             'probe': probe, | ||||||
|             'status': self.enum.TEMPMON_PROBE_STATUS[status], |             'status': self.enum.TEMPMON_PROBE_STATUS[status], | ||||||
|             'reading': reading, |             'reading': reading, | ||||||
|             'taken': localtime(self.config, reading.taken, from_utc=True) if reading else None, |             'taken': localtime(self.config, reading.taken, from_utc=True) if reading else None, | ||||||
|             'now': now, |             'now': localtime(self.config, self.now, from_utc=True), | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         prev_status = probe.status |         prev_status = probe.status | ||||||
|  | @ -232,10 +231,10 @@ class TempmonServerDaemon(Daemon): | ||||||
|         # fetch last 90 minutes of readings |         # fetch last 90 minutes of readings | ||||||
|         session = orm.object_session(probe) |         session = orm.object_session(probe) | ||||||
|         recent_minutes = 90     # TODO: make configurable |         recent_minutes = 90     # TODO: make configurable | ||||||
|         cutoff = now - datetime.timedelta(seconds=(60 * recent_minutes)) |         cutoff = self.now - datetime.timedelta(seconds=(60 * recent_minutes)) | ||||||
|         readings = session.query(tempmon.Reading)\ |         readings = session.query(tempmon.Reading)\ | ||||||
|                           .filter(tempmon.Reading.probe == probe)\ |                           .filter(tempmon.Reading.probe == probe)\ | ||||||
|                           .filter(tempmon.Reading.taken >= make_utc(cutoff))\ |                           .filter(tempmon.Reading.taken >= cutoff)\ | ||||||
|                           .order_by(tempmon.Reading.taken.desc()) |                           .order_by(tempmon.Reading.taken.desc()) | ||||||
|         data['recent_minutes'] = recent_minutes |         data['recent_minutes'] = recent_minutes | ||||||
|         data['recent_readings'] = readings |         data['recent_readings'] = readings | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Lance Edgar
						Lance Edgar