-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #76 from gwu-libraries/t49-harvest-status-consume
T49 harvest status consume
- Loading branch information
Showing
15 changed files
with
85 additions
and
17 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
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
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
Empty file.
Empty file.
Empty file.
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,19 @@ | ||
from django.conf import settings | ||
from django.core.management.base import BaseCommand | ||
from message_consumer.sfm_ui_consumer import SfmUiConsumer | ||
from sfmutils.consumer import MqConfig, EXCHANGE | ||
|
||
QUEUE = "sfm_ui" | ||
ROUTING_KEYS = ["harvest.status.*", "harvest.status.*.*"] | ||
|
||
|
||
class Command(BaseCommand): | ||
help = 'Starts the message consumer' | ||
|
||
def handle(self, *args, **options): | ||
username = settings.RABBITMQ_USER | ||
password = settings.RABBITMQ_PASSWORD | ||
consumer = SfmUiConsumer(mq_config=MqConfig(settings.RABBITMQ_HOST, | ||
username, password, EXCHANGE, | ||
{QUEUE: ROUTING_KEYS})) | ||
consumer.run() |
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,23 @@ | ||
import logging | ||
from sfmutils.consumer import BaseConsumer | ||
from ui.models import Harvest, SeedSet | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
class SfmUiConsumer(BaseConsumer): | ||
""" | ||
Class for the SFM UI Consumer, which subscribes to | ||
messages from the queue and updates the models as appropriate. | ||
""" | ||
def on_message(self): | ||
m = self.message | ||
m_id = m['id'] | ||
m_status = m['status'] | ||
m_date_started = m['date_started'] | ||
m_date_ended = m['date_ended'] | ||
|
||
ss = SeedSet(id=m_id) | ||
h = Harvest(seed_set=ss, stats=m_status, | ||
date_started=m_date_started, date_ended=m_date_ended) | ||
h.save() |
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
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,28 +1,22 @@ | ||
from django.apps import AppConfig | ||
from django.conf import settings | ||
import pika | ||
import os | ||
from sfmutils.consumer import EXCHANGE | ||
|
||
|
||
class RabbitWorker(AppConfig): | ||
name = 'ui' | ||
verbose_name = "ui" | ||
# Create a connection | ||
credentials = pika.PlainCredentials( | ||
username=os.environ['MQ_ENV_RABBITMQ_DEFAULT_USER'], | ||
password=os.environ['MQ_ENV_RABBITMQ_DEFAULT_PASS']) | ||
username=settings.RABBITMQ_USER, | ||
password=settings.RABBITMQ_PASSWORD) | ||
parameters = pika.ConnectionParameters(host='mq', credentials=credentials) | ||
connection = pika.BlockingConnection(parameters) | ||
# create channel | ||
channel = connection.channel() | ||
|
||
def ready(self): | ||
# Declare sfm_exchange | ||
RabbitWorker.channel.exchange_declare(exchange="sfm_exchange", | ||
RabbitWorker.channel.exchange_declare(exchange=EXCHANGE, | ||
type="topic", durable=True) | ||
# Declare harvester queue | ||
RabbitWorker.channel.queue_declare(queue="sfm_exchange", durable=True) | ||
# Bind | ||
RabbitWorker.channel.queue_bind(exchange="sfm_exchange", | ||
queue="sfm_exchange", | ||
routing_key="sfm_exchange") | ||
pass # startup code here |
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