-
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.
test subscription for disabled users prototype
- Loading branch information
John Tordoff
committed
Feb 28, 2024
1 parent
794c660
commit ff2b581
Showing
4 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
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 app.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,15 @@ | ||
import os | ||
from celery import Celery | ||
|
||
# Set the default Django settings module for the 'celery' program. | ||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'your_project_name.settings') | ||
|
||
app = Celery(broker='amqp://guest:guest@192.168.168.167:5672//') | ||
app.conf.result_backend = 'rpc://' | ||
|
||
# Using a string here means the worker doesn't have to serialize | ||
# the configuration object to child processes. | ||
app.config_from_object('django.conf:settings', namespace='CELERY') | ||
|
||
# Load task modules from all registered Django apps. | ||
app.autodiscover_tasks() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from app.celery import app | ||
from kombu import Queue, Exchange, Consumer | ||
|
||
|
||
def listen_for_disabled_users(): | ||
exchange = Exchange('test_exchange', type='direct') | ||
queue = Queue(name='test_rpc_queue', exchange=exchange, routing_key='test_rpc_routing_key') | ||
|
||
def process_message(body, message): | ||
print(f"Received message: {body}") | ||
message.ack() | ||
|
||
with app.connection() as connection: | ||
with Consumer(connection, queues=queue, callbacks=[process_message], accept=['json']): | ||
while True: | ||
connection.drain_events() |