Add get_run_count DB API function
This commit adds a new DB API function get_run_count() which, like it's name implies, returns the number of runs in the DB. Change-Id: I31507f2e8ee8e3cc9b4587573f3b44b3f10dffee
This commit is contained in:
parent
c47cfaa6c7
commit
b0b5d2c517
@ -0,0 +1,4 @@
|
||||
---
|
||||
features:
|
||||
- Add a new DB API function get_runs_count() which returns the total number of
|
||||
runs in the DB
|
@ -1671,6 +1671,17 @@ def get_recent_failed_runs_by_run_metadata(key, value, num_runs=10,
|
||||
models.Run.run_at.desc()).limit(num_runs).all()
|
||||
|
||||
|
||||
def get_runs_count(session=None):
|
||||
"""Get the number of runs currently in the database
|
||||
|
||||
:return count: The number of runs in the DB
|
||||
:rtype: int
|
||||
"""
|
||||
session = session or get_session()
|
||||
query = db_utils.model_query(models.Run, session)
|
||||
return query.count()
|
||||
|
||||
|
||||
def get_runs_counts_by_run_metadata(key, value, start_date=None, session=None):
|
||||
"""Check runs for a given run metadata pair
|
||||
|
||||
|
@ -909,6 +909,15 @@ class TestDatabaseAPI(base.TestCase):
|
||||
self.assertEqual(1, len(results))
|
||||
self.assertEqual(run_c.id, results[0].id)
|
||||
|
||||
def test_get_runs_count(self):
|
||||
for i in range(0, 100):
|
||||
api.create_run()
|
||||
count = api.get_runs_count()
|
||||
self.assertEqual(100, count)
|
||||
|
||||
def test_get_runs_count_zero(self):
|
||||
self.assertEqual(0, api.get_runs_count())
|
||||
|
||||
def test_get_runs_counts_by_run_metadata_no_start_date(self):
|
||||
run_a = api.create_run(fails=1)
|
||||
api.create_run()
|
||||
|
Loading…
Reference in New Issue
Block a user