Change notificationworker to use a data interface
This commit is contained in:
parent
8ec198228c
commit
b6f1782642
10 changed files with 149 additions and 56 deletions
50
workers/notificationworker/models_interface.py
Normal file
50
workers/notificationworker/models_interface.py
Normal file
|
@ -0,0 +1,50 @@
|
|||
from abc import ABCMeta, abstractmethod
|
||||
from collections import namedtuple
|
||||
from six import add_metaclass
|
||||
|
||||
|
||||
class Repository(namedtuple('Repository', ['namespace_name', 'name'])):
|
||||
"""
|
||||
Repository represents a repository.
|
||||
"""
|
||||
|
||||
|
||||
class Notification(
|
||||
namedtuple('Notification', [
|
||||
'uuid', 'event_name', 'method_name', 'event_config_dict', 'method_config_dict',
|
||||
'repository'])):
|
||||
"""
|
||||
Notification represents a registered notification of some kind.
|
||||
"""
|
||||
|
||||
|
||||
@add_metaclass(ABCMeta)
|
||||
class NotificationWorkerDataInterface(object):
|
||||
"""
|
||||
Interface that represents all data store interactions required by the notification worker.
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
def get_enabled_notification(self, notification_uuid):
|
||||
""" Returns an *enabled* notification with the given UUID, or None if none. """
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def reset_number_of_failures_to_zero(self, notification):
|
||||
""" Resets the number of failures for the given notification back to zero. """
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def increment_notification_failure_count(self, notification):
|
||||
""" Increments the number of failures on the given notification. """
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def create_notification_for_testing(self, target_username):
|
||||
""" Creates a notification for testing. """
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def user_has_local_notifications(self, target_username):
|
||||
""" Returns whether there are any Quay-local notifications for the given user. """
|
||||
pass
|
Reference in a new issue