Ejemplo n.º 1
0
class GenericModelSchema(ma.ModelSchema):
    class Meta:
        model = GenericModel

    uuid = fields.String(missing=uuid_factory("GENERIC"))
    created_at = fields.DateTime()
    updated_at = fields.DateTime()

    # Correlation IDs:
    user_id = fields.Integer(required=True, load_only=True)
Ejemplo n.º 2
0
class GenericModel(IBase):
    __tablename__ = "generic_models"
    id = Column(BigInteger(), primary_key=True)

    uuid = Column(String(),
                  unique=True,
                  default=lambda: uuid_factory("GENERIC"))
    name = Column(String(), nullable=False)
    created_at = Column(DateTime,
                        nullable=False,
                        default=lambda: datetime.datetime.now())
    updated_at = Column(DateTime,
                        nullable=False,
                        default=lambda: datetime.datetime.now())

    # Correlation ID
    user_id = Column(BigInteger())
Ejemplo n.º 3
0
def start_redis_consumer(consumer_group_config,
                         registered_handlers,
                         start_from=">"):
    broker = RedisStream.get_broker()
    streams_dict = {s: start_from for s in consumer_group_config["streams"]}
    maybe_create_consumer_groups(broker, consumer_group_config)

    group_name = consumer_group_config["name"]
    consumer_name = uuid_factory(group_name + "-consumer")()
    batch_size = consumer_group_config["batch_size"]

    while True:
        item = broker.xreadgroup(group_name,
                                 consumer_name,
                                 streams_dict,
                                 count=batch_size,
                                 block=1000)
        if item:
            stream_name, event_ids, events = decode_item(
                item[0])  # TODO: Handle batchsize > 1
            for event_id, event in zip(event_ids, events):
                digest_event(stream_name, event, event_id, registered_handlers)
                broker.xack(stream_name, group_name, event_id)
Ejemplo n.º 4
0
 def __post_init__(self):
     self.timestamp = self.timestamp or time.time()
     # pylint: disable=no-member
     self.uuid = self.uuid or uuid_factory(self.prefix or "EVENT")()
     self.event_type = self.event_type or EventType.GENERIC_EVENT
Ejemplo n.º 5
0
def make_consumer_name(uuid, group_name):
    if uuid:
        return group_name + "_consumer-" + str(uuid)
    return uuid_factory(group_name + "-consumer")()
Ejemplo n.º 6
0
 def __post_init__(self):
     self.timestamp = self.timestamp or time.time()
     # pylint: disable=no-member
     self.uuid = self.uuid or uuid_factory(self.prefix or "COMMAND")()
     self.event_type = self.event_type or CommandType.GENERIC_COMMAND
Ejemplo n.º 7
0
 def __post_init__(self) -> None:
     self.timestamp = self.timestamp or time.time()
     self.uuid = self.uuid or uuid_factory(self.prefix or "EVENT")()
     self.event_type = self.event_type or EventType.GENERIC_EVENT