Skip to content

Commit

Permalink
Remove unused FF_HOOK_EVENTS (#1026)
Browse files Browse the repository at this point in the history
- Removes `FF_HOOK_EVENTS` from the service configuration.
- Changes `signals.py` classes for both Chains and Safe Apps, so these classes don't use the `/v2/flush/` endpoint anymore. (And modifies their test counterparts accordingly)
- Removes the `flush` function from the Safe Client Gateway client implementation.
  • Loading branch information
hectorgomezv authored Jan 17, 2024
1 parent ef68413 commit 5c86839
Show file tree
Hide file tree
Showing 8 changed files with 776 additions and 1,412 deletions.
51 changes: 13 additions & 38 deletions src/chains/signals.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import logging
from typing import Any

from django.conf import settings
from django.db.models.signals import m2m_changed, post_delete, post_save, pre_delete
from django.dispatch import receiver

from clients.safe_client_gateway import HookEvent, flush, hook_event
from clients.safe_client_gateway import HookEvent, hook_event

from .models import Chain, Feature, GasPrice, Wallet

Expand All @@ -16,22 +15,14 @@
@receiver(post_delete, sender=Chain)
def on_chain_update(sender: Chain, instance: Chain, **kwargs: Any) -> None:
logger.info("Chain update. Triggering CGW webhook")
if settings.FF_HOOK_EVENTS:
hook_event(HookEvent(type=HookEvent.Type.CHAIN_UPDATE, chain_id=instance.id))
else:
flush()
hook_event(HookEvent(type=HookEvent.Type.CHAIN_UPDATE, chain_id=instance.id))


@receiver(post_save, sender=GasPrice)
@receiver(post_delete, sender=GasPrice)
def on_gas_price_update(sender: GasPrice, instance: GasPrice, **kwargs: Any) -> None:
logger.info("GasPrice update. Triggering CGW webhook")
if settings.FF_HOOK_EVENTS:
hook_event(
HookEvent(type=HookEvent.Type.CHAIN_UPDATE, chain_id=instance.chain.id)
)
else:
flush()
hook_event(HookEvent(type=HookEvent.Type.CHAIN_UPDATE, chain_id=instance.chain.id))


# pre_delete is used because on pre_delete the model still has chains
Expand All @@ -40,12 +31,9 @@ def on_gas_price_update(sender: GasPrice, instance: GasPrice, **kwargs: Any) ->
@receiver(pre_delete, sender=Feature)
def on_feature_changed(sender: Feature, instance: Feature, **kwargs: Any) -> None:
logger.info("Feature update. Triggering CGW webhook")
if settings.FF_HOOK_EVENTS:
# A Feature change affects all the chains that have this feature
for chain in instance.chains.all():
hook_event(HookEvent(type=HookEvent.Type.CHAIN_UPDATE, chain_id=chain.id))
else:
flush()
# A Feature change affects all the chains that have this feature
for chain in instance.chains.all():
hook_event(HookEvent(type=HookEvent.Type.CHAIN_UPDATE, chain_id=chain.id))


@receiver(m2m_changed, sender=Feature.chains.through)
Expand All @@ -54,13 +42,8 @@ def on_feature_chains_changed(
) -> None:
logger.info("FeatureChains update. Triggering CGW webhook")
if action == "post_add" or action == "post_remove":
if settings.FF_HOOK_EVENTS:
for chain_id in pk_set:
hook_event(
HookEvent(type=HookEvent.Type.CHAIN_UPDATE, chain_id=chain_id)
)
else:
flush()
for chain_id in pk_set:
hook_event(HookEvent(type=HookEvent.Type.CHAIN_UPDATE, chain_id=chain_id))


# pre_delete is used because on pre_delete the model still has chains
Expand All @@ -69,12 +52,9 @@ def on_feature_chains_changed(
@receiver(pre_delete, sender=Wallet)
def on_wallet_changed(sender: Wallet, instance: Wallet, **kwargs: Any) -> None:
logger.info("Wallet update. Triggering CGW webhook")
if settings.FF_HOOK_EVENTS:
# A Wallet change affects all the chains that have this wallet
for chain in instance.chains.all():
hook_event(HookEvent(type=HookEvent.Type.CHAIN_UPDATE, chain_id=chain.id))
else:
flush()
# A Wallet change affects all the chains that have this wallet
for chain in instance.chains.all():
hook_event(HookEvent(type=HookEvent.Type.CHAIN_UPDATE, chain_id=chain.id))


@receiver(m2m_changed, sender=Wallet.chains.through)
Expand All @@ -83,10 +63,5 @@ def on_wallet_chains_changed(
) -> None:
logger.info("WalletChains update. Triggering CGW webhook")
if action == "post_add" or action == "post_remove":
if settings.FF_HOOK_EVENTS:
for chain_id in pk_set:
hook_event(
HookEvent(type=HookEvent.Type.CHAIN_UPDATE, chain_id=chain_id)
)
else:
flush()
for chain_id in pk_set:
hook_event(HookEvent(type=HookEvent.Type.CHAIN_UPDATE, chain_id=chain_id))
Loading

0 comments on commit 5c86839

Please sign in to comment.