Skip to content

Commit

Permalink
inotifications: group notifications for each patron
Browse files Browse the repository at this point in the history
* Groups notifications through a dispach process.
* Adds a CLI to display time stamp monitoring.
* Fixes different pickup locations for availability notifications.
* Closes rero#1236.

Co-Authored-by: Peter Weber <peter.weber@rero.ch>
  • Loading branch information
rerowep and rerowep committed Apr 29, 2021
1 parent ebfdee3 commit 1377085
Show file tree
Hide file tree
Showing 41 changed files with 686 additions and 371 deletions.
44 changes: 39 additions & 5 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Expand Up @@ -79,6 +79,7 @@ cryptography = ">3.3.1"
freezegun = "^1.1.0"
lazyreader = ">1.0.0"
jinja2 = ">2.11.2"
num2words = "^0.5.10"

[tool.poetry.dev-dependencies]
## Python packages development dependencies (order matters)
Expand Down
32 changes: 32 additions & 0 deletions rero_ils/config.py
Expand Up @@ -307,6 +307,38 @@ def _(x):
'enabled': False,
# TODO: in production set this up once a day
},
'notification-dispatch-due_soon': {
'task': 'rero_ils.modules.notifications.tasks.process_notifications',
'schedule': crontab(minute="*/15"),
'kwargs': {
'notification_type': Notification.DUE_SOON_NOTIFICATION_TYPE
},
'enabled': False,
},
'notification-dispatch-overdue': {
'task': 'rero_ils.modules.notifications.tasks.process_notifications',
'schedule': timedelta(minutes=15),
'kwargs': {
'notification_type': Notification.OVERDUE_NOTIFICATION_TYPE
},
'enabled': False,
},
'notification-dispatch-availability': {
'task': 'rero_ils.modules.notifications.tasks.process_notifications',
'schedule': timedelta(minutes=15),
'kwargs': {
'notification_type': Notification.AVAILABILITY_NOTIFICATION_TYPE
},
'enabled': False,
},
'notification-dispatch-recall': {
'task': 'rero_ils.modules.notifications.tasks.process_notifications',
'schedule': timedelta(minutes=15),
'kwargs': {
'notification_type': Notification.RECALL_NOTIFICATION_TYPE
},
'enabled': False,
},
'claims-creation': {
'task': ('rero_ils.modules.items.tasks'
'.process_late_claimed_issues'),
Expand Down
23 changes: 12 additions & 11 deletions rero_ils/modules/libraries/api.py
Expand Up @@ -333,17 +333,6 @@ def get_timezone(self):
default = pytz.timezone('Europe/Zurich')
return default

def email_notification_type(self, notification_type):
"""Get the email corresponding to the given notification type.
:param notification_type: the notification type.
:return: the email corresponding to the notification type.
:rtype: string
"""
for setting in self['notification_settings']:
if setting['type'] == notification_type:
return setting['email']


class LibrariesIndexer(IlsRecordsIndexer):
"""Holdings indexing class."""
Expand All @@ -356,3 +345,15 @@ def bulk_index(self, record_id_iterator):
:param record_id_iterator: Iterator yielding record UUIDs.
"""
super().bulk_index(record_id_iterator, doc_type='lib')


def email_notification_type(libray, notification_type):
"""Get the email corresponding to the given notification type.
:param notification_type: the notification type.
:return: the email corresponding to the notification type.
:rtype: string
"""
for setting in libray['notification_settings']:
if setting['type'] == notification_type:
return setting['email']
9 changes: 2 additions & 7 deletions rero_ils/modules/loans/api.py
Expand Up @@ -191,7 +191,7 @@ def check_required_params(self, action, **kwargs):
required_params = self.action_required_params(action=action)
missing_params = set(required_params) - set(kwargs)
if missing_params:
message = 'Parameters {} are required'.format(missing_params)
message = f'Parameters {missing_params} are required'
raise MissingRequiredParameterError(description=message)

def update_pickup_location(self, pickup_location_pid):
Expand Down Expand Up @@ -574,12 +574,7 @@ def create_notification(self, notification_type=None, counter=0):
}
notification = Notification.create(
data=record, dbcommit=True, reindex=True)
enqueue = notification_type not in [
Notification.RECALL_NOTIFICATION_TYPE,
Notification.AVAILABILITY_NOTIFICATION_TYPE
]
# put into the queue only for batch notifications i.e. overdue
return notification.dispatch(enqueue=enqueue)
return notification

@classmethod
def concluded(cls, loan):
Expand Down

0 comments on commit 1377085

Please sign in to comment.