Esempio n. 1
0
def get_days_since_fail(repo=None):
    """
    Query Keen.io database and retrieve time since last failed buildjob.

    Parameters :
    - repo : repo name (fe. buildtimetrend/python-lib)
    """
    if repo is None or not is_readable():
        return -1

    try:
        failed_timestamp = keen.maximum(
            "build_jobs",
            target_property="job.finished_at.timestamp_seconds",
            filters=[
                get_repo_filter(repo),
                {
                    "operator": "ne",
                    "property_name": "job.result",
                    "property_value": "passed"
                }
            ]
        )
    except requests.ConnectionError:
        logger.error("Connection to Keen.io API failed")
        return -1
    except keen.exceptions.KeenApiError as msg:
        logger.error("Error in keenio.get_days_since_fail() : " + str(msg))
        return -1

    if isinstance(failed_timestamp, (int, float)) and failed_timestamp > 0:
        dt_failed = datetime.fromtimestamp(failed_timestamp)
        dt_now = datetime.now()
        return math.floor((dt_now - dt_failed).total_seconds() / (3600 * 24))

    return -1
 def test_maximum(self):
     resp = keen.maximum("query test", target_property="number", timeframe="today")
     self.assertEqual(type(resp), int)
 def test_maximum(self, get):
     get.return_value = self.INT_RESPONSE
     resp = keen.maximum("query test",
                         target_property="number",
                         timeframe="today")
     self.assertEqual(type(resp), int)
 def test_maximum(self):
     resp = keen.maximum("query test", target_property="number", timeframe="today")
     assert type(resp) is int
Esempio n. 5
0
 def test_maximum(self, get):
     get.return_value = self.INT_RESPONSE
     resp = keen.maximum("query test", target_property="number", timeframe="today")
     self.assertEqual(type(resp), int)
Esempio n. 6
0
 def test_maximum(self):
     resp = keen.maximum("query test",
                         target_property="number",
                         timeframe="today")
     assert type(resp) is int