def bulk_get(self, queue, message_ids, project): if project is None: project = '' message_ids = [ id for id in map(utils.msgid_decode, message_ids) if id is not None ] statement = sa.sql.select([ tables.Messages.c.id, tables.Messages.c.body, tables.Messages.c.ttl, tables.Messages.c.created, tables.Messages.c.cid ]) and_stmt = [tables.Messages.c.id.in_(message_ids)] and_stmt.extend(self._and_stmt_with_ttl(queue, project)) j = sa.join(tables.Messages, tables.Queues, tables.Messages.c.qid == tables.Queues.c.id) statement = statement.select_from(j).where(sa.and_(*and_stmt)) now = timeutils.utcnow_ts() records = self.driver.run(statement) for id, body, ttl, created, cid in records: yield { 'id': utils.msgid_encode(int(id)), 'ttl': ttl, 'age': now - calendar.timegm(created.timetuple()), 'body': utils.json_decode(body), 'claim_id': utils.cid_encode(cid) if cid else None, }
def bulk_get(self, queue, message_ids, project): if project is None: project = '' message_ids = [id for id in map(utils.msgid_decode, message_ids) if id is not None] statement = sa.sql.select([tables.Messages.c.id, tables.Messages.c.body, tables.Messages.c.ttl, tables.Messages.c.created, tables.Messages.c.cid]) and_stmt = [tables.Messages.c.id.in_(message_ids)] and_stmt.extend(self._and_stmt_with_ttl(queue, project)) j = sa.join(tables.Messages, tables.Queues, tables.Messages.c.qid == tables.Queues.c.id) statement = statement.select_from(j).where(sa.and_(*and_stmt)) now = timeutils.utcnow_ts() records = self.driver.run(statement) for id, body, ttl, created, cid in records: yield { 'id': utils.msgid_encode(int(id)), 'ttl': ttl, 'age': now - calendar.timegm(created.timetuple()), 'body': utils.json_decode(body), 'claim_id': utils.cid_encode(cid) if cid else None, }
def _normalize(flavor, detailed=False): ret = {"name": flavor[0], "pool": flavor[2]} if detailed: capabilities = flavor[3] ret["capabilities"] = utils.json_decode(capabilities) if capabilities else {} return ret
def it(): for rec in records: marker_name['next'] = rec[0] yield ({ 'name': rec[0] } if not detailed else { 'name': rec[0], 'metadata': utils.json_decode(rec[1]) })
def get(self, queue, message_id, project): body, ttl, created, cid = self._get(queue, message_id, project) now = timeutils.utcnow_ts() return { 'id': message_id, 'ttl': ttl, 'age': now - calendar.timegm(created.timetuple()), 'body': utils.json_decode(body), 'claim_id': utils.cid_encode(cid) if cid else None, }
def it(): now = timeutils.utcnow_ts() for id, body, ttl, created, cid in records: marker_id['next'] = id yield { 'id': utils.msgid_encode(id), 'ttl': ttl, 'age': now - calendar.timegm(created.timetuple()), 'body': utils.json_decode(body), 'claim_id': utils.cid_encode(cid) if cid else None, }
def _normalize(flavor, detailed=False): ret = { 'name': flavor[0], } if detailed: capabilities = flavor[2] ret['capabilities'] = (utils.json_decode(capabilities) if capabilities else {}) return ret
def get_metadata(self, name, project): if project is None: project = '' try: sel = sa.sql.select([tables.Queues.c.metadata], sa.and_(tables.Queues.c.project == project, tables.Queues.c.name == name)) return utils.json_decode(self.driver.get(sel)[0]) except utils.NoResult: raise errors.QueueDoesNotExist(name, project)
def get_metadata(self, name, project): if project is None: project = '' try: sel = sa.sql.select([tables.Queues.c.metadata], sa.and_( tables.Queues.c.project == project, tables.Queues.c.name == name )) return utils.json_decode(self.driver.get(sel)[0]) except utils.NoResult: raise errors.QueueDoesNotExist(name, project)
def _normalize(flavor, detailed=False): ret = { 'name': flavor[0], 'pool_group': flavor[2], } if detailed: capabilities = flavor[3] ret['capabilities'] = (utils.json_decode(capabilities) if capabilities else {}) return ret
def _normalize(pool, detailed=False): ret = { 'name': pool[0], 'group': pool[1], 'uri': pool[2], 'weight': pool[3], } if detailed: opts = pool[4] ret['options'] = utils.json_decode(opts) if opts else {} return ret
def pop(self, queue_name, limit, project=None): if project is None: project = '' with self.driver.trans() as trans: sel = sa.sql.select([ tables.Messages.c.id, tables.Messages.c.body, tables.Messages.c.ttl, tables.Messages.c.created, tables.Messages.c.cid ]) j = sa.join(tables.Messages, tables.Queues, tables.Messages.c.qid == tables.Queues.c.id) sel = sel.select_from(j) and_clause = self._and_stmt_with_ttl(queue_name, project) and_clause.append(tables.Messages.c.cid == (None)) sel = sel.where(sa.and_(*and_clause)) sel = sel.limit(limit) records = trans.execute(sel) now = timeutils.utcnow_ts() messages = [] message_ids = [] for id, body, ttl, created, cid in records: messages.append({ 'id': utils.msgid_encode(id), 'ttl': ttl, 'age': now - calendar.timegm(created.timetuple()), 'body': utils.json_decode(body), 'claim_id': utils.cid_encode(cid) if cid else None, }) message_ids.append(id) statement = tables.Messages.delete() qid = utils.get_qid(self.driver, queue_name, project) and_stmt = [ tables.Messages.c.id.in_(message_ids), tables.Messages.c.qid == qid ] trans.execute(statement.where(sa.and_(*and_stmt))) return messages
def _normalize(pool, detailed=False): ret = { 'name': pool[0], 'uri': pool[1], 'weight': pool[2], 'flavor': pool[4], } if detailed: opts = pool[3] ret['options'] = utils.json_decode(opts) if opts else {} return ret
def get_metadata(self, name, project): if project is None: project = '' sel = sa.sql.select([tables.Queues.c.metadata], sa.and_(tables.Queues.c.project == project, tables.Queues.c.name == name)) queue = self.driver.run(sel).fetchone() if queue is None: raise errors.QueueDoesNotExist(name, project) return utils.json_decode(queue[0])
def get_metadata(self, name, project): if project is None: project = '' sel = sa.sql.select([tables.Queues.c.metadata], sa.and_( tables.Queues.c.project == project, tables.Queues.c.name == name )) queue = self.driver.run(sel).fetchone() if queue is None: raise errors.QueueDoesNotExist(name, project) return utils.json_decode(queue[0])
def pop(self, queue_name, limit, project=None): if project is None: project = '' with self.driver.trans() as trans: sel = sa.sql.select([tables.Messages.c.id, tables.Messages.c.body, tables.Messages.c.ttl, tables.Messages.c.created, tables.Messages.c.cid]) j = sa.join(tables.Messages, tables.Queues, tables.Messages.c.qid == tables.Queues.c.id) sel = sel.select_from(j) and_clause = self._and_stmt_with_ttl(queue_name, project) and_clause.append(tables.Messages.c.cid == (None)) sel = sel.where(sa.and_(*and_clause)) sel = sel.limit(limit) records = trans.execute(sel) now = timeutils.utcnow_ts() messages = [] message_ids = [] for id, body, ttl, created, cid in records: messages.append({ 'id': utils.msgid_encode(id), 'ttl': ttl, 'age': now - calendar.timegm(created.timetuple()), 'body': utils.json_decode(body), 'claim_id': utils.cid_encode(cid) if cid else None, }) message_ids.append(id) statement = tables.Messages.delete() qid = utils.get_qid(self.driver, queue_name, project) and_stmt = [tables.Messages.c.id.in_(message_ids), tables.Messages.c.qid == qid] trans.execute(statement.where(sa.and_(*and_stmt))) return messages
def __get(self, cid, trans): # NOTE(flaper87): This probably needs to # join on `Claim` to check the claim ttl. sel = sa.sql.select([tables.Messages.c.id, tables.Messages.c.body, tables.Messages.c.ttl, tables.Messages.c.created], sa.and_( tables.Messages.c.ttl > utils.get_age(tables.Messages.c.created), # tables.Messages.c.ttl > # utils.get_age(tables.Claims.c.created), tables.Messages.c.cid == cid)) records = trans.execute(sel) for id, body, ttl, created in records: yield { 'id': utils.msgid_encode(int(id)), 'ttl': ttl, 'age': (timeutils.utcnow() - created).seconds, 'body': utils.json_decode(body), }
def it(): for rec in records: marker_name['next'] = rec[0] yield ({'name': rec[0]} if not detailed else {'name': rec[0], 'metadata': utils.json_decode(rec[1])})