mirror of
				https://github.com/lubuntu-team/metrics.git
				synced 2025-10-30 21:44:16 +00:00 
			
		
		
		
	Use requests_cache and add a time range function.
This commit is contained in:
		
							parent
							
								
									11a23f817f
								
							
						
					
					
						commit
						b8fbd5ef6c
					
				| @ -15,10 +15,15 @@ | ||||
| # You should have received a copy of the GNU General Public License | ||||
| # along with this program.  If not, see <https://www.gnu.org/licenses/>. | ||||
| 
 | ||||
| import datetime | ||||
| import requests_cache | ||||
| import time | ||||
| from jenkinsapi.custom_exceptions import NoBuildData | ||||
| from jenkinsapi.jenkins import Jenkins | ||||
| from os import getenv | ||||
| 
 | ||||
| requests_cache.install_cache("jenkins", backend="sqlite", expire_after=300) | ||||
| 
 | ||||
| 
 | ||||
| class JenkinsModule: | ||||
|     """Jenkins module for the Metrics program""" | ||||
| @ -109,3 +114,20 @@ class JenkinsModule: | ||||
|                 date, nonpassing, failing, total) | ||||
| 
 | ||||
|         return command | ||||
| 
 | ||||
|     def sqlite_time_range(self, days): | ||||
|         """Get the rows which have been inserted given days | ||||
| 
 | ||||
|         e.g. if days is 180, it gets all of the values which have been | ||||
|         inserted in the past 180 days. | ||||
| 
 | ||||
|         Note: this just returns the command to be ran, it doesn't actually run | ||||
|         """ | ||||
| 
 | ||||
|         now = datetime.datetime.now() | ||||
|         timedelta = datetime.timedelta(days=days) | ||||
|         unix_time = int(time.mktime((now - timedelta).timetuple())) | ||||
| 
 | ||||
|         command = "SELECT * FROM jenkins WHERE date > %s;" % unix_time | ||||
| 
 | ||||
|         return command | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user