Esempio 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)
Esempio 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)
Esempio 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'])
Esempio 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'])
Esempio 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)
Esempio 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"])
Esempio 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)
Esempio 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)
Esempio 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)
Esempio 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)
Esempio 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)
Esempio 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)