From c17d5bdb4004e87336fe11e0dcfbc36b255dc950 Mon Sep 17 00:00:00 2001 From: Sayan Chowdhury Date: Nov 21 2015 08:02:14 +0000 Subject: Initial commit for the plugin; Add autocloud plugin --- diff --git a/bugyou_plugins/autocloud/__init__.py b/bugyou_plugins/autocloud/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/bugyou_plugins/autocloud/__init__.py +++ /dev/null diff --git a/bugyou_plugins/autocloud/plugin.py b/bugyou_plugins/autocloud/plugin.py deleted file mode 100644 index 2c4d2ba..0000000 --- a/bugyou_plugins/autocloud/plugin.py +++ /dev/null @@ -1,3 +0,0 @@ -class AutocloudPlugin: - def __init__(self): - print 'I am ready' diff --git a/bugyou_plugins/plugins/autocloud/__init__.py b/bugyou_plugins/plugins/autocloud/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/bugyou_plugins/plugins/autocloud/__init__.py diff --git a/bugyou_plugins/plugins/autocloud/plugin.py b/bugyou_plugins/plugins/autocloud/plugin.py new file mode 100644 index 0000000..ecde123 --- /dev/null +++ b/bugyou_plugins/plugins/autocloud/plugin.py @@ -0,0 +1,11 @@ +from bugyou_plugins.base import BasePlugin + +class AutocloudPlugin(BasePlugin): + def __init__(self): + self.queue_name = 'autocloud' + + def process(self, task): + print task + + + diff --git a/bugyou_plugins/plugins/base.py b/bugyou_plugins/plugins/base.py new file mode 100644 index 0000000..b6c647f --- /dev/null +++ b/bugyou_plugins/plugins/base.py @@ -0,0 +1,35 @@ +import abc +import copy +import multiprocessing + +from retask import Queue + + +class BasePlugin(object): + __metaclass__ = abc.ABCMeta + + def initialize(self): + self.init_retask_connection() + self.init_worker() + + def init_retask_connection(self): + """ Connect to the retask queue for the plugin """ + self.queue = Queue(self.queue_name) + conn = self.queue.connect() + if not conn: + log.debug('Could not connect to %s queue' % self.queue_name) + return False + + def consume(self): + while True: + task = self.queue.wait() + self.process(task) + + def init_worker(self): + """ Create a process and start consuming the messages """ + process = multiprocessing.Process(target=self.consume) + process.start() + + @abc.abstractmethod + def process(self): + """ Consumes the messages from retask """ diff --git a/setup.py b/setup.py index deea2a9..1d4310e 100644 --- a/setup.py +++ b/setup.py @@ -26,8 +26,8 @@ setup( 'Programming Language :: Python', ], entry_points={ - 'console_scripts': [ - 'bugyouctl = bugyou_plugins.bugyouctl:main', + 'bugyou.plugin': [ + "autocloud = bugyou_plugins.autocloud:AutocloudPlugin", ] }, )