diff --git a/modules/jenkins.py b/modules/jenkins.py index d97d0bf..494a601 100755 --- a/modules/jenkins.py +++ b/modules/jenkins.py @@ -15,10 +15,15 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +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