Beispiel #1
0
def _show(args):

    dbi = DBMgr.getInstance()

    dbi.startRequest()
    c = Client()

    if args.field == "status":
        status = c.getStatus()

        print "Scheduler is currently %s" % \
              ("running" if status['state'] else "NOT running")
        print """
Spooled commands: %(spooled)s

Tasks:
  - Waiting:  %(waiting)s
  - Running:  %(running)s
  - Failed:   %(failed)s
  - Finished: %(finished)s
""" % status
    elif args.field == "spool":

        for op, obj in c.getSpool():
            if op in ['add', 'del']:
                print "%s %s" % (op, obj)
            else:
                print op

    dbi.endRequest()
Beispiel #2
0
def addOccurrenceNotificationsTask(dbi, prevVersion):
    """
    Add OccurrenceNotificationsTask to scheduler and remove old RoomReservationTask
    """
    scheduler_client = Client()
    scheduler_module = scheduler_client._schedMod
    old_tasks = []

    for _, task in scheduler_module.getWaitingQueue():
        if getattr(task, 'typeId', None) in {'RoomReservationTask', 'RoomReservationEndTask'}:
            old_tasks.append(task)
    for task in scheduler_module._runningList:
        if getattr(task, 'typeId', None) in {'RoomReservationTask', 'RoomReservationEndTask'}:
            old_tasks.append(task)
    for finished_task in scheduler_module._finishedIndex.values():
        task = finished_task._task if hasattr(finished_task, '_task') else finished_task
        if getattr(task, 'typeId', None) in {'RoomReservationTask', 'RoomReservationEndTask'}:
            scheduler_module._finishedIndex.unindex_obj(finished_task)
    for failed_task in scheduler_module._failedIndex.values():
        task = failed_task._task if hasattr(failed_task, '_task') else failed_task
        if getattr(task, 'typeId', None) in {'RoomReservationTask', 'RoomReservationEndTask'}:
            scheduler_module._failedIndex.unindex_obj(failed_task)
    for task in old_tasks:
        scheduler_client.dequeue(task)

    scheduler_client.enqueue(OccurrenceNotifications(rrule.HOURLY, byminute=0, bysecond=0))
    dbi.commit()
Beispiel #3
0
def _stop(args):

    _setup(args)

    running = _check_running()

    if not args.force and not running:
        raise Exception("The daemon doesn't seem to be running (consider -f?)")

    dbi = DBMgr.getInstance()
    dbi.startRequest()
    c = Client()
    c.shutdown(msg="Daemon script")
    dbi.commit()

    print "Waiting for death confirmation... "
    for i in range(0, 20):
        if not c.getStatus()['state']:
            break
        else:
            time.sleep(1)
            dbi.sync()
    else:
        print "FAILED!"

    print "DONE!"
    dbi.endRequest()
Beispiel #4
0
    def testTaskRelocate(self):
        """
        Creating 1 task and relocating it
        """

        self._startSomeWorkers([TestTask],
                               [base.TimeSource.get().getCurrentTime() + \
                                timedelta(seconds=2)])

        base.TimeSource.get().sleep(1)

        with self._context('database', sync=True) as conn:

            # wait to task to be scheduled
            c = Client()
            while True:
                try:
                    conn.sync()
                    t = c.getTask(0)
                    break
                except KeyError:
                    continue

            c.moveTask(t, base.TimeSource.get().getCurrentTime() + timedelta(seconds=2))

        self.assertEqual(self._checkWorkersFinished(5),
                         True)

        self._assertStatus({'state': True,
                            'waiting': 0,
                            'running': 0,
                            'spooled': 0,
                            'finished': 1,
                            'failed': 0})
Beispiel #5
0
    def _shutdown(self):

        with self._context('database', sync=True):
            c = Client()
            c.shutdown()

        self._sched.join()
Beispiel #6
0
def _show(args):

    dbi = DBMgr.getInstance()

    dbi.startRequest()
    c = Client()

    if args.field == "status":
        status = c.getStatus()

        if status['state']:
            print 'Scheduler is currently running on {0[hostname]} with pid {0[pid]}'.format(
                status)
        else:
            print 'Scheduler is currently NOT running'
        print """
Spooled commands: %(spooled)s

Tasks:
  - Waiting:  %(waiting)s
  - Running:  %(running)s
  - Failed:   %(failed)s
  - Finished: %(finished)s
""" % status
    elif args.field == "spool":

        for op, obj in c.getSpool():
            if op in ['add', 'del']:
                print "%s %s" % (op, obj)
            else:
                print op

    dbi.endRequest()
Beispiel #7
0
def _stop(args):

    _setup(args)

    running = _check_running()

    if not args.force and not running:
        raise Exception("The daemon doesn't seem to be running (consider -f?)")

    dbi = DBMgr.getInstance()
    dbi.startRequest()
    c = Client()
    c.shutdown(msg="Daemon script")
    dbi.commit()

    print "Waiting for death confirmation... "
    for i in range(0, 20):
        if not c.getStatus()['state']:
            break
        else:
            time.sleep(1)
            dbi.sync()
    else:
        print "FAILED!"

    print "DONE!"
    dbi.endRequest()
Beispiel #8
0
def _show(args):

    dbi = DBMgr.getInstance()

    dbi.startRequest()
    c = Client()

    if args.field == "status":
        status = c.getStatus()

        if status['state']:
            print 'Scheduler is currently running on {0[hostname]} with pid {0[pid]}'.format(status)
        else:
            print 'Scheduler is currently NOT running'
        print """
Spooled commands: %(spooled)s

Tasks:
  - Waiting:  %(waiting)s
  - Running:  %(running)s
  - Failed:   %(failed)s
  - Finished: %(finished)s
""" % status
    elif args.field == "spool":

        for op, obj in c.getSpool():
            if op in ['add', 'del']:
                print "%s %s" % (op, obj)
            else:
                print op

    dbi.endRequest()
Beispiel #9
0
    def _shutdown(self):

        with self._context('database', sync=True):
            c = Client()
            c.shutdown()

        self._sched.join()
Beispiel #10
0
def _show(args):

    dbi = DBMgr.getInstance()

    dbi.startRequest()
    c = Client()

    if args.field == "status":
        status = c.getStatus()

        print "Scheduler is currently %s" % \
              ("running" if status['state'] else "NOT running")
        print """
Spooled commands: %(spooled)s

Tasks:
  - Waiting:  %(waiting)s
  - Running:  %(running)s
  - Failed:   %(failed)s
  - Finished: %(finished)s
""" % status
    elif args.field == "spool":

        for op, obj in c.getSpool():
            if op in ['add', 'del']:
                print "%s %s" % (op, obj)
            else:
                print op

    dbi.endRequest()
Beispiel #11
0
def addSuggestionsTask(dbi, withRBDB, prevVersion):
    """Add Category Suggestion Task to scheduler (Redis needed)"""
    if not Config.getInstance().getRedisConnectionURL():
        print console.colored("  Redis not configured, skipping", 'yellow')
        return
    task = CategorySuggestionTask(rrule.DAILY)
    client = Client()
    client.enqueue(task)
    dbi.commit()
Beispiel #12
0
def addSuggestionsTask(dbi, withRBDB, prevVersion):
    """Add Category Suggestion Task to scheduler (Redis needed)"""
    if not Config.getInstance().getRedisConnectionURL():
        print console.colored("  Redis not configured, skipping", 'yellow')
        return
    task = CategorySuggestionTask(rrule.DAILY)
    client = Client()
    client.enqueue(task)
    dbi.commit()
Beispiel #13
0
 def register(interval=15):
     from indico.modules.scheduler import Client
     from dateutil.rrule import MINUTELY
     from MaKaC.common import DBMgr
     DBMgr.getInstance().startRequest()
     task = OutlookUpdateCalendarNotificationTask(MINUTELY, interval=interval)
     client = Client()
     client.enqueue(task)
     DBMgr.getInstance().endRequest()
Beispiel #14
0
    def _checkParams(self):
        SchedulerModuleAdminService._checkParams(self)
        tid = self._params.get('id', None)

        if tid == None:
            raise ServiceError('ERR-T0','Task Id not provided')

        self._client = Client()
        self._task = self._client.getTask(tid)
Beispiel #15
0
 def register(interval=15):
     from indico.modules.scheduler import Client
     from dateutil.rrule import MINUTELY
     from indico.core.db import DBMgr
     DBMgr.getInstance().startRequest()
     task = OutlookUpdateCalendarNotificationTask(MINUTELY, interval=interval)
     client = Client()
     client.enqueue(task)
     DBMgr.getInstance().endRequest()
Beispiel #16
0
def _check_running():

    dbi = DBMgr.getInstance()

    dbi.startRequest()
    c = Client()
    running = c.getStatus()['state']
    dbi.endRequest()

    return running
Beispiel #17
0
def _check_running():

    dbi = DBMgr.getInstance()

    dbi.startRequest()
    c = Client()
    running = c.getStatus()['state']
    dbi.endRequest()

    return running
Beispiel #18
0
def _cmd(args):

    dbi = DBMgr.getInstance()

    dbi.startRequest()
    c = Client()

    if args.command == "clear_spool":
        print "%s operations removed" % c.clearSpool()

    dbi.endRequest()
Beispiel #19
0
def _cmd(args):

    dbi = DBMgr.getInstance()

    dbi.startRequest()
    c = Client()

    if args.command == "clear_spool":
        print "%s operations removed" % c.clearSpool()

    dbi.endRequest()
Beispiel #20
0
    def _run(self, args):

        if args.action == 'add_task':
            c = Client()
            task = LiveSyncUpdateTask(MINUTELY, interval=args.interval)
            c.enqueue(task)
            self._dbi.commit()
        elif args.action == 'export':
            self._export(args)
            self._dbi.abort()
        elif args.action == 'simulate':
            self._simulate(args)
            self._dbi.abort()
Beispiel #21
0
    def _run(self, args):

        if args.action == 'add_task':
            c = Client()
            task = LiveSyncUpdateTask(MINUTELY, interval=args.interval)
            c.enqueue(task)
            self._dbi.commit()
        elif args.action == 'export':
            self._export(args)
            self._dbi.abort()
        elif args.action == 'simulate':
            self._simulate(args)
            self._dbi.abort()
Beispiel #22
0
def taskMigration(dbi, withRBDB, prevVersion):
    """
    Migrating database tasks from the old format to the new one
    """

    c = Client()

    for t in HelperTaskList().getTaskListInstance().getTasks():
        for obj in t.listObj.values():
            print console.colored("   * %s" % obj.__class__.__name__, 'blue')
            if obj.__class__.__name__ == 'FoundationSync':
                c.enqueue(
                    FoundationSyncTask(rrule.DAILY, byhour=0, byminute=0))
            elif obj.__class__.__name__ == 'StatisticsUpdater':
                c.enqueue(CategoryStatisticsUpdaterTask(
                    CategoryManager().getById('0'),
                    rrule.DAILY,
                    byhour=0, byminute=0))
            elif obj.__class__.__name__ == 'sendMail':
                # they have to be somewhere in the conference
                alarm = t.conf.alarmList[t.id]
                c.enqueue(alarm)
            else:
                raise Exception("Unknown task type!")

    if withRBDB:
        DALManager.commit()
    dbi.commit()
Beispiel #23
0
def _check(args):
    if not os.path.isdir('/proc'):
        raise Exception('This command only works on systems that have /proc/')

    with DBMgr.getInstance().global_connection():
        status = Client().getStatus()
        if status['hostname'] is not None and status[
                'hostname'] != socket.getfqdn():
            print >> sys.stderr, 'The daemon is running on another machine ({0[hostname]})'.format(
                status)
            sys.exit(2)

        db_running = _check_running(False)
        os_running = _check_running(True)

        if not args.quiet:
            print >> sys.stderr, 'Database status: running={1}, host={0[hostname]}, pid={0[pid]}'.format(
                status, db_running)
            print >> sys.stderr, 'Process status:  running={0}'.format(
                os_running)

        if db_running and os_running:
            print status['pid']
            sys.exit(0)
        elif not db_running and not os_running:
            sys.exit(1)
        elif db_running and not os_running:
            if not args.quiet:
                print >> sys.stderr, 'Marking dead scheduler as not running'
            SchedulerModule.getDBInstance().setSchedulerRunningStatus(False)
            DBMgr.getInstance().commit()
            sys.exit(1)
        else:
            print >> sys.stderr, 'Unexpected state! Process is running, but scheduler is not marked as running'
            sys.exit(2)
Beispiel #24
0
    def testPriority(self):
        """
        Checking that one task is executed before another
        """

        self._workers = {}

        global terminated

        terminated = multiprocessing.Array('i', [0, 0])

        terminated[0] = 0
        terminated[1] = 0

        w1 = Worker(0, TestTask, base.TimeSource.get().getCurrentTime() + \
                    timedelta(seconds=4))
        w1.start()

        base.TimeSource.get().sleep(1)

        w2 = Worker(1, TestTask, base.TimeSource.get().getCurrentTime() + \
                    timedelta(seconds=0))
        w2.start()

        self._workers[0] = w1
        self._workers[1] = w2

        w1.join()
        w2.join()

        self.assertEqual(self._checkWorkersFinished(10), True)

        self._assertStatus({
            'state': True,
            'waiting': 0,
            'running': 0,
            'spooled': 0,
            'finished': 2,
            'failed': 0
        })

        with self._context('database', sync=True):
            c = Client()
            t1 = c.getTask(0)
            t2 = c.getTask(1)

            self.assertEqual(t1.endedOn > t2.endedOn, True)
Beispiel #25
0
    def testPriority(self):
        """
        Checking that one task is executed before another
        """

        self._workers = {}

        global terminated

        terminated = multiprocessing.Array('i', [0, 0])

        terminated[0] = 0
        terminated[1] = 0

        w1 = Worker(0, TestTask, base.TimeSource.get().getCurrentTime() + \
                    timedelta(seconds=4))
        w1.start()

        base.TimeSource.get().sleep(1)

        w2 = Worker(1, TestTask, base.TimeSource.get().getCurrentTime() + \
                    timedelta(seconds=0))
        w2.start()

        self._workers[0] = w1
        self._workers[1] = w2

        w1.join()
        w2.join()

        self.assertEqual(self._checkWorkersFinished(10),
                         True)

        self._assertStatus({'state': True,
                            'waiting': 0,
                            'running': 0,
                            'spooled': 0,
                            'finished': 2,
                            'failed': 0})

        with self._context('database', sync=True):
            c = Client()
            t1 = c.getTask(0)
            t2 = c.getTask(1)

            self.assertEqual(t1.endedOn > t2.endedOn, True)
Beispiel #26
0
def taskMigration(dbi, withRBDB, prevVersion):
    """
    Migrating database tasks from the old format to the new one
    """

    c = Client()

    for t in HelperTaskList().getTaskListInstance().getTasks():
        for obj in t.listObj.values():
            print console.colored("   * %s" % obj.__class__.__name__, 'blue')
            if obj.__class__.__name__ == 'OfflineWebsiteCreator':
                continue
            if obj.__class__.__name__ == 'FoundationSync':
                c.enqueue(
                    FoundationSyncTask(rrule.DAILY, byhour=0, byminute=0))
            elif obj.__class__.__name__ == 'StatisticsUpdater':
                c.enqueue(CategoryStatisticsUpdaterTask(
                    CategoryManager().getById('0'),
                    rrule.DAILY,
                    byhour=0, byminute=0))
            elif obj.__class__.__name__ == 'sendMail':
                # they have to be somewhere in the conference
                alarm = t.conf.alarmList[t.id]
                c.enqueue(alarm)
            else:
                print console.colored("WARNING: Unknown task type!", 'yellow')

    if withRBDB:
        DALManager.commit()
    dbi.commit()
Beispiel #27
0
    def _checkParams(self):
        SchedulerModuleAdminService._checkParams(self)
        tid = self._params.get('id', None)

        if tid == None:
            raise ServiceError('ERR-T0','Task Id not provided')

        self._client = Client()
        self._task = self._client.getTask(tid)
Beispiel #28
0
    def _checkParams(self):
        SchedulerModuleAdminService._checkParams(self)
        tid = self._params.get("id", None)

        if tid == None:
            raise ServiceError("ERR-T0", "Task Id not provided")

        self._client = Client()
        self._task = self._client.getTask(tid)
Beispiel #29
0
def _check_running(check_process=False):

    with DBMgr.getInstance().global_connection():
        status = Client().getStatus()

    if not check_process:
        return status['state']

    if status['pid'] is None:
        return False
    return os.path.isdir('/proc/{0}/'.format(status['pid']))
Beispiel #30
0
def _restart(args):
    with DBMgr.getInstance().global_connection():
        status = Client().getStatus()
    if status['hostname'] is not None and status['hostname'] != socket.getfqdn(
    ) and not args.force:
        raise Exception(
            'The daemon is running on another machine ({0[hostname]}) (consider -f?)'
            .format(status))

    _stop(args)
    _start(args)
Beispiel #31
0
def addOccurrenceNotificationsTask(dbi, prevVersion):
    """
    Add OccurrenceNotificationsTask to scheduler and remove old RoomReservationTask
    """
    scheduler_client = Client()
    scheduler_module = scheduler_client._schedMod
    old_tasks = []

    for _, task in scheduler_module.getWaitingQueue():
        if getattr(task, 'typeId', None) in {'RoomReservationTask', 'RoomReservationEndTask'}:
            old_tasks.append(task)
    for task in scheduler_module._runningList:
        if getattr(task, 'typeId', None) in {'RoomReservationTask', 'RoomReservationEndTask'}:
            old_tasks.append(task)
    for finished_task in scheduler_module._finishedIndex.values():
        task = finished_task._task if hasattr(finished_task, '_task') else finished_task
        if getattr(task, 'typeId', None) in {'RoomReservationTask', 'RoomReservationEndTask'}:
            scheduler_module._finishedIndex.unindex_obj(finished_task)
    for failed_task in scheduler_module._failedIndex.values():
        task = failed_task._task if hasattr(failed_task, '_task') else failed_task
        if getattr(task, 'typeId', None) in {'RoomReservationTask', 'RoomReservationEndTask'}:
            scheduler_module._failedIndex.unindex_obj(failed_task)
    for task in old_tasks:
        scheduler_client.dequeue(task)

    scheduler_client.enqueue(OccurrenceNotifications(rrule.HOURLY, byminute=0, bysecond=0))
    dbi.commit()
Beispiel #32
0
    def testTaskRelocate(self):
        """
        Creating 1 task and relocating it
        """

        self._startSomeWorkers([TestTask],
                               [base.TimeSource.get().getCurrentTime() + \
                                timedelta(seconds=2)])

        base.TimeSource.get().sleep(1)

        with self._context('database', sync=True) as conn:

            # wait to task to be scheduled
            c = Client()
            while True:
                try:
                    conn.sync()
                    t = c.getTask(0)
                    break
                except KeyError:
                    continue

            c.moveTask(
                t,
                base.TimeSource.get().getCurrentTime() + timedelta(seconds=2))

        self.assertEqual(self._checkWorkersFinished(5), True)

        self._assertStatus({
            'state': True,
            'waiting': 0,
            'running': 0,
            'spooled': 0,
            'finished': 1,
            'failed': 0
        })
Beispiel #33
0
def runReservationNotificationMigration(dbi, withRBDB, prevVersion):
    """
    Migrate the reservation notification system.
    """
    if not withRBDB:
        return

    # Delete old start end notification data
    for i, resv in enumerate(CrossLocationQueries.getReservations()):
        if hasattr(resv, '_startEndNotification'):
            resv._startEndNotification = None
        if i % 1000 == 0:
            DALManager.commit()
    # Create start notification task
    Client().enqueue(RoomReservationTask(rrule.HOURLY, byminute=0, bysecond=0))
    DALManager.commit()
from indico.modules.scheduler import Client
from dateutil import rrule
from indico.core.db import DBMgr
from indicoaffiliation.tasks.ecosoc import ECOSOCListTask

dbi = DBMgr.getInstance()
c = Client()
pt = ECOSOCListTask(rrule.HOURLY)
c.enqueue(pt)
dbi.commit()
Beispiel #35
0
 def run(self):
     DBMgr.getInstance().startRequest()
     c = Client()
     c.enqueue(self._task_t(self._id, self._time, **self._extra_args))
     DBMgr.getInstance().endRequest()
Beispiel #36
0
 def run(self):
     DBMgr.getInstance().startRequest()
     c = Client()
     c.enqueue(self._task_t(self._id, self._time, **self._extra_args))
     DBMgr.getInstance().endRequest()