Exemple #1
0
    def startServer(self):
        beanstalk = beanstalkc.Connection(host=gBeanstalkdServerHost, port=gBeanstalkdServerPort)
        #beanstalk.use(self.fileListTubeName)
        beanstalk.watch(self.fileListTubeName)
        beanstalk.ignore('default')
        while True:
            job = beanstalk.reserve()
            print "got job", job.body
            item = json.loads(job.body)
            if not os.path.exists(item["fullPath"]):
                print 'Path not exists'
                job.delete()
                continue

            self.addedList.append([job, item])
            if self.processJob(job, item):
                #If processJob returns True, job processing completed, clean self.addedList
                for addedJob, addedItem in self.addedList:
                    #pprint(beanstalk.stats_tube(self.fileListTubeName))
                    #print self.addedList
                    #print dir(addedJob)
                    #print addedJob.state()
                    try:
                        addedJob.delete()
                    except:
                        pass
                    print "removed addedItem from tube", addedItem
                self.addedList = []
Exemple #2
0
 def startServer(self):
     print self.__class__, self.tubeName
     self.register_cmd_tube()
     self.watchTube()
     #!!!Not working. Kick all items to active when start, as we bury them in the previous processing
     #kickedItemNum = beanstalk.kick(gMaxMonitoringItems)
     #print kickedItemNum
     while True:
         try:
             job = self.beanstalk.reserve()
         except:
             self.stop()
             return
         print "got job", job.body
         item = json.loads(job.body)
         if self.is_term_signal(item):
             self.stop()
             job.delete()
             return
             #continue
         print item
         try:
             if self.processItem(job, item):
                 #If return True, the job was processed but should be still in queue, release and delay it
                 job.release(priority = beanstalkc.DEFAULT_PRIORITY, delay = gItemDelayTime)
             ########################################
             # !!! Otherwise, sub class must delete the item. Or timeout will occur
             ########################################
         except Exception,e:
             print >>sys.stderr, "processing task error, ignore the following"
             traceback.print_exc()
             #raise e
             job.delete()
Exemple #3
0
def main():
    d = testDbSys.testDbSys()
    res = submitter.packagePathRecurse("d:/tmp", d)
    s = json.dumps(res, sort_keys=True, indent=4)
    jsonRes = u"\n".join([l.rstrip() for l in s.splitlines()])
    print jsonRes
    f = open("d:/tmp/dirJson.json", "w")
    f.write(jsonRes)
    f.close()
    r = json.loads(jsonRes)
    print r
Exemple #4
0
 def startServer(self):
     beanstalk = beanstalkc.Connection(host=gBeanstalkdServerHost, port=gBeanstalkdServerPort)
     beanstalk.watch(self.inputTubeName)
     beanstalk.ignore('default')
     #!!!Not working. Kick all items to active when start, as we bury them in the previous processing
     #kickedItemNum = beanstalk.kick(gMaxMonitoringItems)
     #print kickedItemNum
     while True:
         job = beanstalk.reserve()
         print "got job", job.body
         item = json.loads(job.body)
         print item
         if item.has_key('command'):
             self.processCmd(job, item)
         else:
             self.processItem(job, item)
 def startServer(self):
     print self.__class__, self.tubeName
     self.watchTube()
     #!!!Not working. Kick all items to active when start, as we bury them in the previous processing
     #kickedItemNum = beanstalk.kick(gMaxMonitoringItems)
     #print kickedItemNum
     while True:
         try:
             job = self.beanstalk.reserve()
         except:
             self.stop()
             return
         print "got job", job.body
         item = json.loads(job.body)
         if item.has_key("cmd"):
             if item["cmd"] == "registration":
                 if item.has_key("pid"):
                     if item.has_key("cmd_tube_name"):
                         if self.taskid_cmd_tube_name_dict.has_key(item["pid"]):
                             if self.taskid_cmd_tube_name_dict[item["pid"]] != item["cmd_tube_name"]:
                                 print "registered but not the same"
                             else:
                                 print "already registered, same tube name"
                         else:
                             self.taskid_cmd_tube_name_dict[item["pid"]] = item["cmd_tube_name"]
                     else:
                         print "not a correct registration, no cmd_tube_name"
                 else:
                     print "not a correct registration, no pid"
             elif item["cmd"] == "stop":
                 if item.has_key("pid"):
                     if self.taskid_cmd_tube_name_dict.has_key(item["pid"]):
                         self.put_item({"cmd":"stop"}, self.taskid_cmd_tube_name_dict[item["pid"]])
                     else:
                         print "no tube name registered for pid", item["pid"], self.taskid_cmd_tube_name_dict
                 else:
                     print "not a valid cmd", item
         
         job.delete()
Exemple #6
0
 def startServer(self):
     beanstalk = beanstalkc.Connection(host=gBeanstalkdServerHost, port=gBeanstalkdServerPort)
     #beanstalk.use(gMonitorServiceTubeName)
     beanstalk.watch(gMonitorServiceTubeName)
     #beanstalk.ignore(gMonitorServiceTubeName)
     beanstalk.ignore('default')
     #!!!Not working. Kick all items to active when start, as we bury them in the previous processing
     #kickedItemNum = beanstalk.kick(gMaxMonitoringItems)
     #print kickedItemNum
     while True:
         job = beanstalk.reserve()
         print "got job", job.body
         item = json.loads(job.body)
         fullPath = transform.transformDirToInternal(item["fullPath"])
         if self.notifyThreads.has_key(fullPath):
             #Notifier already added.
             continue
         if not os.path.exists(item["fullPath"]) or self.notifyThreads.has_key(fullPath):
             job.delete()
             continue
         t = changeNotifyForBeanstalkd(fullPath)
         self.notifyThreads[fullPath] = t
         t.start()