Exemplo n.º 1
0
    def get(self, queue, claim_id, project):
        if project is None:
            project = ''

        cid = utils.cid_decode(claim_id)
        if cid is None:
            raise exceptions.ClaimDoesNotExist(claim_id, queue, project)

        with self.driver('deferred'):
            try:
                id, ttl, age = self.driver.get(
                    '''
                    select C.id, C.ttl, julianday() * 86400.0 - C.created
                      from Queues as Q join Claims as C
                        on Q.id = C.qid
                     where C.ttl > julianday() * 86400.0 - C.created
                       and C.id = ? and project = ? and name = ?
                ''', cid, project, queue)

                return ({
                    'id': claim_id,
                    'ttl': ttl,
                    'age': int(age),
                }, self.__get(id))

            except utils.NoResult:
                raise exceptions.ClaimDoesNotExist(claim_id, queue, project)
Exemplo n.º 2
0
    def get(self, queue, claim_id, project):
        if project is None:
            project = ''

        with self.driver('deferred'):
            try:
                id, ttl, age = self.driver.get('''
                    select C.id, C.ttl, julianday() * 86400.0 - C.created
                      from Queues as Q join Claims as C
                        on Q.id = C.qid
                     where C.ttl > julianday() * 86400.0 - C.created
                       and C.id = ? and project = ? and name = ?
                ''', utils.cid_decode(claim_id), project, queue)

                return (
                    {
                        'id': claim_id,
                        'ttl': ttl,
                        'age': int(age),
                    },
                    self.__get(id)
                )

            except (utils.NoResult, exceptions.MalformedID()):
                raise exceptions.ClaimDoesNotExist(claim_id, queue, project)
Exemplo n.º 3
0
    def update(self, queue, claim_id, metadata, project):
        if project is None:
            project = ''

        try:
            id = utils.cid_decode(claim_id)
        except exceptions.MalformedID:
            raise exceptions.ClaimDoesNotExist(claim_id, queue, project)

        with self.driver('deferred'):

            # still delay the cleanup here
            self.driver.run('''
                update Claims
                   set created = julianday() * 86400.0,
                       ttl = ?
                 where ttl > julianday() * 86400.0 - created
                   and id = ?
                   and qid = (select id from Queues
                               where project = ? and name = ?)
            ''', metadata['ttl'], id, project, queue)

            if not self.driver.affected:
                raise exceptions.ClaimDoesNotExist(claim_id,
                                                   queue,
                                                   project)

            self.__update_claimed(id, metadata['ttl'])
Exemplo n.º 4
0
    def update(self, queue, claim_id, metadata, project):
        if project is None:
            project = ''

        id = utils.cid_decode(claim_id)
        if id is None:
            raise exceptions.ClaimDoesNotExist(claim_id, queue, project)

        with self.driver('deferred'):

            # still delay the cleanup here
            self.driver.run(
                '''
                update Claims
                   set created = julianday() * 86400.0,
                       ttl = ?
                 where ttl > julianday() * 86400.0 - created
                   and id = ?
                   and qid = (select id from Queues
                               where project = ? and name = ?)
            ''', metadata['ttl'], id, project, queue)

            if not self.driver.affected:
                raise exceptions.ClaimDoesNotExist(claim_id, queue, project)

            self.__update_claimed(id, metadata['ttl'])
Exemplo n.º 5
0
    def get(self, queue, claim_id, project):
        if project is None:
            project = ""

        cid = utils.cid_decode(claim_id)
        if cid is None:
            raise exceptions.ClaimDoesNotExist(claim_id, queue, project)

        with self.driver("deferred"):
            try:
                id, ttl, age = self.driver.get(
                    """
                    select C.id, C.ttl, julianday() * 86400.0 - C.created
                      from Queues as Q join Claims as C
                        on Q.id = C.qid
                     where C.ttl > julianday() * 86400.0 - C.created
                       and C.id = ? and project = ? and name = ?
                """,
                    cid,
                    project,
                    queue,
                )

                return ({"id": claim_id, "ttl": ttl, "age": int(age)}, self.__get(id))

            except utils.NoResult:
                raise exceptions.ClaimDoesNotExist(claim_id, queue, project)
Exemplo n.º 6
0
    def update(self, queue, claim_id, metadata, project):
        if project is None:
            project = ""

        id = utils.cid_decode(claim_id)
        if id is None:
            raise exceptions.ClaimDoesNotExist(claim_id, queue, project)

        with self.driver("deferred"):

            # still delay the cleanup here
            self.driver.run(
                """
                update Claims
                   set created = julianday() * 86400.0,
                       ttl = ?
                 where ttl > julianday() * 86400.0 - created
                   and id = ?
                   and qid = (select id from Queues
                               where project = ? and name = ?)
            """,
                metadata["ttl"],
                id,
                project,
                queue,
            )

            if not self.driver.affected:
                raise exceptions.ClaimDoesNotExist(claim_id, queue, project)

            self.__update_claimed(id, metadata["ttl"])
Exemplo n.º 7
0
    def __delete_claimed(self, id, claim):
        # Precondition: id exists in a specific queue
        self.driver.run('''
            delete from Messages
             where id = ?
               and id in (select msgid
                            from Claims join Locked
                              on id = cid
                           where ttl > julianday() * 86400.0 - created
                             and id = ?)
        ''', id, utils.cid_decode(claim))

        if not self.driver.affected:
            raise exceptions.ClaimNotPermitted(utils.msgid_encode(id), claim)
Exemplo n.º 8
0
    def delete(self, queue, claim_id, project):
        if project is None:
            project = ''

        cid = utils.cid_decode(claim_id)
        if cid is None:
            return

        self.driver.run('''
            delete from Claims
             where id = ?
               and qid = (select id from Queues
                           where project = ? and name = ?)
        ''', cid, project, queue)
Exemplo n.º 9
0
    def delete(self, queue, claim_id, project):
        if project is None:
            project = ''

        cid = utils.cid_decode(claim_id)
        if cid is None:
            return

        self.driver.run('''
            delete from Claims
             where id = ?
               and qid = (select id from Queues
                           where project = ? and name = ?)
        ''', cid, project, queue)
Exemplo n.º 10
0
    def delete(self, queue, claim_id, project):
        if project is None:
            project = ''

        try:
            cid = utils.cid_decode(claim_id)
        except exceptions.MalformedID:
            return

        self.driver.run('''
            delete from Claims
             where id = ?
               and qid = (select id from Queues
                           where project = ? and name = ?)
        ''', cid, project, queue)
Exemplo n.º 11
0
    def __delete_claimed(self, id, claim):
        # Precondition: id exists in a specific queue
        cid = utils.cid_decode(claim)
        if cid is None:
            return

        self.driver.run('''
            delete from Messages
             where id = ?
               and id in (select msgid
                            from Claims join Locked
                              on id = cid
                           where ttl > julianday() * 86400.0 - created
                             and id = ?)
        ''', id, cid)

        if not self.driver.affected:
            raise exceptions.MessageIsClaimedBy(id, claim)
Exemplo n.º 12
0
    def __delete_claimed(self, id, claim):
        # Precondition: id exists in a specific queue
        cid = utils.cid_decode(claim)
        if cid is None:
            return

        self.driver.run(
            '''
            delete from Messages
             where id = ?
               and id in (select msgid
                            from Claims join Locked
                              on id = cid
                           where ttl > julianday() * 86400.0 - created
                             and id = ?)
        ''', id, cid)

        if not self.driver.affected:
            raise exceptions.MessageIsClaimedBy(id, claim)