Megatest

Check-in [f03dbc0c69]
Login
Overview
Comment:Removed transaction from snag task - works much better but needs to be proven no collisions
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: f03dbc0c693b52a994fddd552f3250167e6b4712
User & Date: matt on 2011-10-24 23:14:55
Other Links: manifest | tags
Context
2011-10-25
20:12
Fixed command line -runall borked by the monitor stuff check-in: fa52f9444d user: mrwellan tags: trunk
2011-10-24
23:14
Removed transaction from snag task - works much better but needs to be proven no collisions check-in: f03dbc0c69 user: matt tags: trunk
13:36
Removed tasks_queue and monitor from patch-db check-in: 2a3d3d5d7a user: mrwellan tags: trunk
Changes

Modified dashboard-guimonitor.scm from [b2626c2ba5] to [2a8d79b5c8].

123
124
125
126
127
128
129
130











131
132
133
134
135
136
137
123
124
125
126
127
128
129

130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147







-
+
+
+
+
+
+
+
+
+
+
+







	 (topdialog  #f))
    (set! topdialog (iup:dialog 
		     #:close_cb (lambda (a)(exit))
		     #:title "Run Controls"
		     (iup:vbox
		      (iup:hbox keyentries othervars)
		      controls
		      (let ((tabtop (iup:tabs monitors actions)))
		      (let ((tabtop (iup:tabs 
				     monitors
				     (iup:vbox 
				       (let* ((tb (iup:textbox #:expand "HORIZONTAL"))
					      (bt (iup:button "Remove tasks by id"
							      #:action (lambda (obj)
									 (let ((val (iup:attribute tb "VALUE")))
									   (tasks:remove-queue-entries tdb val)))))
					      (lb (iup:label "(comma separated)")))
					 (iup:hbox bt tb lb))
				      actions))))
			(iup:attribute-set! tabtop "TABTITLE0" "Monitors")
			(iup:attribute-set! tabtop "TABTITLE1" "Actions")
			tabtop)
		      )))
		      ; (iup:frame
		      ;  #:title "Monitors"
		      ;  monitors)

Modified tasks.scm from [75fb629769] to [0c91ba49cf].

34
35
36
37
38
39
40

41
42
43
44
45
46
47
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48







+







                                action TEXT DEFAULT '',
                                owner TEXT,
                                state TEXT DEFAULT 'new',
                                target TEXT DEFAULT '',
                                name TEXT DEFAULT '',
                                test TEXT DEFAULT '',
                                item TEXT DEFAULT '',
                                keylock TEXT,
                                creation_time TIMESTAMP,
                                execution_time TIMESTAMP);")
	  (sqlite3:execute tdb "CREATE TABLE IF NOT EXISTS monitors (id INTEGER PRIMARY KEY,
                                pid INTEGER,
                                start_time TIMESTAMP,
                                last_update TIMESTAMP,
                                hostname TEXT,
111
112
113
114
115
116
117
118
119
120
121













122
123
124
125
126
127





128
129
130
131
132
133
134
135
136
137
138
139






140
141
142
143
144
145
146
112
113
114
115
116
117
118




119
120
121
122
123
124
125
126
127
128
129
130
131






132
133
134
135
136












137
138
139
140
141
142
143
144
145
146
147
148
149







-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+







	(testpatts (hash-table-ref/default var-params "testpatts" "%"))
	(itempatts (hash-table-ref/default var-params "itempatts" "%")))
    (tasks:add tdb action owner target runname testpatts itempatts)))

;; return one task from those who are 'new' OR 'waiting' AND more than 10sec old
;;
(define (tasks:snag-a-task tdb)
  (let ((res #f))
    (with-transaction 
     tdb
     (lambda ()
  (let ((res    #f)
	(keytxt (conc (current-process-id) "-" (get-host-name) "-" (car (user-information (current-user-id))))))

    ;; first randomly set a new to pid-hostname-hostname
    (sqlite3:execute
     tdb 
     "UPDATE tasks_queue SET keylock=? WHERE id IN
        (SELECT id FROM tasks_queue 
           WHERE state='new' OR 
                 (state='waiting' AND (strftime('%s','now')-execution_time) > 10) OR
                 state='reset'
           ORDER BY RANDOM() LIMIT 1);" keytxt)

       ;; execution time is updated with every snag, wait 10 secs before doing anything with the queue
       (sqlite3:for-each-row
	(lambda (id . rem)
	  (set! res (apply vector id rem)))
	tdb
	"SELECT id,action,owner,state,target,name,test,item,creation_time,execution_time
    (sqlite3:for-each-row
     (lambda (id . rem)
       (set! res (apply vector id rem)))
     tdb
     "SELECT id,action,owner,state,target,name,test,item,creation_time,execution_time FROM tasks_queue WHERE keylock=? ORDER BY execution_time ASC LIMIT 1;" keytxt)
           FROM tasks_queue
             WHERE 
                state='new' OR
                (state='waiting' AND (strftime('%s','now')-execution_time) > 10) OR
                state='reset'
             ORDER BY execution_time ASC LIMIT 1;")
       (if res ;; yep, have work to be done
	   (begin
	     (sqlite3:execute tdb "UPDATE tasks_queue SET state='inprogress',execution_time=strftime('%s','now') WHERE id=?;"
			      (tasks:task-get-id res))
	     res)
	   #f)))))
    (if res ;; yep, have work to be done
	(begin
	  (sqlite3:execute tdb "UPDATE tasks_queue SET state='inprogress',execution_time=strftime('%s','now') WHERE id=?;"
			   (tasks:task-get-id res))
	  res)
	#f)))

(define (tasks:reset-stuck-tasks tdb)
  (let ((res '()))
    (sqlite3:for-each-row
     (lambda (id delta)
       (set! res (cons id res)))
     tdb
161
162
163
164
165
166
167




168
169
170
171
172
173
174
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181







+
+
+
+







               FROM tasks_queue "
               ;; WHERE  
               ;;   state IN " statesstr " AND 
	       ;;   action IN " actionsstr 
	   " ORDER BY creation_time DESC;"))
    res))

;; remove tasks given by a string of numbers comma separated
(define (tasks:remove-queue-entries tdb task-ids)
  (sqlite3:execute tdb (conc "DELETE FROM tasks_queue WHERE id IN (" task-ids ");")))

;; 
(define (tasks:start-monitor db tdb)
  (if (> (tasks:get-num-alive-monitors tdb) 2) ;; have two running, no need for more
      (debug:print 1 "INFO: Not starting monitor, already have more than two running")
      (let* ((megatestdb     (conc *toppath* "/megatest.db"))
	     (monitordbf     (conc *toppath* "/monitor.db"))
	     (last-db-update 0)) ;; (file-modification-time megatestdb)))