@@ -12,19 +12,19 @@ class ResWeb(pystache.View):
12
12
def __init__ (self , host ):
13
13
super (ResWeb , self ).__init__ ()
14
14
self .resq = host
15
-
15
+
16
16
def media_folder (self ):
17
17
return '/media/'
18
-
18
+
19
19
def close (self ):
20
20
self .resq .close ()
21
-
21
+
22
22
def address (self ):
23
23
return '%s:%s' % (self .resq .redis .host ,self .resq .redis .port )
24
-
24
+
25
25
def version (self ):
26
26
return str (__version__ )
27
-
27
+
28
28
def pages (self , start , size , link_function , width = 20 ):
29
29
pages = []
30
30
@@ -49,10 +49,10 @@ def __init__(self, host, queue=None, start=0):
49
49
self ._queue = queue
50
50
self ._start = start
51
51
super (Overview , self ).__init__ (host )
52
-
52
+
53
53
def queue (self ):
54
54
return self ._queue
55
-
55
+
56
56
def queues (self ):
57
57
queues = []
58
58
for q in self .resq .queues ():
@@ -61,16 +61,16 @@ def queues(self):
61
61
'size' : str (self .resq .size (q )),
62
62
})
63
63
return queues
64
-
64
+
65
65
def start (self ):
66
66
return str (self ._start )
67
-
67
+
68
68
def end (self ):
69
69
return str (self ._start + 20 )
70
-
70
+
71
71
def size (self ):
72
72
return str (self .resq .size (self ._queue ))
73
-
73
+
74
74
def jobs (self ):
75
75
jobs = []
76
76
for job in self .resq .peek (self ._queue , self ._start , self ._start + 20 ):
@@ -79,17 +79,17 @@ def jobs(self):
79
79
'args' :',' .join (job ['args' ])
80
80
})
81
81
return jobs
82
-
82
+
83
83
def empty_jobs (self ):
84
84
return len (self .jobs ()) == 0
85
-
85
+
86
86
def empty (self ):
87
87
return not self ._queue
88
-
88
+
89
89
def fail_count (self ):
90
90
#from pyres.failure import Failure
91
91
return str (failure .count (self .resq ))
92
-
92
+
93
93
def workers (self ):
94
94
workers = []
95
95
for w in self .resq .working ():
@@ -113,10 +113,10 @@ def workers(self):
113
113
return workers
114
114
def worker_size (self ):
115
115
return str (len (self .workers ()))
116
-
116
+
117
117
def total_workers (self ):
118
118
return str (len (Wrkr .all (self .resq )))
119
-
119
+
120
120
def empty_workers (self ):
121
121
if len (self .workers ()):
122
122
return False
@@ -127,14 +127,14 @@ class Queues(Overview):
127
127
128
128
class Working (Overview ):
129
129
template_name = 'working_full'
130
-
130
+
131
131
class Workers (ResWeb ):
132
132
def size (self ):
133
133
return str (len (self .all ()))
134
-
134
+
135
135
def all (self ):
136
136
return Wrkr .all (self .resq )
137
-
137
+
138
138
def workers (self ):
139
139
workers = []
140
140
for w in self .all ():
@@ -167,7 +167,7 @@ def __init__(self, host, key, start=0):
167
167
self .key = key
168
168
self ._start = start
169
169
super (Queue , self ).__init__ (host )
170
-
170
+
171
171
def start (self ):
172
172
return str (self ._start )
173
173
@@ -176,13 +176,13 @@ def end(self):
176
176
if end > int (self .size ()):
177
177
end = self .size ()
178
178
return str (end )
179
-
179
+
180
180
def queue (self ):
181
181
return self .key
182
-
182
+
183
183
def size (self ):
184
184
return str (self .resq .size (self .key ) or 0 )
185
-
185
+
186
186
def jobs (self ):
187
187
jobs = []
188
188
for job in self .resq .peek (self .key , self ._start , self ._start + 20 ):
@@ -191,29 +191,29 @@ def jobs(self):
191
191
'args' : str (job ['args' ])
192
192
})
193
193
return jobs
194
-
194
+
195
195
def pagination (self ):
196
196
return self .pages (self ._start , int (self .size ()), self .link_func )
197
-
197
+
198
198
def link_func (self , start ):
199
199
return '/queues/%s/?start=%s' % (self .key , start )
200
-
200
+
201
201
202
202
class Failed (ResWeb ):
203
203
def __init__ (self , host , start = 0 ):
204
204
self ._start = start
205
205
self .host = host
206
206
super (Failed , self ).__init__ (host )
207
-
207
+
208
208
def start (self ):
209
209
return str (self ._start )
210
-
210
+
211
211
def end (self ):
212
212
return str (self ._start + 20 )
213
-
213
+
214
214
def size (self ):
215
215
return str (failure .count (self .resq ) or 0 )
216
-
216
+
217
217
def failed_jobs (self ):
218
218
from base64 import b64encode
219
219
try :
@@ -230,18 +230,18 @@ def failed_jobs(self):
230
230
item ['traceback' ] = job ['backtrace' ]
231
231
jobs .append (item )
232
232
return jobs
233
-
233
+
234
234
def pagination (self ):
235
235
return self .pages (self ._start , int (self .size ()), self .link_func )
236
-
236
+
237
237
def link_func (self , start ):
238
238
return '/failed/?start=%s' % start
239
-
239
+
240
240
class Stats (ResWeb ):
241
241
def __init__ (self , host , key_id ):
242
242
self .key_id = key_id
243
243
super (Stats , self ).__init__ (host )
244
-
244
+
245
245
def sub_nav (self ):
246
246
sub_nav = []
247
247
sub_nav .append ({
@@ -257,7 +257,7 @@ def sub_nav(self):
257
257
'subtab' :'keys'
258
258
})
259
259
return sub_nav
260
-
260
+
261
261
def title (self ):
262
262
if self .key_id == 'resque' :
263
263
return 'Pyres'
@@ -267,7 +267,7 @@ def title(self):
267
267
return 'Keys owned by Pyres'
268
268
else :
269
269
return ''
270
-
270
+
271
271
def stats (self ):
272
272
if self .key_id == 'resque' :
273
273
return self .resque_info ()
@@ -277,7 +277,7 @@ def stats(self):
277
277
return self .key_info ()
278
278
else :
279
279
return []
280
-
280
+
281
281
def resque_info (self ):
282
282
stats = []
283
283
for key , value in self .resq .info ().items ():
@@ -286,7 +286,7 @@ def resque_info(self):
286
286
'value' : str (value )
287
287
})
288
288
return stats
289
-
289
+
290
290
def redis_info (self ):
291
291
stats = []
292
292
for key , value in self .resq .redis .info ().items ():
@@ -298,16 +298,16 @@ def redis_info(self):
298
298
def key_info (self ):
299
299
stats = []
300
300
for key in self .resq .keys ():
301
-
301
+
302
302
stats .append ({
303
303
'key' : str (key ),
304
304
'type' : str (self .resq .redis .type ('resque:' + key )),
305
- 'size' : str (redis_size (key , self .resq ))
305
+ 'size' : str (redis_size (key , self .resq ))
306
306
})
307
307
return stats
308
308
def standard (self ):
309
309
return not self .resque_keys ()
310
-
310
+
311
311
def resque_keys (self ):
312
312
if self .key_id == 'keys' :
313
313
return True
@@ -317,13 +317,13 @@ class Stat(ResWeb):
317
317
def __init__ (self , host , stat_id ):
318
318
self .stat_id = stat_id
319
319
super (Stat , self ).__init__ (host )
320
-
320
+
321
321
def key (self ):
322
322
return str (self .stat_id )
323
-
323
+
324
324
def key_type (self ):
325
325
return str (self .resq .redis .type ('resque:' + str (self .stat_id )))
326
-
326
+
327
327
def items (self ):
328
328
items = []
329
329
if self .key_type () == 'list' :
@@ -343,32 +343,32 @@ def items(self):
343
343
'row' :str (self .resq .redis .get ('resque:' + self .stat_id ))
344
344
})
345
345
return items
346
-
346
+
347
347
def size (self ):
348
348
return redis_size (self .stat_id ,self .resq )
349
-
349
+
350
350
class Worker (ResWeb ):
351
351
def __init__ (self , host , worker_id ):
352
352
self .worker_id = worker_id
353
353
super (Worker , self ).__init__ (host )
354
354
self ._worker = Wrkr .find (worker_id , self .resq )
355
-
355
+
356
356
def worker (self ):
357
357
return str (self .worker_id )
358
-
358
+
359
359
def host (self ):
360
360
host ,pid ,queues = str (self .worker_id ).split (':' )
361
361
return str (host )
362
362
def pid (self ):
363
363
host ,pid ,queues = str (self .worker_id ).split (':' )
364
364
return str (pid )
365
-
365
+
366
366
def state (self ):
367
367
return str (self ._worker .state ())
368
-
368
+
369
369
def started_at (self ):
370
370
return str (self ._worker .started )
371
-
371
+
372
372
def queues (self ):
373
373
host ,pid ,queues = str (self .worker_id ).split (':' )
374
374
qs = []
@@ -379,7 +379,7 @@ def queues(self):
379
379
return qs
380
380
def processed (self ):
381
381
return str (self ._worker .get_processed ())
382
-
382
+
383
383
def failed (self ):
384
384
return str (self ._worker .get_failed ())
385
385
def data (self ):
@@ -397,7 +397,7 @@ def runat(self):
397
397
if self .data ():
398
398
return str (datetime .datetime .fromtimestamp (float (data ['run_at' ])))
399
399
return ''
400
-
400
+
401
401
"""
402
402
item = {
403
403
'state':w.state(),
@@ -442,9 +442,9 @@ def jobs(self):
442
442
t = datetime .datetime .fromtimestamp (float (timestamp ))
443
443
item = dict (timestamp = str (timestamp ))
444
444
item ['size' ] = str (self .resq .delayed_timestamp_size (timestamp ))
445
-
445
+
446
446
item ['formated_time' ] = str (t )
447
-
447
+
448
448
jobs .append (item )
449
449
return jobs
450
450
@@ -459,10 +459,10 @@ def __init__(self, host, timestamp, start=0):
459
459
self ._start = start
460
460
self ._timestamp = timestamp
461
461
super (DelayedTimestamp , self ).__init__ (host )
462
-
462
+
463
463
def formated_timestamp (self ):
464
464
return str (datetime .datetime .fromtimestamp (float (self ._timestamp )))
465
-
465
+
466
466
def start (self ):
467
467
return str (self ._start )
468
468
@@ -482,12 +482,12 @@ def jobs(self):
482
482
}
483
483
jobs .append (item )
484
484
return jobs
485
-
485
+
486
486
def no_jobs (self ):
487
487
if int (self .size ()) > 0 :
488
488
return False
489
489
return True
490
-
490
+
491
491
def pagination (self ):
492
492
return self .pages (self ._start , int (self .size ()), self .link_func )
493
493
0 commit comments