Commit c760f3f5 authored by Sofia Papagiannaki's avatar Sofia Papagiannaki
Browse files

move aquarium listener in endpoints

parent 5d3f717e
......@@ -106,7 +106,7 @@ showuser Show user info
To update user credibility from the billing system (Aquarium), enable the queue, install snf-pithos-tools and use ``pithos-dispatcher``::
pithos-dispatcher --exchange=aquarium --callback=astakos.im.queue.listener.on_creditevent
pithos-dispatcher --exchange=aquarium --callback=astakos.im.endpoints.aquarium.consumer.on_creditevent
Load groups:
------------
......
......@@ -33,14 +33,22 @@
import logging
from astakos.im.functions import set_user_credibility
logging.basicConfig(format='%(asctime)s [%(levelname)s] %(name)s %(message)s',
datefmt='%Y-%m-%d %H:%M:%S'
)
logger = logging.getLogger('endpoint.aquarium')
logger = logging.getLogger(__name__)
from astakos.im.models import AstakosUser
def on_creditevent(msg):
"""
Queue handler for updating AstakosUser has_credits
"""
try:
email = msg.get('userid')
has_credits = True if msg.get('status') == 'on' else False
set_user_credibility(email, has_credits)
except Exception, e:
has_credits = msg.get('status') == 'on' or False
user = AstakosUser.objects.get(email=email, is_active=True)
user.has_credits = has_credits
user.save()
except BaseException, e:
logger.exception(e)
\ No newline at end of file
# Copyright 2011-2012 GRNET S.A. All rights reserved.
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
# conditions are met:
#
# 1. Redistributions of source code must retain the above
# copyright notice, this list of conditions and the following
# disclaimer.
#
# 2. Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# The views and conclusions contained in the software and
# documentation are those of the authors and should not be
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.
import json
from time import time
from hashlib import sha1
class UserEvent(object):
def __init__(self, client, user, eventType, details=None):
self.eventVersion = '1'
self.occurredMillis = int(time() * 1000)
self.receivedMillis = self.occurredMillis
self.clientID = client
self.userID = user.email
self.isActive = user.is_active
self.role = 'default'
self.eventType = eventType
self.details = details or {}
hash = sha1()
hash.update(json.dumps([client,
self.userID,
self.isActive,
self.role,
self.eventType,
self.details,
self.occurredMillis
]
)
)
self.id = hash.hexdigest()
def format(self):
return self.__dict__
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment