Skip to content

Commit

Permalink
notifications: patron url
Browse files Browse the repository at this point in the history
* Corrects patron url. `RERO_ILS_APP_BASE_URL` is used to construct the patron url. closes rero#802
* Adds comand line interface for notifications. Process of notifications can now be started with `invenio run notifications process`.

Co-Authored-by: Peter Weber <peter.weber@rero.ch>
  • Loading branch information
rerowep committed Jun 8, 2020
1 parent 2d179b7 commit 838b707
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 3 deletions.
15 changes: 13 additions & 2 deletions rero_ils/modules/notifications/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

import ciso8601
from celery import current_app as current_celery_app
from flask import current_app
from flask import current_app, request
from kombu import Exchange, Producer, Queue
from kombu.compat import Consumer
from sqlalchemy.orm.exc import NoResultFound
Expand Down Expand Up @@ -164,7 +164,9 @@ def replace_pids_and_refs(self):
base_url = current_app.config.get('RERO_ILS_APP_BASE_URL')
url_api = '{base_url}/{view_code}/patrons/profile'
profile_url = url_api.format(
base_url=base_url, view_code=view_code)
base_url=base_url,
view_code=view_code
)
data['loan']['profile_url'] = profile_url

return data
Expand Down Expand Up @@ -328,6 +330,15 @@ def process_notifications(cls, verbose=False):

return count

@classmethod
def queue_info(cls):
"""Count of notifications in queue."""
count = None
with current_celery_app.pool.acquire(block=True) as conn:
with conn.channel() as channel:
count = channel.queue_declare()
return count


class NotificationsIndexer(IlsRecordsIndexer):
"""Holdings indexing class."""
Expand Down
47 changes: 47 additions & 0 deletions rero_ils/modules/notifications/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# -*- coding: utf-8 -*-
#
# RERO ILS
# Copyright (C) 2019 RERO
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

"""Click command-line interface for notifications."""

from __future__ import absolute_import, print_function

import click
from flask.cli import with_appcontext

from .tasks import process_notifications


@click.group()
def notifications():
"""Notification management commands."""


@notifications.command('process')
@click.option('--delayed', '-d', is_flag=True, default=False,
help='Run indexing in background.')
@click.option('-v', '--verbose', is_flag=True, default=False,
help='Verbose output')
@with_appcontext
def process(delayed, verbose):
"""Process notifications."""
click.secho('Process notifications:', fg='green')
if delayed:
uid = process_notifications.delay(verbose=verbose)
msg = 'Started task: {uid}'.format(uid=uid)
else:
msg = process_notifications(verbose=verbose)
click.echo(msg)
3 changes: 3 additions & 0 deletions scripts/setup
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,9 @@ eval ${PREFIX} invenio utils runindex --raise-on-error
info_msg "Circulation transactions:"
eval ${PREFIX} invenio fixtures create_loans ${DATA_PATH}/loans.json

# process notifications
eval ${PREFIX} invenio notifications process

# # OAI configuration
info_msg "OAI configuration:"
eval ${PREFIX} invenio oaiharvester initconfig ${DATA_PATH}/oaisources.yml
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ def run(self):
'oaiharvester = rero_ils.modules.ebooks.cli:oaiharvester',
'apiharvester = rero_ils.modules.apiharvester.cli:apiharvester',
'monitoring = rero_ils.modules.monitoring:monitoring',
'scheduler = rero_ils.schedulers:scheduler'
'scheduler = rero_ils.schedulers:scheduler',
'notifications = rero_ils.modules.notifications.cli:notifications'
],
'invenio_db.models': [
'organisations = rero_ils.modules.organisations.models',
Expand Down

0 comments on commit 838b707

Please sign in to comment.