-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Setup rabbit listener for disabled users
- Loading branch information
John Tordoff
committed
Feb 29, 2024
1 parent
794c660
commit a6a0dbb
Showing
7 changed files
with
55 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,15 @@ | ||
import threading | ||
|
||
from django.apps import AppConfig | ||
|
||
from addon_service.tasks import listen_for_osf_signals | ||
|
||
|
||
class AddonServiceConfig(AppConfig): | ||
default_auto_field = "django.db.models.BigAutoField" | ||
name = "addon_service" | ||
|
||
def ready(self): | ||
thread = threading.Thread(target=listen_for_osf_signals) | ||
thread.daemon = True | ||
thread.start() |
8 changes: 8 additions & 0 deletions
8
addon_service/management/commands/test_disabled_accounts_subscription.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from django.core.management.base import BaseCommand | ||
from addon_service.tasks import listen_for_disabled_users | ||
|
||
class Command(BaseCommand): | ||
help = 'Subscribes to an RPC exchange and listens for messages.' | ||
|
||
def handle(self, *args, **options): | ||
listen_for_disabled_users() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from celery import Celery | ||
|
||
osf_listener = Celery(broker='amqp://guest:guest@192.168.168.167:5672//') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from addon_service.osf_listener import osf_listener | ||
from kombu import Queue, Exchange, Consumer | ||
OSF_DEFAULT_QUEUE = 'celery' | ||
from addon_service.models import UserReference | ||
|
||
|
||
def process_disabled_user_message(body, message): | ||
print(f"Received message: {body}") | ||
user_uri = body['user_uri'] | ||
UserReference.objects.get(user_uri=user_uri).delete() | ||
message.ack() | ||
|
||
|
||
def listen_for_osf_signals(): | ||
with osf_listener.connection() as connection: | ||
with Consumer( | ||
connection, | ||
queues=Queue( | ||
name=OSF_DEFAULT_QUEUE, # TODO: Any plans here? | ||
exchange=Exchange(OSF_DEFAULT_QUEUE), # TODO: Define exchange(s) for merged/disabled | ||
), | ||
callbacks=[ # TODO: Multiple callbacks or multiple queues? | ||
process_disabled_user_message | ||
], | ||
accept=['json'] | ||
): | ||
while True: | ||
connection.drain_events() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters