]> mj.ucw.cz Git - moe.git/commitdiff
HOOKS->EXTENSIONS (with explanation), added dummy extension
authorTomas Gavenciak <gavento@ucw.cz>
Sat, 11 Sep 2010 15:45:12 +0000 (17:45 +0200)
committerTomas Gavenciak <gavento@ucw.cz>
Sat, 11 Sep 2010 15:53:31 +0000 (17:53 +0200)
Hooks had some problems - the hook modules have to insert self
into the pipeline, but cannot decide into which (only main) and
cannot see Eval during init() (or use the logs)

Having HOOKS with explicit timing:
HOOKS="m:8:my_main_pipeline_hook t:79:cleanup_in_test_pipeline"
would be a possibility, but a little too complex.

Extension is almost the same thing as hook (sugary name change),
but can do anything during init, can insert multiple hooks
(to both main and test pipelines), read/change configuration
and use logs.

Good extension example is fetching tasks via RSYNC or GIT.

t/moe/exts/__init__.py [new file with mode: 0644]
t/moe/exts/dummy.py [new file with mode: 0644]

diff --git a/t/moe/exts/__init__.py b/t/moe/exts/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/t/moe/exts/dummy.py b/t/moe/exts/dummy.py
new file mode 100644 (file)
index 0000000..eef59bd
--- /dev/null
@@ -0,0 +1,22 @@
+"""
+
+Debug dummy extension.
+
+Adds several info-printing hooks to both pipelines.
+"""
+
+def init(e):
+      
+      def hook_m_0:
+         e.log.info('Hey! It\'s me, the dummy extension in your main pipeline! (at time 0)')
+      e.main_pipeline.insert(hook_m_0, 'exts.dummy.hook_m_0', 0)
+      
+      def hook_m_79:
+         e.log.info('Me, the dummy extension, requies no cleanup! (at time 79)')
+      e.main_pipeline.insert(hook_m_79, 'exts.dummy.hook_m_79', 79) 
+      
+      def hook_t_42:
+         t = 'It\'s test %s and the dummy extension did nothing! (at time 42)' % e['TEST']
+         e.log.info(t)
+         e.log.user.info(t)
+      e.test_pipeline.insert(hook_t_42, 'exts.dummy.hook_t_42', 42)