Skip to content

Commit

Permalink
Store elapsed time for the downloaded file
Browse files Browse the repository at this point in the history
  • Loading branch information
codex-corp committed Dec 19, 2017
1 parent 1208dc7 commit 32c5b11
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
7 changes: 7 additions & 0 deletions master.py
Expand Up @@ -59,17 +59,24 @@ def download_video(url, task_id):
name, ext = os.path.splitext(file_name)
file_name = task_id + ext
file_name = os.path.join(config.master_path, file_name)
download_time = 0

try:
with open(file_name, 'wb') as f:
c = pycurl.Curl()
c.setopt(c.URL, url)
c.setopt(c.WRITEDATA, f)
c.perform()
if c.getinfo(c.RESPONSE_CODE) is 200:
# Elapsed time for the transfer.
download_time = c.getinfo(c.TOTAL_TIME)
logger.info('Status: %f' % c.getinfo(c.TOTAL_TIME))

c.close()
except:
file_name = ''
finally:
db_update_download_time(task_id, download_time)
return file_name

'''
Expand Down
14 changes: 12 additions & 2 deletions sys_info.py
Expand Up @@ -82,15 +82,15 @@ def __exit__(self, type, value, traceback):

def init_db():
db.query("CREATE TABLE IF NOT EXISTS task_info(id VARCHAR(100), submit_time REAL, start_time REAL, \
finish_time REAL, service_type INTEGER, trans_time REAL, task_ongoing INTEGER)")
download_time REAL, finish_time REAL, service_type INTEGER, trans_time REAL, task_ongoing INTEGER)")

db.query("CREATE TABLE IF NOT EXISTS server_info(id VARCHAR(100) NOT NULL PRIMARY KEY, \
last_time REAL, state INTEGER)")


def db_insert_task_info(task_id, service_type):
cur_time = time.time()
return db.query('INSERT INTO task_info VALUES("{task_id}", {cur_time}, -1, -1, {service_type}, -1, 1)'.format(
return db.query('INSERT INTO task_info VALUES("{task_id}", {cur_time}, -1, -1, -1, {service_type}, -1, 1)'.format(
task_id=task_id, cur_time=cur_time, service_type=service_type))


Expand Down Expand Up @@ -146,3 +146,13 @@ def db_get_worker_state(host_name):
def db_update_last_access(host_name):
cur_time = time.time()
return db.query("update server_info set last_time = %f where id = '%s'" % (cur_time, host_name))


'''
update download time
'''


def db_update_download_time(task_id, download_time):
return db.query("UPDATE task_info SET download_time = %f WHERE id = '%s'" \
% (download_time, task_id))

0 comments on commit 32c5b11

Please sign in to comment.