Skip to content

Commit

Permalink
Updating status after starting/finishing downloads, done_at and
Browse files Browse the repository at this point in the history
started_at times.
  • Loading branch information
sddhrthrt committed Jul 6, 2012
1 parent bfc91b3 commit 81882b1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
Binary file modified data/archive.db
Binary file not shown.
2 changes: 1 addition & 1 deletion data/schema.sql
Expand Up @@ -20,7 +20,7 @@ create table requests (
script string not null,
description string,
queued_at datetime default current_timestamp,
started_at datetime,
started_at datetime,
done_at datetime,
frequency string,
status integer not null
Expand Down
19 changes: 15 additions & 4 deletions queue_manager.py
Expand Up @@ -133,6 +133,8 @@ def peek(self):
return None
def add_unfinished(self):
remaining=self.execute('select * from requests where status = ?', ('0',))
if not remaining:
return
existing = self.execute('select request_id from queue')
if existing:
existing = [r['request_id'] for r in existing]
Expand All @@ -141,9 +143,15 @@ def add_unfinished(self):
for request in remaining:
if request['request_id'] not in existing:
self.append(request['request_id'], request['frequency'], time.time(), request['status'])
q.execute('update requests set status = ? where request_id = ?', (1, request['request_id'],))
q.execute('update requests set started_at = ? where request_id=?', (time.time(), request['request_id']))
def service_queue(self):
q.add_unfinished()
req=self.popleft()[0]
req=self.popleft()
if(not req):
return
else:
req=req[0]
if(req['queued_at'] > time.time()):
self.append(req['request_id'], req['frequency'], req['queued_at'], req['status'])
return
Expand All @@ -157,13 +165,16 @@ def service_queue(self):
req['queued_at']=req['queued_at']+convertToSeconds(req['frequency'])
self.append(req['request_id'], req['frequency'], req['queued_at'], req['status'])
return
else:
q.execute('update requests set status = ? where request_id = ?', (2, req['request_id'],))
q.execute('update requests set done_at = ? where request_id = ?', (time.time(), req['request_id']) )


if __name__=='__main__':
q= RequestQueue('data/archive.db')
#q.append(2,'1d', int(time.time()), 0)
print q.execute('select * from queue', return_list = True)
while(q.execute('select count(*) from queue')[0]>0):
#while(q.execute('select count(*) from queue', return_list=True)[0][0]>0):
while(1):
q.service_queue()
print q.execute('select * from queue', return_list = True)
sleep(2)

0 comments on commit 81882b1

Please sign in to comment.