Refactored event worker plugin structure into plugin directory.
Worker plugins are now part of the general plugin architecture and framework. Subscription plugin has also been moved to storyboard.plugin to indicate that it's a plugin (though inline). Change-Id: I8477c0aeda5270d6bc9ae1a4da90ab14e657961f
This commit is contained in:
parent
5561fa4078
commit
ab11380b34
@ -23,7 +23,7 @@ setup.cfg file. For example::
|
||||
[entry_points]
|
||||
storyboard.plugin.user_preferences =
|
||||
my-plugin-config = my.namespace.plugin:UserPreferences
|
||||
storyboard.worker.task =
|
||||
storyboard.plugin.worker =
|
||||
my-plugin-worker = my.namespace.plugin:EventWorker
|
||||
storyboard.plugin.cron =
|
||||
my-plugin-cron = my.namespace.plugin:CronWorker
|
||||
@ -89,7 +89,7 @@ and your plugin can decide how to process each event in an asynchronous
|
||||
thread which will not impact the stability of the API::
|
||||
|
||||
[entry_points]
|
||||
storyboard.worker.task =
|
||||
storyboard.plugin.worker =
|
||||
my-plugin-worker = my.namespace.plugin:EventWorker
|
||||
|
||||
To learn how to write a user preference plugin, please contribute to this
|
||||
|
@ -30,12 +30,12 @@ data_files =
|
||||
console_scripts =
|
||||
storyboard-api = storyboard.api.app:start
|
||||
storyboard-subscriber = storyboard.notifications.subscriber:subscribe
|
||||
storyboard-worker-daemon = storyboard.worker.daemon:run
|
||||
storyboard-worker-daemon = storyboard.plugin.daemon:run_daemon
|
||||
storyboard-db-manage = storyboard.db.migration.cli:main
|
||||
storyboard-migrate = storyboard.migrate.cli:main
|
||||
storyboard-cron = storyboard.plugin.cron:main
|
||||
storyboard.worker.task =
|
||||
subscription = storyboard.worker.task.subscription:Subscription
|
||||
storyboard.plugin.worker =
|
||||
subscription = storyboard.plugin.subscription.base:Subscription
|
||||
storyboard.plugin.user_preferences =
|
||||
storyboard.plugin.scheduler =
|
||||
token-cleaner = storyboard.plugin.token_cleaner.cleaner:TokenCleaner
|
||||
|
@ -44,7 +44,7 @@ def subscribe():
|
||||
subscriber.start()
|
||||
|
||||
manager = enabled.EnabledExtensionManager(
|
||||
namespace='storyboard.worker.task',
|
||||
namespace='storyboard.plugin.worker',
|
||||
check_func=check_enabled,
|
||||
invoke_on_load=True,
|
||||
invoke_args=(CONF,)
|
||||
|
@ -12,6 +12,7 @@
|
||||
# implied. See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import abc
|
||||
import signal
|
||||
|
||||
from multiprocessing import Process
|
||||
@ -21,7 +22,7 @@ from threading import Timer
|
||||
from oslo.config import cfg
|
||||
from storyboard.notifications.subscriber import subscribe
|
||||
from storyboard.openstack.common.gettextutils import _LI, _LW # noqa
|
||||
|
||||
from storyboard.plugin.base import PluginBase
|
||||
|
||||
CONF = cfg.CONF
|
||||
LOG = log.getLogger(__name__)
|
||||
@ -34,7 +35,7 @@ IMPORT_OPTS = [
|
||||
]
|
||||
|
||||
|
||||
def run():
|
||||
def run_daemon():
|
||||
"""Start the daemon manager.
|
||||
"""
|
||||
global MANAGER
|
||||
@ -151,3 +152,27 @@ class PerpetualTimer():
|
||||
|
||||
def cancel(self):
|
||||
self.thread.cancel()
|
||||
|
||||
|
||||
class WorkerTaskBase(PluginBase):
|
||||
"""Base class for a worker that listens to API Events."""
|
||||
|
||||
__metaclass__ = abc.ABCMeta
|
||||
|
||||
@abc.abstractmethod
|
||||
def handle(self, author_id, method, path, status, resource, resource_id,
|
||||
sub_resource=None, sub_resource_id=None,
|
||||
resource_before=None, resource_after=None):
|
||||
"""Handle an event.
|
||||
|
||||
:param author_id: ID of the author's user record.
|
||||
:param method: The HTTP Method.
|
||||
:param path: The full HTTP Path requested.
|
||||
:param status: The returned HTTP Status of the response.
|
||||
:param resource: The resource type.
|
||||
:param resource_id: The ID of the resource.
|
||||
:param sub_resource: The subresource type.
|
||||
:param sub_resource_id: The ID of the subresource.
|
||||
:param resource_before: The resource state before this event occurred.
|
||||
:param resource_after: The resource state after this event occurred.
|
||||
"""
|
@ -17,7 +17,7 @@ import json
|
||||
import storyboard.db.api.base as db_api
|
||||
from storyboard.db.api import subscriptions as sub_api
|
||||
import storyboard.db.models as models
|
||||
from storyboard.worker.task.base import WorkerTaskBase
|
||||
from storyboard.plugin.event_worker import WorkerTaskBase
|
||||
|
||||
|
||||
class Subscription(WorkerTaskBase):
|
@ -1,51 +0,0 @@
|
||||
# Copyright (c) 2014 Hewlett-Packard Development Company, L.P.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import abc
|
||||
|
||||
|
||||
class WorkerTaskBase(object):
|
||||
"""Base class for a worker that listens to events that occur within the
|
||||
API.
|
||||
"""
|
||||
|
||||
__metaclass__ = abc.ABCMeta
|
||||
|
||||
def __init__(self, config):
|
||||
self.config = config
|
||||
|
||||
@abc.abstractmethod
|
||||
def enabled(self):
|
||||
"""A method which indicates whether this worker task is properly
|
||||
configured and should be enabled. If it's ready to go, return True.
|
||||
Otherwise, return False.
|
||||
"""
|
||||
|
||||
@abc.abstractmethod
|
||||
def handle(self, author_id, method, path, status, resource, resource_id,
|
||||
sub_resource=None, sub_resource_id=None,
|
||||
resource_before=None, resource_after=None):
|
||||
"""Handle an event.
|
||||
|
||||
:param author_id: ID of the author's user record.
|
||||
:param method: The HTTP Method.
|
||||
:param path: The full HTTP Path requested.
|
||||
:param status: The returned HTTP Status of the response.
|
||||
:param resource: The resource type.
|
||||
:param resource_id: The ID of the resource.
|
||||
:param sub_resource: The subresource type.
|
||||
:param sub_resource_id: The ID of the subresource.
|
||||
:param resource_before: The resource state before this event occurred.
|
||||
:param resource_after: The resource state after this event occurred.
|
||||
"""
|
Loading…
Reference in New Issue
Block a user