Subversion Repositories SE.SVN

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
35 7u83 1
 
2
import threading
3
import dbcontrol
4
import time
5
 
6
 
7
class Jobber(threading.Thread):
8
 
9
 
10
#	sql_nextjob = """SELECT * FROM %s 
11
#						WHERE sched<NOW() AND (NOT (sched IS NULL)) ORDER BY 
12
#						sched ASC LIMIT 1 FOR UPDATE """ % (self.db_table,)
13
 
14
 
15
	def get_selectjob_sql(self):
16
		return ""
17
 
18
	def get_markjob_sql(self,row):
19
		return ""
20
 
21
 
22
 
23
 
24
	def get_nextjob(self):
25
 
26
		db = self.db_pool.get_conn()
27
 
28
		try:
29
			cursor=db.cursor()
30
			while True:
31
				try:
32
					(sql,p) = self.get_selectjob_sql()
33
					cursor.execute(sql,p)
34
					break
35
				except Exception, e:
36
					if type(e) != dbcontrol.pgdb.OperationalError:
37
						raise e
38
					db.rollback()
39
					time.sleep(0.5)
40
 
41
 
42
 
43
			row = cursor.fetchone()
44
			if row != None:
45
				row =dbcontrol.row_to_dict(cursor,row)
46
				(sql,p) = self.get_markjob_sql(row)
47
#				sql = "UPDATE %s SET sched=NULL WHERE url=%s" % (self.db_table,"%s")
48
				cursor.execute(sql,p)
49
 
50
			db.commit()
51
			return row
52
 
53
		finally:
54
			cursor.close()
55
			self.db_pool.free_conn(db)
56
 
57
 
58
 
59
	def process_nextjob(self):
60
		return False
61
 
62
	def run(self):
63
		while True:
64
			rc = self.process_nextjob()
65
			if rc == False:
66
				time.sleep(1)
67
			else:	
68
				time.sleep(0.01)
69
 
70
			# return if the main thread has finished
71
			en = threading.enumerate()
72
			if not en[0].is_alive():
73
				return
74
 
75
 
76
 
77
 
78
 
79
 
80
		row = self.get_nextjob()
81