src/pyams_scheduler/zmi/scheduler.py
changeset 19 687d616d7dfb
parent 11 2746eb7b3437
child 22 b1a1ccc1fa26
equal deleted inserted replaced
18:4806161ea41a 19:687d616d7dfb
    30 from pyams_zmi.layer import IAdminLayer
    30 from pyams_zmi.layer import IAdminLayer
    31 from z3c.table.interfaces import IColumn, IValues
    31 from z3c.table.interfaces import IColumn, IValues
    32 from zope.component.interfaces import ISite
    32 from zope.component.interfaces import ISite
    33 
    33 
    34 # import packages
    34 # import packages
    35 import zmq
       
    36 from pyams_form.form import AJAXEditForm
    35 from pyams_form.form import AJAXEditForm
    37 from pyams_pagelet.pagelet import pagelet_config
    36 from pyams_pagelet.pagelet import pagelet_config
    38 from pyams_skin.container import ContainerView
    37 from pyams_skin.container import ContainerView
    39 from pyams_skin.page import DefaultPageHeaderAdapter
    38 from pyams_skin.page import DefaultPageHeaderAdapter
    40 from pyams_skin.table import DefaultElementEditorAdapter, BaseTable, I18nColumn, TrashColumn, ActionColumn
    39 from pyams_skin.table import DefaultElementEditorAdapter, BaseTable, I18nColumn, TrashColumn, ActionColumn
    47 from pyams_utils.url import absolute_url
    46 from pyams_utils.url import absolute_url
    48 from pyams_viewlet.manager import viewletmanager_config
    47 from pyams_viewlet.manager import viewletmanager_config
    49 from pyams_viewlet.viewlet import viewlet_config, Viewlet
    48 from pyams_viewlet.viewlet import viewlet_config, Viewlet
    50 from pyams_zmi.form import AdminDialogEditForm, AdminDialogDisplayForm
    49 from pyams_zmi.form import AdminDialogEditForm, AdminDialogDisplayForm
    51 from pyams_zmi.view import AdminView
    50 from pyams_zmi.view import AdminView
       
    51 from pyams_zmq.socket import zmq_socket, zmq_response
    52 from pyramid.url import resource_url
    52 from pyramid.url import resource_url
    53 from pyramid.view import view_config
    53 from pyramid.view import view_config
    54 from z3c.form import field
    54 from z3c.form import field
    55 from z3c.table.column import GetAttrColumn
    55 from z3c.table.column import GetAttrColumn
    56 from zope.interface import implementer, Interface
    56 from zope.interface import implementer, Interface
    77 @implementer(ISchedulerMenu)
    77 @implementer(ISchedulerMenu)
    78 class SchedulerMenuItem(MenuItem):
    78 class SchedulerMenuItem(MenuItem):
    79     """Scheduler menu"""
    79     """Scheduler menu"""
    80 
    80 
    81     label = _("Tasks scheduler")
    81     label = _("Tasks scheduler")
    82     icon_class = 'fa fa-fw fa-clock-o'
    82     icon_class = 'fa-clock-o'
    83     url = '#scheduler-tasks.html'
    83     url = '#scheduler-tasks.html'
    84 
    84 
    85 
    85 
    86 class SchedulerTasksTable(BaseTable):
    86 class SchedulerTasksTable(BaseTable):
    87     """Scheduler tasks table"""
    87     """Scheduler tasks table"""
   362 
   362 
   363     @property
   363     @property
   364     def values(self):
   364     def values(self):
   365         handler = self.request.registry.settings.get(SCHEDULER_HANDLER_KEY, False)
   365         handler = self.request.registry.settings.get(SCHEDULER_HANDLER_KEY, False)
   366         if handler:
   366         if handler:
   367             context = zmq.Context()
   367             socket = zmq_socket(handler)
   368             socket = context.socket(zmq.REQ)
       
   369             socket.connect('tcp://{0}'.format(handler))
       
   370             socket.send_json(['get_jobs', {}])
   368             socket.send_json(['get_jobs', {}])
   371             return socket.recv_json()
   369             status, response = zmq_response(socket)
       
   370             if status == 200:
       
   371                 return response
       
   372             else:  # error
       
   373                 return ()
   372         else:
   374         else:
   373             return ()
   375             return ()
   374 
   376 
   375 
   377 
   376 @viewlet_config(name='scheduler-jobs', view=SchedulerJobsDisplayForm, layer=IAdminLayer,
   378 @viewlet_config(name='scheduler-jobs', view=SchedulerJobsDisplayForm, layer=IAdminLayer,