예제 #1
0
    def doWork(self):

        # Find all work items with the same push ID and find the highest
        # priority.  Delete matching work items.
        results = (yield Select([self.table.WORK_ID, self.table.PRIORITY,
            self.table.PUSH_ID],
            From=self.table, Where=self.table.PUSH_ID == self.pushID).on(
            self.transaction))

        maxPriority = self.priority

        # If there are other enqueued work items for this push ID, find the
        # highest priority one and use that value
        if results:
            workIDs = []
            for workID, priority, pushID in results:
                if priority > maxPriority:
                    maxPriority = priority
                workIDs.append(workID)

            # Delete the work items we selected
            yield Delete(From=self.table,
                         Where=self.table.WORK_ID.In(
                            Parameter("workIDs", len(workIDs)))
                        ).on(self.transaction, workIDs=workIDs)

        pushDistributor = self.transaction._pushDistributor
        if pushDistributor is not None:
            # Convert the integer priority value back into a constant
            priority = PushPriority.lookupByValue(maxPriority)
            yield pushDistributor.enqueue(self.transaction, self.pushID,
                priority=priority)
예제 #2
0
    def doWork(self):

        # Find all work items with the same push ID and find the highest
        # priority.  Delete matching work items.
        results = (yield Select([self.table.WORK_ID, self.table.JOB_ID, self.table.PUSH_PRIORITY],
            From=self.table, Where=self.table.PUSH_ID == self.pushID).on(
            self.transaction))

        maxPriority = self.pushPriority

        # If there are other enqueued work items for this push ID, find the
        # highest priority one and use that value
        if results:
            workIDs, jobIDs, priorities = zip(*results)
            maxPriority = max(priorities)

            # Delete the work items and jobs we selected - deleting the job will ensure that there are no
            # orphaned" jobs left in the job queue which would otherwise get to run at some later point,
            # though not do anything because there is no related work item.
            yield Delete(
                From=self.table,
                Where=self.table.WORK_ID.In(Parameter("workIDs", len(workIDs)))
            ).on(self.transaction, workIDs=workIDs)
            yield Delete(
                From=JobItem.table, #@UndefinedVariable
                Where=JobItem.jobID.In(Parameter("jobIDs", len(jobIDs))) #@UndefinedVariable
            ).on(self.transaction, jobIDs=jobIDs)

        pushDistributor = self.transaction._pushDistributor
        if pushDistributor is not None:
            # Convert the integer priority value back into a constant
            priority = PushPriority.lookupByValue(maxPriority)
            yield pushDistributor.enqueue(self.transaction, self.pushID, priority=priority)
예제 #3
0
 def enqueueFromWorker(self, id, dataChangedTimestamp=None,
     priority=PushPriority.high.value):
     if dataChangedTimestamp is None:
         dataChangedTimestamp = int(time.time())
     self.master.enqueue(None, id, dataChangedTimestamp=dataChangedTimestamp,
         priority=PushPriority.lookupByValue(priority))
     return {"status" : "OK"}
예제 #4
0
    def doWork(self):

        # Find all work items with the same push ID and find the highest
        # priority.  Delete matching work items.
        results = (yield Select(
            [self.table.WORK_ID, self.table.JOB_ID, self.table.PUSH_PRIORITY],
            From=self.table,
            Where=self.table.PUSH_ID == self.pushID).on(self.transaction))

        maxPriority = self.pushPriority

        # If there are other enqueued work items for this push ID, find the
        # highest priority one and use that value
        if results:
            workIDs, jobIDs, priorities = zip(*results)
            maxPriority = max(priorities)

            # Delete the work items and jobs we selected - deleting the job will ensure that there are no
            # orphaned" jobs left in the job queue which would otherwise get to run at some later point,
            # though not do anything because there is no related work item.
            yield Delete(From=self.table,
                         Where=self.table.WORK_ID.In(
                             Parameter("workIDs",
                                       len(workIDs)))).on(self.transaction,
                                                          workIDs=workIDs)
            yield Delete(
                From=JobItem.table,  #@UndefinedVariable
                Where=JobItem.jobID.In(Parameter(
                    "jobIDs", len(jobIDs)))  #@UndefinedVariable
            ).on(self.transaction, jobIDs=jobIDs)

        pushDistributor = self.transaction._pushDistributor
        if pushDistributor is not None:
            # Convert the integer priority value back into a constant
            priority = PushPriority.lookupByValue(maxPriority)
            yield pushDistributor.enqueue(self.transaction,
                                          self.pushID,
                                          priority=priority)
예제 #5
0
 def notificationForID(self, id, dataChangedTimestamp, priority):
     yield self.callback(id, dataChangedTimestamp,
                         PushPriority.lookupByValue(priority))
     returnValue({"status": "OK"})
예제 #6
0
 def notificationForID(self, id, dataChangedTimestamp, priority):
     yield self.callback(id, dataChangedTimestamp, PushPriority.lookupByValue(priority))
     returnValue({"status" : "OK"})