Skip to content

Commit 8750f3e

Browse files
committed
2.0.1 release
1 parent 8b3457d commit 8750f3e

File tree

15 files changed

+1052
-64
lines changed

15 files changed

+1052
-64
lines changed

controllers/plugin_cs_monitor.py

+85-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# coding: utf8
22
from datetime import timedelta as timed
33
import datetime
4+
import time
45
from gluon.storage import Storage
56
from gluon import current
67
from gluon.serializers import json as dumps
@@ -9,6 +10,7 @@
910
from plugin_cs_monitor.html_helpers import nice_worker_stats, nice_task_status, mybootstrap
1011
from plugin_cs_monitor.html_helpers import fixup_bs3_widgets
1112
from plugin_cs_monitor.scheduler_helpers import requeue_task
13+
from gluon.scheduler import JobGraph
1214
from collections import defaultdict
1315

1416
response.files.append(URL('static', 'plugin_cs_monitor/js/stupidtable/stupidtable.min.js'))
@@ -25,6 +27,9 @@
2527

2628
response.files.append(URL('static', 'plugin_cs_monitor/js/dagre/dagre-d3.min.js'))
2729

30+
response.files.append(URL('static', 'plugin_cs_monitor/js/select2/select2.min.js'))
31+
response.files.append(URL('static', 'plugin_cs_monitor/js/select2/select2-bootstrap.css'))
32+
2833
response.files.append(URL('static', 'plugin_cs_monitor/js/app.js'))
2934

3035
##Configure start
@@ -48,7 +53,7 @@
4853
'cacheable': True}
4954

5055
TASKS_SUMMARY_KWARGS = {
51-
'cache': (cache.with_prefix(sc_cache, "plugin_cs_monitor"),TASKS_SUMMARY_CACHE_TIME),
56+
'cache': (cache.with_prefix(sc_cache, "plugin_cs_monitor"), TASKS_SUMMARY_CACHE_TIME),
5257
'cacheable' : True}
5358

5459
response.meta.author = 'Niphlod <[email protected]>'
@@ -100,12 +105,12 @@ def wactions():
100105
r = [request.vars.w_records]
101106
else:
102107
r = request.vars.w_records
108+
for w in r:
109+
s.set_worker_status(action=request.vars.action, worker_name=w)
103110
rtn = dbs(sw.worker_name.belongs(r)).validate_and_update(status=request.vars.action)
104-
if rtn.errors:
105-
session.flash = "Not a valid action"
106-
elif rtn.updated:
107-
session.flash = "%s workers updated correctly" % rtn.updated
108-
redirect(default)
111+
session.flash = "%s workers updated correctly" % len(r)
112+
redirect(default)
113+
109114

110115
@auth.requires_signature()
111116
def tactions():
@@ -168,13 +173,15 @@ def tactions():
168173

169174
redirect(default)
170175

176+
171177
@auth.requires_signature()
172178
def tasks():
173179
session.forget(response)
174180
c = cache_tasks_counts(st)
175181

176182
return dict(c=c)
177183

184+
178185
def cache_tasks_counts(t):
179186

180187
if GROUPING_MODE == 'python':
@@ -202,6 +209,7 @@ def cache_tasks_counts(t):
202209

203210
return rtn
204211

212+
205213
@auth.requires_signature()
206214
def task_group():
207215
session.forget(response)
@@ -243,6 +251,7 @@ def task_group():
243251
BASEURL = URL("plugin_cs_monitor", "tactions", user_signature=True)
244252
return dict(tasks=tasks, paginate=paginate, total=total, page=page, BASEURL=BASEURL)
245253

254+
246255
@auth.requires_signature()
247256
def task_details():
248257
session.forget(response)
@@ -255,6 +264,7 @@ def task_details():
255264
deps = [row.job_name for row in deps]
256265
return dict(task=task, st=st, deps=deps)
257266

267+
258268
@auth.requires_signature()
259269
def run_details():
260270
session.forget(response)
@@ -288,6 +298,7 @@ def run_details():
288298
row.elapsed_seconds_ = td
289299
return dict(runs=runs, paginate=paginate, total=total, page=page)
290300

301+
291302
@auth.requires_signature()
292303
def run_traceback():
293304
session.forget(response)
@@ -299,6 +310,7 @@ def run_traceback():
299310
return ''
300311
return dict(traceback=rtn.traceback)
301312

313+
302314
@auth.requires_signature()
303315
def edit_task():
304316
task_id = request.args(0)
@@ -359,6 +371,7 @@ def edit_task():
359371
response.flash = 'Errors detected'
360372
return dict(form=form, task=task)
361373

374+
362375
def gb_duration(q):
363376
#byduration
364377
count_ = sr.id.count()
@@ -398,6 +411,7 @@ def gb_duration(q):
398411

399412
return gb_duration_rows, jgb_duration_series
400413

414+
401415
def gb_status(q, mode='runs'):
402416
#bystatus
403417
if GROUPING_MODE == 'python':
@@ -441,6 +455,7 @@ def gb_status(q, mode='runs'):
441455

442456
return gb_status_rows, jgb_status_series
443457

458+
444459
def bydate(q, mode):
445460
#by period
446461

@@ -503,6 +518,7 @@ def bydate(q, mode):
503518

504519
return gb_when_rows, jgb_when_series
505520

521+
506522
def byday(q, day, mode):
507523
#by period
508524
if GROUPING_MODE == 'python':
@@ -648,6 +664,7 @@ def clear_cache():
648664
session.flash = 'Cache Cleared'
649665
redirect(URL("index"), client_side=True)
650666

667+
651668
@auth.requires_signature()
652669
def delete_tasks():
653670
session.forget(response)
@@ -677,16 +694,26 @@ def delete_tasks():
677694
limit = limit.strftime('%Y-%m-%d %H:%M:%S')
678695
return dict(limit=limit)
679696

680-
@auth.requires_signature()
697+
698+
@auth.requires_signature(hash_vars=False)
681699
def jobs():
700+
return dict()
701+
702+
703+
@auth.requires_signature(hash_vars=False)
704+
def jobs_render():
682705
session.forget(response)
683-
q = sd.id > 0
684706
if request.vars.job_name:
685707
q = sd.job_name == request.vars.job_name
686-
all_jobs = dbs(q).select(sd.job_name, groupby=sd.job_name)
687-
all_jobs = dict([(row.job_name, "a_%s" % k) for k, row in enumerate(all_jobs)])
688-
all_deps = dbs(q).select()
708+
all_jobs = {request.vars.job_name : 'a_0'}
709+
newjob = None
710+
else:
711+
q = sd.id > 0
712+
all_jobs = dbs(q).select(sd.job_name, groupby=sd.job_name)
713+
all_jobs = dict([(row.job_name, "a_%s" % k) for k, row in enumerate(all_jobs)])
714+
newjob = str(int(time.mktime(datetime.datetime.utcnow().timetuple())))
689715

716+
all_deps = dbs(q).select()
690717
all_nodes = {}
691718
all_edges = {}
692719
for row in all_deps:
@@ -705,7 +732,9 @@ def jobs():
705732
for id in v.keys():
706733
all_tasks_ids[id] = None
707734

708-
all_tasks_labels = dbs(st.id.belongs(all_tasks_ids.keys())).select().as_dict()
735+
all_tasks_labels = dbs(st.id.belongs(all_tasks_ids.keys())).select(
736+
st.id, st.function_name, st.task_name, st.status
737+
).as_dict()
709738

710739
for k, v in all_nodes.iteritems():
711740
for id in v.keys():
@@ -714,5 +743,48 @@ def jobs():
714743
title="%(id)s (%(function_name)s): %(status)s" % all_tasks_labels[id],
715744
linkto=URL('task_details', args=id, user_signature=True))
716745

717-
return dict(all_jobs=all_jobs, all_edges=dumps(all_edges), all_nodes=dumps(all_nodes))
746+
return dict(all_jobs=all_jobs, all_edges=dumps(all_edges), all_nodes=dumps(all_nodes), newjob=newjob)
747+
748+
@auth.requires_signature(hash_vars=False)
749+
def edit_job():
750+
posted = request.post_vars
751+
if posted:
752+
if ',' in posted.task_child and ',' in posted.task_parent:
753+
session.flash = 'Only one multiple value allowed'
754+
return dict()
755+
if ',' in posted.task_child:
756+
posted.task_child = posted.task_child.split(',')
757+
else:
758+
posted.task_child = [posted.task_child]
759+
if ',' in posted.task_parent:
760+
posted.task_parent = posted.task_parent.split(',')
761+
else:
762+
posted.task_parent = [posted.task_parent]
763+
myjob = JobGraph(dbs, posted.job_name)
764+
for child in posted.task_child:
765+
for parent in posted.task_parent:
766+
myjob.add_deps(parent, child)
767+
rtn = myjob.validate(posted.job_name)
768+
if rtn is None:
769+
session.flash = "No task added, validation failed"
770+
else:
771+
session.flash = "Dependency correctly added"
772+
return dict()
773+
774+
@auth.requires_signature(hash_vars=False)
775+
def tasks_dropdown_helper():
776+
session.forget(response)
777+
if not request.get_vars.q:
778+
raise HTTP(404)
779+
q = request.get_vars.q
780+
all_tasks = dbs(
781+
(st.task_name.ilike('%' + q + '%')) |
782+
(st.id.ilike('%' + q + '%'))
783+
).select(
784+
st.id, st.task_name
785+
)
786+
rtn = []
787+
for row in all_tasks:
788+
rtn.append(dict(id=row.id, text='%(id)s - %(task_name)s' % row))
718789

790+
return dumps(dict(results=rtn))

modules/plugin_cs_monitor/html_helpers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
'STOPPED' : ('#B94A48', SPAN('STOPPED', _class="label label-danger")),
1212
'EXPIRED' : ('#F89406', SPAN('EXPIRED', _class="label label-warning")),
1313
'ASSIGNED' : ('#FAA732', SPAN('ASSIGNED', _class="label label-warning")),
14-
'TIMEOUT' : ('#FAA732', SPAN('TIMEOUT', _class="label label-warning")),
14+
'TIMEOUT' : ('#B94A48', SPAN('TIMEOUT', _class="label label-warning")),
1515
}
1616

1717
WORKER_STATUS = {

static/plugin_cs_monitor/js/instantclick.min.js

+13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Copyright 2014 Igor Vaynberg
2+
3+
Version: @@ver@@ Timestamp: @@timestamp@@
4+
5+
This software is licensed under the Apache License, Version 2.0 (the "Apache License") or the GNU
6+
General Public License version 2 (the "GPL License"). You may choose either license to govern your
7+
use of this software only upon the condition that you accept all of the terms of either the Apache
8+
License or the GPL License.
9+
10+
You may obtain a copy of the Apache License and the GPL License at:
11+
12+
http://www.apache.org/licenses/LICENSE-2.0
13+
http://www.gnu.org/licenses/gpl-2.0.html
14+
15+
Unless required by applicable law or agreed to in writing, software distributed under the Apache License
16+
or the GPL Licesnse is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
17+
either express or implied. See the Apache License and the GPL License for the specific language governing
18+
permissions and limitations under the Apache License and the GPL License.

0 commit comments

Comments
 (0)