From 5656c8764b09bfaa10585fa92c2cea3628ff643d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0smail=20Ba=C5=9Faran?= Date: Mon, 29 Feb 2016 17:13:39 +0200 Subject: [PATCH] added task base --- opt/ahenk/base/task/TaskInQueue.py | 25 +++++++++++++++++++++++++ opt/ahenk/base/task/TaskJob.py | 16 ++++++++++++++++ opt/ahenk/base/task/TaskManager.py | 9 +++++++++ opt/ahenk/base/task/__init__.py | 0 4 files changed, 50 insertions(+) create mode 100644 opt/ahenk/base/task/TaskInQueue.py create mode 100644 opt/ahenk/base/task/TaskJob.py create mode 100644 opt/ahenk/base/task/TaskManager.py create mode 100644 opt/ahenk/base/task/__init__.py diff --git a/opt/ahenk/base/task/TaskInQueue.py b/opt/ahenk/base/task/TaskInQueue.py new file mode 100644 index 0000000..c9dab2d --- /dev/null +++ b/opt/ahenk/base/task/TaskInQueue.py @@ -0,0 +1,25 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- +# Author: İsmail BAŞARAN + +import threading +from base.task.TaskJob import TaskJob + +class TaskInQueue(threading.Thread): + """docstring for TaskInQueue""" + def __init__(self,inQueue): + super(TaskInQueue, self).__init__() + self.inQueue = inQueue + + def run(self): + # Add task to db. Adding task to db important because task can be lost when processing. + # Call plugin manager and process message inside task job + try: + task = self.inQueue.get() + print(task) + # Can be validate task before processing + job = TaskJob(task) + job.start() + + except Exception as e: + raise diff --git a/opt/ahenk/base/task/TaskJob.py b/opt/ahenk/base/task/TaskJob.py new file mode 100644 index 0000000..75d431f --- /dev/null +++ b/opt/ahenk/base/task/TaskJob.py @@ -0,0 +1,16 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- +# Author: İsmail BAŞARAN +import threading +from base.Scope import Scope + +class TaskJob(threading.Thread): + """docstring for TaskJob""" + def __init__(self, task): + super(TaskJob, self).__init__() + scope = Scope.getInstance() + self.task = task + self.pluginManager = scope.getPluginManager() + + def run(self): + self.pluginManager.process(self.task) diff --git a/opt/ahenk/base/task/TaskManager.py b/opt/ahenk/base/task/TaskManager.py new file mode 100644 index 0000000..e011f1b --- /dev/null +++ b/opt/ahenk/base/task/TaskManager.py @@ -0,0 +1,9 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- +# Author: İsmail BAŞARAN + +class TaskManager(object): + """docstring for TaskManager""" + def __init__(self): + super(TaskManager, self).__init__() + diff --git a/opt/ahenk/base/task/__init__.py b/opt/ahenk/base/task/__init__.py new file mode 100644 index 0000000..e69de29