Skip to content

Commit 109e0ae

Browse files
author
Atte Keltanen
committed
make the polling interval of test runs customizable
1 parent 47c11fe commit 109e0ae

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

testdroid/__init__.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22

3-
import os, sys, requests, json, logging, time, base64
3+
import os, sys, requests, json, logging, time, base64
44

55
if sys.version_info[0] > 2:
66
import http.client
@@ -130,6 +130,9 @@ def set_url(self, url):
130130
def set_download_buffer_size(self, download_buffer_size):
131131
self.download_buffer_size = download_buffer_size
132132

133+
def set_polling_interval_mins(self, polling_interval_mins):
134+
self.polling_interval_mins = polling_interval_mins
135+
133136
""" Get Oauth2 token
134137
"""
135138
def get_token(self):
@@ -526,9 +529,12 @@ def start_wait_download_test_run(self, project_id, device_group_id=None, device_
526529
"""
527530
def wait_test_run(self, project_id, test_run_id):
528531
if test_run_id:
529-
print("Awaiting completion of test run with id %s. Will wait forever polling every %smins." % (test_run_id, Testdroid.polling_interval_mins))
532+
print("Awaiting completion of test run with id {}. Will wait forever polling every {}.".format(
533+
test_run_id,
534+
'{} minutes'.format(self.polling_interval_mins) if self.polling_interval_mins != 1 else 'minute'))
535+
530536
while True:
531-
time.sleep(Testdroid.polling_interval_mins*60)
537+
time.sleep(self.polling_interval_mins * 60)
532538
if not self.api_key:
533539
self.access_token = None #WORKAROUND: access token thinks it's still valid,
534540
# > token valid for another 633.357925177
@@ -756,6 +762,8 @@ def format_epilog(self, formatter):
756762
help="Password. Required if username is used. You can use environment variable TESTDROID_PASSWORD as well.")
757763
parser.add_option("-c", "--url", dest="url", default="https://cloud.bitbar.com",
758764
help="Cloud endpoint. Default is https://cloud.bitbar.com. You can use environment variable TESTDROID_URL as well.")
765+
parser.add_option("-i", "--interval", dest="interval",
766+
help="How frequently the status of a test run should be checked (in minutes). Can be used with the command wait-test-run.")
759767
parser.add_option("-q", "--quiet", action="store_true", dest="quiet",
760768
help="Quiet mode")
761769
parser.add_option("-d", "--debug", action="store_true", dest="debug",
@@ -811,11 +819,18 @@ def cli(self, parser, commands):
811819
password = options.password or os.environ.get('TESTDROID_PASSWORD')
812820
apikey = options.apikey or os.environ.get('TESTDROID_APIKEY')
813821
url = os.environ.get('TESTDROID_URL') or options.url
822+
polling_interval_mins = 10
823+
824+
try:
825+
polling_interval_mins = max(int(options.interval), 1)
826+
except:
827+
polling_interval_mins = 10
814828

815829
self.set_username(username)
816830
self.set_password(password)
817831
self.set_apikey(apikey)
818832
self.set_url(url)
833+
self.set_polling_interval_mins(polling_interval_mins)
819834

820835
command = commands[args[0]]
821836
if not command:

0 commit comments

Comments
 (0)