Ejemplo n.º 1
0
    def test(self) -> None:
        creator = SubscriptionCreator(self.dataset)
        subscription = LegacySubscriptionData(
            project_id=1,
            conditions=[],
            aggregations=[["count()", "", "count"]],
            time_window=timedelta(minutes=10),
            resolution=timedelta(minutes=1),
        )
        identifier = creator.create(subscription, Timer("test"))
        assert (
            cast(
                List[Tuple[UUID, SubscriptionData]],
                RedisSubscriptionDataStore(
                    redis_client, self.dataset, identifier.partition,
                ).all(),
            )[0][1]
            == subscription
        )

        SubscriptionDeleter(self.dataset, identifier.partition).delete(identifier.uuid)
        assert (
            RedisSubscriptionDataStore(
                redis_client, self.dataset, identifier.partition,
            ).all()
            == []
        )
Ejemplo n.º 2
0
    def test(self) -> None:
        creator = SubscriptionCreator(self.dataset, EntityKey.EVENTS)
        subscription = SubscriptionData(
            project_id=1,
            query="MATCH (events) SELECT count() AS count",
            time_window_sec=10 * 60,
            resolution_sec=60,
            entity_subscription=create_entity_subscription(),
        )
        identifier = creator.create(subscription, Timer("test"))
        assert (cast(
            List[Tuple[UUID, SubscriptionData]],
            RedisSubscriptionDataStore(
                redis_client,
                self.entity_key,
                identifier.partition,
            ).all(),
        )[0][1] == subscription)

        SubscriptionDeleter(self.entity_key,
                            identifier.partition).delete(identifier.uuid)
        assert (RedisSubscriptionDataStore(
            redis_client,
            self.entity_key,
            identifier.partition,
        ).all() == [])
Ejemplo n.º 3
0
def delete_subscription(
    *, dataset: Dataset, partition: int, key: str, entity: Entity
) -> RespTuple:
    if entity not in dataset.get_all_entities():
        raise InvalidSubscriptionError(
            "Invalid subscription dataset and entity combination"
        )
    entity_key = ENTITY_NAME_LOOKUP[entity]
    SubscriptionDeleter(entity_key, PartitionId(partition)).delete(UUID(key))
    metrics.increment("subscription_deleted", tags={"entity": entity_key.value})

    return "ok", 202, {"Content-Type": "text/plain"}
Ejemplo n.º 4
0
    def test(self):
        creator = SubscriptionCreator(self.dataset)
        subscription = SubscriptionData(
            project_id=1,
            conditions=[],
            aggregations=[["count()", "", "count"]],
            time_window=timedelta(minutes=10),
            resolution=timedelta(minutes=1),
        )
        identifier = creator.create(subscription, Timer("test"))
        RedisSubscriptionDataStore(
            redis_client, self.dataset, identifier.partition,
        ).all()[0][1] == subscription

        SubscriptionDeleter(self.dataset, identifier.partition).delete(identifier.uuid)
        RedisSubscriptionDataStore(
            redis_client, self.dataset, identifier.partition,
        ).all() == []
Ejemplo n.º 5
0
def delete_subscription(*, dataset: Dataset, partition: int, key: str) -> RespTuple:
    SubscriptionDeleter(dataset, PartitionId(partition)).delete(UUID(key))
    return "ok", 202, {"Content-Type": "text/plain"}
Ejemplo n.º 6
0
def delete_subscription(*, dataset: Dataset, partition: int, key: str):
    ensure_not_internal(dataset)
    SubscriptionDeleter(dataset, PartitionId(partition)).delete(UUID(key))
    return "ok", 202, {"Content-Type": "text/plain"}