Exemplo n.º 1
0
def get_api(request, interface):
  if interface == 'beat':
    from desktop.lib.scheduler.lib.beat import CeleryBeatApi
    return CeleryBeatApi(user=request.user)
  elif interface == 'oozie':
    from desktop.lib.scheduler.lib.oozie import OozieApi
    return OozieApi(user=request.user)
  else:
    raise PopupException(_('Scheduler connector interface not recognized: %s') % interface)
Exemplo n.º 2
0
    def app(self, appid):
        appid = appid.rsplit('-')[-1]
        api = CeleryBeatApi(user=self.user)

        app = api.list_task(appid)

        return {
            'id': 'celery-beat-%(id)s' % app,
            'name': '%(name)s' % app,
            'status': self._massage_status(app),
            'apiStatus': self._api_status(self._massage_status(app)),
            'type': 'celery-beat',
            'user': app['description'],
            'progress': 50,
            'queue': app['queue'],
            'duration': 1,
            'canWrite': self.user.username == app['description'],
            'submitted': app.get('date_changed'),
            'properties': {}
        }
Exemplo n.º 3
0
    def action(self, app_ids, operation):
        api = CeleryBeatApi(user=self.user)

        operations = []
        actual_app_ids = [
            app_id.replace('celery-beat-', '') for app_id in app_ids
        ]

        for app_id in actual_app_ids:
            try:
                api.action(app_id, operation['action'])
                operations.append(app_id)
            except Exception:
                LOG.exception('Could not stop job %s' % app_id)

        return {
            'kills':
            operations,
            'status':
            len(app_ids) - len(operations),
            'message':
            _('%s signal sent to %s') % (operation['action'], operations)
        }
Exemplo n.º 4
0
    def apps(self, filters):
        api = CeleryBeatApi(user=self.user)

        tasks = api.list_tasks(self.user)

        return {
            'apps': [
                {
                    'id':
                    'celery-beat-%(id)s' % app,
                    'name':
                    '%(name)s' % app,
                    'status':
                    self._massage_status(app),
                    'apiStatus':
                    self._api_status(self._massage_status(app)),
                    'type':
                    'celery-beat',
                    'user':
                    app['description'],  # No user id available yet
                    'progress':
                    50,
                    'queue':
                    app['queue'],
                    'canWrite':
                    self.user.username == app['description'],
                    'duration':
                    ((datetime.now() - parser.parse(app['start_time']).replace(
                        tzinfo=None)).seconds *
                     1000) if app['start_time'] else 1,
                    'submitted':
                    app.get('date_changed')
                } for app in tasks
            ],
            'total':
            len(tasks)
        }