Changeset 116

Show
Ignore:
Timestamp:
12/04/07 01:14:12 (1 year ago)
Author:
edsuom
Message:

Modules reload in case they've changed; forgets jobs when the master says they're done.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • projects/AsynQueue/trunk/asynqueue/jobs.py

    r112 r116  
    2626from twisted.internet import defer, reactor 
    2727from twisted.python.failure import Failure 
    28 from twisted.python.reflect import namedObject 
     28from twisted.python import reflect 
    2929from twisted.spread import pb, flavors 
    3030 
     
    7272    def remote_registerClasses(self, *args): 
    7373        """ 
    74         Instructs my broker to register the classes specified by the argument(s). 
    75  
    76         The classes will be registered for B{all} jobs, and are specified by their 
    77         string representations:: 
     74        Instructs my broker to register the classes specified by the 
     75        argument(s). 
     76 
     77        The classes will be registered for B{all} jobs, and are specified by 
     78        their string representations:: 
    7879         
    7980            <package(s).module.class> 
    8081         
    8182        """ 
     83        modules = [] 
    8284        for stringRep in args: 
    8385            # Load the class for the string representation 
    84             cls = namedObject(stringRep) 
     86            cls = reflect.namedObject(stringRep) 
    8587            # Register instances of the class, including its type and module 
    8688            pb.setUnjellyableForClass(stringRep, cls) 
    87  
     89            if cls.__module__ not in modules: 
     90                modules.append(cls.__module__) 
     91        # Try to reload the modules for the classes in case they've changed 
     92        # since the last run 
     93        for module in modules: 
     94            try: 
     95                reload(reflect.namedModule(module)) 
     96            except: 
     97                pass 
     98     
    8899    def remote_newJob(self, jobID, jobCode): 
    89100        """ 
     
    136147            % (callName, jobID))) 
    137148 
     149    def remote_forgetJob(self, jobID): 
     150        """ 
     151        Call this with the I{jobID} of a job that is done and I will forget its 
     152        namespace, thus freeing up memory. 
     153        """ 
     154        if jobID in self.jobs: 
     155            del self.jobs[jobID] 
     156     
    138157    def remote_exit(self, stopReactor=False): 
    139158        """ 
     
    414433        def jobRan(result): 
    415434            status, result = result 
    416             if status: 
    417                 del self.callsPending[jobID][d] 
    418                 d.callback(result) 
     435            if status and jobID in self.callsPending: 
     436                if d in self.callsPending[jobID]: 
     437                    del self.callsPending[jobID][d] 
     438                    d.callback(result) 
    419439            else: 
    420440                log("Error running job %d:\n%s", jobID, result) 
     
    453473        self.updates.pop(jobID, None) 
    454474        self.callsPending.pop(jobID, None) 
     475        dList = [ 
     476            worker.remoteCaller('forgetJob', jobID) 
     477            for worker in self.queue.workers()] 
     478        return defer.DeferredList(dList)