Exemplo n.º 1
0
    def run(cls):
        while cls._process_enabled:
            # Retrieve one action from the queue
            try:
                action = ActionQueue.get()
            except ActionQueue.DoesNotExist:
                time.sleep(5)
                continue
            except Exception, ex:
                log.warn('Unable to retrieve action from queue - %s', ex, exc_info=True)
                time.sleep(5)
                continue

            log.debug('Retrieved %r action from queue', action.event)

            try:
                performed = cls.process(action)

                cls.resolve(action, performed)

                log.debug('Action %r sent, moved action to history', action.event)
            except Exception, ex:
                log.warn('Unable to process action %%r - %s' % ex.message, action.event, exc_info=True, extra={
                    'event': {
                        'module': __name__,
                        'name': 'run.process_exception',
                        'key': ex.message
                    }
                })
Exemplo n.º 2
0
    def run(cls):
        while cls._process_enabled:
            # Retrieve one action from the queue
            try:
                action = ActionQueue.get()
            except ActionQueue.DoesNotExist:
                time.sleep(5)
                continue
            except DisabledError:
                break
            except Exception as ex:
                log.warn('Unable to retrieve action from queue - %s', ex, exc_info=True)
                time.sleep(5)
                continue

            log.debug('Retrieved %r action from queue', action.event)

            try:
                performed = cls.process(action)

                cls.resolve(action, performed)

                log.debug('Action %r sent, moved action to history', action.event)
            except Exception as ex:
                log.warn('Unable to process action %%r - %s' % ex.message, action.event, exc_info=True, extra={
                    'event': {
                        'module': __name__,
                        'name': 'run.process_exception',
                        'key': ex.message
                    }
                })
            finally:
                time.sleep(5)
Exemplo n.º 3
0
    def queue(cls, event, request, session=None, account=None):
        if event is None:
            return None

        obj = None

        if request is not None:
            request = json.dumps(request)

        # Retrieve `account_id` for action
        account_id = None

        if session:
            try:
                account_id = session.account_id
            except KeyError:
                account_id = None

        if account_id is None and account:
            account_id = account.id

        if account_id is None:
            log.debug('Unable to find valid account for event %r, session %r',
                      event, session)
            return None

        if not Preferences.get('scrobble.enabled', account_id):
            log.debug('Scrobbler not enabled for account %r', account_id)
            return None

        # Try queue the event
        try:
            obj = ActionQueue.create(account=account_id,
                                     session=session,
                                     progress=session.progress,
                                     part=session.part,
                                     rating_key=session.rating_key,
                                     event=event,
                                     request=request,
                                     queued_at=datetime.utcnow())
            log.debug('Queued %r event for %r', event, session)
        except (apsw.ConstraintError, peewee.IntegrityError) as ex:
            log.info('Event %r has already been queued for session %r: %s',
                     event,
                     session.session_key,
                     ex,
                     exc_info=True)
        except Exception as ex:
            log.warn('Unable to queue event %r for %r: %s',
                     event,
                     session,
                     ex,
                     exc_info=True)

        # Ensure process thread is started
        cls.start()

        return obj
Exemplo n.º 4
0
    def queue(cls, event, request, session=None, account=None):
        if event is None:
            return None

        obj = None

        if request is not None:
            request = json.dumps(request)

        # Retrieve `account_id` for action
        account_id = None

        if session:
            try:
                account_id = session.account_id
            except KeyError:
                account_id = None

        if account_id is None and account:
            account_id = account.id

        if account_id is None:
            log.debug('Unable to find valid account for event %r, session %r', event, session)
            return None

        if not Preferences.get('scrobble.enabled', account_id):
            log.debug('Scrobbler not enabled for account %r', account_id)
            return None

        # Try queue the event
        try:
            obj = ActionQueue.create(
                account=account_id,
                session=session,

                progress=session.progress,

                part=session.part,
                rating_key=session.rating_key,

                event=event,
                request=request,

                queued_at=datetime.utcnow()
            )
            log.debug('Queued %r event for %r', event, session)
        except (apsw.ConstraintError, peewee.IntegrityError) as ex:
            log.info('Event %r has already been queued for session %r: %s', event, session.session_key, ex, exc_info=True)
        except Exception as ex:
            log.warn('Unable to queue event %r for %r: %s', event, session, ex, exc_info=True)

        # Ensure process thread is started
        cls.start()

        return obj
Exemplo n.º 5
0
    def run(cls):
        while cls._process_enabled:
            # Retrieve one action from the queue
            try:
                action = ActionQueue.get()
            except ActionQueue.DoesNotExist:
                time.sleep(5)
                continue
            except Exception, ex:
                log.warn('Unable to retrieve action from queue - %s', ex, exc_info=True)
                time.sleep(5)
                continue

            log.debug('Retrieved %r action from queue', action.event)

            try:
                performed = cls.process(action)

                cls.resolve(action, performed)

                log.debug('Action %r sent, moved action to history', action.event)
            except Exception, ex:
                log.warn('Unable to process action %r - %s', action.event, ex, exc_info=True)
Exemplo n.º 6
0
 def delete(cls, session_id, event):
     ActionQueue.delete().where(
         ActionQueue.session == session_id,
         ActionQueue.event == event
     ).execute()
Exemplo n.º 7
0
 def delete(cls, session_id, event):
     ActionQueue.delete().where(
         ActionQueue.session == session_id,
         ActionQueue.event == event
     ).execute()