Changeset 3c1479 in indico


Ignore:
Timestamp:
10/13/10 17:22:32 (3 years ago)
Author:
Pedro Ferreira <jose.pedro.ferreira@…>
Branches:
master, burotel, hello-world-walkthrough, ipv6, v0.98-series, v0.98.2, v0.98.3, v0.98b1, v0.98b2, v0.99, 051b2622c51afb171a1dedb46a0df4fbb0cbd02e, 0da0c1403bae8e51d8229f460181c71b9e6dda72
Children:
456f15
Parents:
775b91
git-author:
Juan Alonso <juan.alonso.hernandez@…> (08/07/09 09:40:04)
git-committer:
Pedro Ferreira <jose.pedro.ferreira@…> (10/13/10 17:22:32)
Message:

[IMPROVEMENT] New taskdaemon

Totally refactored.

Files:
12 added
9 edited

Legend:

Unmodified
Added
Removed
  • bin/legacy/chdatetime.py

    rbdd862 r3c1479  
    3838        chconf(conf) 
    3939      get_transaction().commit() 
     40     
    4041    # Tasks 
     42    # tl = Supervisor. 
    4143    htl = timerExec.HelperTaskList.getTaskListInstance() 
    4244    for task in htl.getTasks(): 
  • bin/utils/indicoShell.py

    rb79d09 r3c1479  
    88from MaKaC.conference import Conference, Category, ConferenceHolder, CategoryManager, DeletedObjectHolder 
    99from MaKaC.user import AvatarHolder, GroupHolder 
    10 from MaKaC.common.timerExec import HelperTaskList 
     10from MaKaC.common.timerExec import HelperTaskList # DEPRECATED 
    1111from MaKaC.common.info import HelperMaKaCInfo 
    1212from MaKaC.plugins.base import PluginsHolder 
     
    4747    add(namespace, AvatarHolder) 
    4848    add(namespace, GroupHolder) 
    49     add(namespace, HelperTaskList) 
     49    add(namespace, HelperTaskList) # DEPRECATED 
    5050    add(namespace, HelperMaKaCInfo) 
    5151    add(namespace, PluginsHolder) 
  • indico/MaKaC/booking.py

    rbdd862 r3c1479  
    4141from MaKaC.common.Locators import Locator 
    4242from MaKaC.accessControl import AccessController 
    43 from MaKaC.common.timerExec import HelperTaskList, Alarm 
    4443from MaKaC.errors import MaKaCError, TimingError, ParentTimingError 
    4544from MaKaC import registration 
  • indico/MaKaC/common/dvdCreation.py

    rbdd862 r3c1479  
    1818## along with CDS Indico; if not, write to the Free Software Foundation, Inc., 
    1919## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 
     20 
     21'''TODO TASKDAEMON: remove this file once the migration to the new taskDaemon is complete''' 
    2022 
    2123import traceback, string 
     
    460462        return publicFileURL 
    461463     
     464     
    462465class RHWrapper(Persistent): 
    463  
    464466    def __init__(self, rh): 
    465467        self._user = rh._getUser() 
     
    483485        return "" 
    484486     
     487     
    485488class DVDCreation: 
    486  
    487489    def __init__(self, rh, conf, wf): 
    488490        self._rh=rh 
     
    504506        dvdTask.addObj(dvdCreator) 
    505507 
    506         # Add the track to the track list 
     508        # Add the task to the task list 
    507509        htl = HelperTaskList.getTaskListInstance() 
    508510        htl.addTask(dvdTask) 
    509511 
    510          
  • indico/MaKaC/common/pendingQueues.py

    rbdd862 r3c1479  
    2424from MaKaC.webinterface import mail, urlHandlers 
    2525from MaKaC.common.info import HelperMaKaCInfo 
    26 from MaKaC.common.timerExec import HelperTaskList, task, obj 
     26from MaKaC.common.timerExec import task, obj 
     27from MaKaC.tasks.controllers import Supervisor 
     28from MaKaC.tasks.base import OneShotTask  
    2729from persistent import Persistent 
    2830from MaKaC.user import AvatarHolder 
     
    3335#---GENERAL---- 
    3436 
    35 class PendingHolder: 
    36  
     37class PendingHolder(object): 
    3738    """ This is an index that holds all the requests to add pending people to become 
    3839        Indico users. 
     
    7576        """We must implement this method in order to sent an email with the reminder for the specific pending users""" 
    7677        pass 
     78     
    7779 
    7880    def _getTasksIdx(self): 
     
    8587        if not self._hasTask(email): 
    8688            # Create the object which send the email 
    87             pedingReminder=self._reminder(email) 
    88             pedingReminder.setId("ReminderPending%s-%s"%(self._id,email)) 
     89            pedingReminder = self._reminder(email) 
     90            pedingReminder.setId("ReminderPending%s-%s" % (self._id,email)) 
    8991            # Create the task 
    9092            t=task() 
     
    9597            t.setEndDate(nw+timedelta(15)) # keep trying during 15 days 
    9698            self._tasksIdx.indexTask(email, t) 
    97             # Add the track to the track list 
    98             htl = HelperTaskList.getTaskListInstance() 
    99             htl.addTask(t) 
     99             
     100            Supervisor.addTask(t) 
     101             
    100102         
    101103    def _removeTask(self, email): 
    102104        if self._hasTask(email): 
    103105            t=self._getTasksIdx().matchTask(email)[0] 
    104             htl = HelperTaskList.getTaskListInstance() 
    105             htl.removeTask(t) 
     106            Supervisor.removeTask(t) 
    106107            self._tasksIdx.unindexTask(email, t) 
    107108 
     
    109110        return self._getTasksIdx().matchTask(email) != [] 
    110111 
    111 class _PendingNotification: 
     112 
     113class _PendingNotification(object): 
    112114 
    113115    def __init__( self, psList ): 
     
    148150        return d 
    149151 
    150 class PendingReminder(obj): 
    151  
    152     def __init__(self, email): 
    153         obj.__init__(self) 
    154         self._email=email 
     152 
     153class PendingReminder(OneShotTask): 
     154    def __init__(self, email, **kwargs): 
     155        super(PendingReminder, self).__init__(**kwargs) 
     156        self._email = email 
    155157 
    156158    def run(self): 
     
    174176            return True 
    175177        return False 
    176  
    177     def endTask(self): 
    178         """Mandatory to implement for the specific queues. 
    179            It removes the task from the task list and from the index of the pending queue""" 
    180         pass 
     178     
     179    def tearDown(self): 
     180        '''Inheriting classes must implement this method''' 
     181        raise Exception('Unimplemented tearDown') 
     182     
    181183     
    182184    def getEmail(self): 
     
    278280                mail.GenericMailer.send( notif ) 
    279281 
    280     def endTask(self): 
     282    def tearDown(self): 
    281283        psh=PendingSubmittersHolder() 
    282284        psl=psh.getPendingByEmail(self._email) 
     
    368370        return participations 
    369371 
     372 
    370373class PendingManagerReminder(PendingReminder): 
    371374 
     
    379382                mail.GenericMailer.send( notif ) 
    380383 
    381     def endTask(self): 
    382         psh=PendingManagersHolder() 
    383         psl=psh.getPendingByEmail(self._email) 
     384    def tearDown(self): 
     385        psh = PendingManagersHolder() 
     386        psl = psh.getPendingByEmail(self._email) 
    384387        for e in psl: 
    385388            e.getConference().getPendingQueuesMgr().removePendingManager(e) 
     
    436439 
    437440class _PendingConfManagerNotification(_PendingNotification): 
    438  
    439441    def getBody( self ): 
    440442        url = urlHandlers.UHUserCreation.getURL() 
     
    463465        return participations 
    464466 
     467 
    465468class PendingConfManagerReminder(PendingReminder): 
    466  
    467469    def run(self): 
    468470        hasAccount=PendingReminder.run(self) 
     
    474476                mail.GenericMailer.send( notif ) 
    475477 
    476     def endTask(self): 
    477         psh=PendingManagersHolder() 
    478         psl=psh.getPendingByEmail(self._email) 
     478    def tearDown(self): 
     479        psh = PendingManagersHolder() 
     480        psl = psh.getPendingByEmail(self._email) 
    479481        for e in psl: 
    480482            e.getConference().getPendingQueuesMgr().removePendingManager(e) 
    481483     
    482484    def getPendings(self): 
    483         psh=PendingManagersHolder() 
     485        psh = PendingManagersHolder() 
    484486        return psh.getPendingByEmail(self._email) 
    485487#---END MANAGERS  
     
    560562        return participations 
    561563 
     564 
    562565class PendingCoordinatorReminder(PendingReminder): 
    563  
    564566    def run(self): 
    565567        hasAccount=PendingReminder.run(self) 
    566568        if not hasAccount: 
    567             psh=PendingCoordinatorsHolder() 
    568             psl=psh.getPendingByEmail(self._email) 
     569            psh = PendingCoordinatorsHolder() 
     570            psl = psh.getPendingByEmail(self._email) 
    569571            if psl != [] and psl is not None: 
    570                 notif = _PendingCoordinatorNotification( psl ) 
    571                 mail.GenericMailer.send( notif ) 
    572  
    573     def endTask(self): 
    574         psh=PendingCoordinatorsHolder() 
    575         psl=psh.getPendingByEmail(self._email) 
     572                notif = _PendingCoordinatorNotification(psl) 
     573                mail.GenericMailer.send(notif) 
     574 
     575    def tearDown(self): 
     576        psh = PendingCoordinatorsHolder() 
     577        psl = psh.getPendingByEmail(self._email) 
    576578        for e in psl: 
    577579            e.getConference().getPendingQueuesMgr().removePendingCoordinator(e) 
    578580     
    579581    def getPendings(self): 
    580         psh=PendingCoordinatorsHolder() 
     582        psh = PendingCoordinatorsHolder() 
    581583        return psh.getPendingByEmail(self._email) 
    582584 
     
    584586 
    585587#--GENERAL--- 
    586 class PendingQueuesHolder: 
     588class PendingQueuesHolder(object): 
    587589 
    588590    _pendingQueues=[PendingSubmittersHolder, \ 
  • indico/MaKaC/common/timerExec.py

    r8e9fd9 r3c1479  
    1818## along with CDS Indico; if not, write to the Free Software Foundation, Inc., 
    1919## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 
     20 
     21'''TODO TASKDAEMON: remove this file once the migration to the new taskDaemon is complete''' 
    2022 
    2123import time, signal, copy, sys, traceback 
     
    533535        self.smtpServer = Config.getInstance().getSmtpServer() 
    534536        TrashCanManager().remove(self) 
    535  
    536  
    537 class FoundationSync( obj ): 
    538     """ 
    539     Synchronizes room data (along with associated room managers 
    540     and equipment) with Foundation database. 
    541  
    542     Also, updates list of CERN Official Holidays 
    543  
    544     (This is object for a task class) 
    545     """ 
    546     def __init__(self): 
    547         obj.__init__(self) 
    548  
    549     def run(self): 
    550         from MaKaC.common.FoundationSync.foundationSync import FoundationSync 
    551         FoundationSync().doAll() 
    552  
    553     def delete(self): 
    554         TrashCanManager().add( self ) 
    555  
    556     def recover(self): 
    557         TrashCanManager().remove( self ) 
    558  
    559     @staticmethod 
    560     def register(): 
    561         """ 
    562         Run ONCE to add FoundationSync task 
    563         """ 
    564         # Connect to Indico DB 
    565         db.DBMgr.getInstance().startRequest() 
    566         db.DBMgr.getInstance().sync() 
    567         TASK_ID = 'FoundationSyncTask' 
    568  
    569         t = task() 
    570         t.setId( TASK_ID ) 
    571         d = nowutc() + timedelta( days = 1 ) 
    572         t.setStartDate( d.replace( hour=0, minute=0, second=0, microsecond=0 )) # This midnight 
    573         t.setInterval( timedelta( days = 1 ) ) 
    574         t.addObj( FoundationSync() ) 
    575  
    576         # Check if tasks existis 
    577         taskList = HelperTaskList.getTaskListInstance() 
    578         for existing in taskList.getTasks(): 
    579             if existing.getId() == t.getId(): 
    580                 print TASK_ID + " is already registered" 
    581                 return 
    582  
    583         # Task does not exist: add it 
    584         taskList.addTask( t ) 
    585  
    586         # Disconnect from Indico DB 
    587         db.DBMgr.getInstance().endRequest() 
    588         print "Successfully registered " + TASK_ID 
    589537 
    590538 
     
    880828        TrashCanManager().remove(self) 
    881829 
    882 class StatisticsUpdater(obj): 
    883     def __init__(self, cat): 
    884         self._cat = cat 
    885  
    886     def run( self ): 
    887         CategoryStatistics.updateStatistics(self._cat) 
    888  
    889     def delete(self): 
    890         for obj in self.getObjList(): 
    891             self.removeObj(obj) 
    892             # Id the delete method doesn't exist for obj it has to be 
    893             # implemented. 
    894             obj.delete() 
    895         self.conf = None 
    896         TrashCanManager().add(self) 
    897  
    898     def recover(self): 
    899         TrashCanManager().remove(self) 
    900  
    901830if __name__ == "__main__": 
    902831    """ 
  • indico/MaKaC/consoleScripts/taskDaemon.py

    rbdd862 r3c1479  
    2222import sys, getopt, os, time 
    2323 
    24 duration = 15*60 # seconds 
    25 linuxPIDFile="/var/run/IndicoTaskDaemon.pid" 
    26 logFile="/opt/indico/log/taskDaemon.log" 
    27  
    2824def _isPosix(): 
    2925    return os.name == "posix" 
     
    3228    return os.name == "nt" 
    3329 
    34 def _savePID(pid): 
     30def _savePID(pid, pid_file): 
    3531    try: 
    36         f=open(linuxPIDFile, "w") 
    37         f.write(str(pid)) 
    38         f.close() 
     32        open(pid_file, "w").write(str(pid)) 
    3933    except IOError, e: 
    40         print "Exception while trying to store the daemon PID in the file '%s':\n%s"%(linuxPIDFile, e) 
     34        print "Exception while trying to store the daemon PID in the file '%s':\n%s" % (linuxPIDFile, e) 
     35 
    4136 
    4237def _getPID(printExceptions=True): 
    4338    try: 
    44         f=open(linuxPIDFile, "r") 
    45         pid=f.read() 
    46         pid=pid.strip() 
    47         pid=int(pid) 
    48         f.close() 
     39        pid = int(open(linuxPIDFile, "r").read().strip()) 
    4940        return pid 
    5041    except IOError, e: 
    5142        if printExceptions: 
    52             print "Exception while opening the file '%s' with the daemon PID:\n%s"%(linuxPIDFile, e) 
     43            print "Exception while opening the file '%s' with the daemon PID:\n%s" % (linuxPIDFile, e) 
    5344    except ValueError, e: 
    5445        if printExceptions: 
    55             print "Exception while reading the file '%s' with the daemon PID:\nThere is not a PID in the file"%(linuxPIDFile) 
     46            print "Exception while reading the file '%s' with the daemon PID:\nThere is not a PID in the file" % (linuxPIDFile) 
    5647    return -1 
    5748 
     49 
    5850def _killProcess(): 
    59     if _isPosix(): 
    60         pid=_getPID() 
    61         if pid != -1: 
    62             try: 
    63                 os.kill(pid, 9) 
    64             except OSError, e: 
    65                 print e 
    66                 return False 
     51    if not _isPosix(): 
     52        return False 
     53     
     54    pid = _getPID() 
     55    if pid != -1: 
     56        try: 
     57            os.kill(pid, 9) 
     58        except OSError, e: 
     59            print e 
     60        else: 
    6761            os.remove(linuxPIDFile) 
    6862            return True 
     63         
    6964    return False 
    7065 
     
    108103    print "" 
    109104 
    110 def fileExists(f): 
    111      try: 
    112         fi = open(f,'a') 
    113         fi.close() 
    114      except IOError: 
    115          exists = False 
    116      else: 
    117          exists = True 
    118      return exists 
    119  
    120105 
    121106def run(log=None): 
    122     from MaKaC.common.timerExec import timer 
    123  
    124     if _isPosix() and (not log or not fileExists(log)): 
    125         print "\nPlease enter an existing log file, and start again\nDaemon stopped!\n" 
    126         os.remove(linuxPIDFile) 
    127         sys.exit(2) 
    128     t = timer(duration, log) 
    129     initDefaultTasks() 
    130     t.start() 
     107    from MaKaC.tasks.controllers import Supervisor 
     108    Supervisor.getInstance().run() 
     109    # initDefaultTasks() 
     110     
    131111 
    132112def startTaskDaemon(): 
     
    138118        print "Task daemon is already running" 
    139119        sys.exit(0) 
     120         
    140121    if _isPosix(): 
    141122        pid=os.fork() 
    142123        if pid==0: 
    143124            #Child 
    144             run(log=logFile) 
     125            run() 
    145126        else: 
    146127            #Parent 
    147             _savePID(pid) 
     128            _savePID(pid, linuxPIDFile) 
    148129            print "Daemon started! (pid=%s)\n"%pid 
    149130            time.sleep(3) 
     
    154135        print "Impossible to start the daemon" 
    155136 
     137 
    156138def stopTaskDaemon(): 
    157139    if _killProcess(): 
     
    160142        print "Impossible to stop the process 'taskDaemon', please do it manually" 
    161143 
     144 
    162145def restartTaskDaemon(): 
    163     _killProcess() 
    164     print "Daemon stopped!" 
     146    stopTaskDaemon() 
    165147    startTaskDaemon() 
     148 
    166149 
    167150def main(): 
    168151    "Main" 
    169152    try: 
    170         opts, args = getopt.getopt(sys.argv[1:],"hstr", \ 
    171                  [ \ 
    172                    "help", \ 
    173                    "start", \ 
    174                    "stop", \ 
    175                    "restart" \ 
    176                  ] 
    177         ) 
     153        opts, args = getopt.getopt(sys.argv[1:],"hstr", [ "help", "start", "stop", "restart" ]) 
    178154    except getopt.GetoptError, e: 
    179         help() 
     155        usage() 
    180156        sys.exit(2) 
    181157 
    182     arg=None 
     158    arg = None 
    183159    if len(args) == 1: 
    184160        arg=args[0] 
    185161    elif len(opts)==1: 
    186162        arg=opts[0][0] 
    187     if arg is not None: 
    188         if   arg in ("start", "s", "-s"): 
     163         
     164    if arg: 
     165        if arg in ("start", "s", "-s"): 
    189166            startTaskDaemon() 
    190167        elif arg in ("stop", "t", "-t"): 
     
    193170            restartTaskDaemon() 
    194171        elif arg in ("help", "h", "-h", "--help"): 
    195             help() 
     172            usage() 
    196173            sys.exit() 
    197174        else: 
    198             help() 
     175            usage() 
    199176            sys.exit(2) 
    200177        return 
    201178    else: 
    202         help() 
     179        usage() 
    203180        sys.exit(2) 
    204181 
    205182 
    206 def help(): 
    207         "Print out info" 
     183def usage(): 
     184    print "\nUsage: python taskDaemon.py  start|stop|restart [-h]\n" 
     185    print "  -h                    Help" 
     186    print "  -s                    Start the task daemon" 
     187    print "  -t                    Stop the task daemon" 
     188    print "  -r                    Restart the task daemon" 
    208189 
    209         print "\nUsage: python taskDaemon.py  start|stop|restart [-h]\n" 
    210         print "  -h                    Help" 
    211         print "  -s                    Start the task daemon" 
    212         print "  -t                    Stop the task daemon" 
    213         print "  -r                    Restart the task daemon" 
    214190 
    215191if __name__ == "__main__": 
     192    from MaKaC.common.Configuration import Config 
     193    cfg = Config.getInstance() 
     194    linuxPIDFile = "%s/IndicoTaskDaemon.pid" % cfg.getLogDir() 
     195    logFile = "%s/taskDaemon.log" % cfg.getLogDir() 
    216196    main() 
  • indico/MaKaC/modules/base.py

    rbdd862 r3c1479  
    5050        import MaKaC.modules.cssTpls as cssTpls 
    5151        import MaKaC.modules.upcoming as upcoming 
    52  
     52        import MaKaC.modules.tasks as tasks 
     53         
    5354        ModulesHolder._availableModules = { 
    54             news.NewsModule.id:news.NewsModule, 
    55             cssTpls.CssTplsModule.id:cssTpls.CssTplsModule, 
    56             upcoming.UpcomingEventsModule.id:upcoming.UpcomingEventsModule 
     55            news.NewsModule.id               : news.NewsModule, 
     56            cssTpls.CssTplsModule.id         : cssTpls.CssTplsModule, 
     57            upcoming.UpcomingEventsModule.id : upcoming.UpcomingEventsModule, 
     58            tasks.TasksModule.id             : tasks.TasksModule 
    5759        } 
    5860 
  • setup.py

    r80f35b r3c1479  
    114114 
    115115    base =  ['pytz', 'zope.index', 'zope.interface', 'simplejson', 'suds', 
    116              'lxml', 'cds-indico-extras'] 
     116             'lxml', 'cds-indico-extras', 'zc-queue'] 
    117117    if sys.version_info[1] < 5: #for Python older than 2.5 
    118118        base.append('hashlib') # hashlib isn't a part of Python older than 2.5 
Note: See TracChangeset for help on using the changeset viewer.