# Path: peachbox/task/scheduled_task.py
# class ScheduledTask(Task):
#     """Peachbox scheduled task.
#     A scheduled task ....
#     """
# 
#     def __init__(self):
#         super(ScheduledTask, self).__init__()
#         self.source  = None
#         self.sources = None
#         self.sink    = None
#         self.process = None
#         self.payload = None
# 
#     def execute(self):
#         """User defined ScheduledTaks must implement 'execute'"""
#         raise NotImplementedError
# 
#     def run_scheduled_task(self, param={}):
#         """ run_scheduled_task is executed by peachbox"""
#         if self.source:
#             self.source.set_param(param)
#         if self.sources:
#             for s in self.sources: s.set_param(param)
#         if self.sink:
#             self.sink.set_param(param)
# 
#         self.process = Process(target=self.run_in_process, args=(Scheduler.Instance(),))
#         self.process.start()
# 
#     def run_in_process(self, scheduler):
#        self.execute()
#        self.tear_down()
#        e = self.get_event_finished() 
#        scheduler.publish(e)
# 
#     def tear_down(self):
#         peachbox.Spark.Instance().stop()
# 
#     def get_event_finished(self):
#         e = Event(self.__class__.__name__ + "Finished")
#         status = e.status()
#         try:
#             status['payload'] = self.payload 
#         except AttributeError:
#             pass
#         return e


import unittest
import time
import peachbox.connector.source
import peachbox.connector.sink
import peachbox
from peachbox.task import ScheduledTask

class TestConnector(peachbox.connector.Connector):
    def set_param(self, param):
        self.param = param

class MyTask(ScheduledTask):
    def __init__(self):
        self.source  = TestConnector()
        self.sources = [TestConnector(), TestConnector()]
        self.sink    = TestConnector()

    def execute(self):
        print "In execute"


# Path: peachbox/task/scheduled_task.py
# class ScheduledTask(Task):
#     """Peachbox scheduled task.
#     A scheduled task ....
#     """
# 
#     def __init__(self):
#         super(ScheduledTask, self).__init__()
#         self.source  = None
#         self.sources = None
#         self.sink    = None
#         self.process = None
#         self.payload = None
# 
#     def execute(self):
#         """User defined ScheduledTaks must implement 'execute'"""
#         raise NotImplementedError
# 
#     def run_scheduled_task(self, param={}):
#         """ run_scheduled_task is executed by peachbox"""
#         if self.source:
#             self.source.set_param(param)
#         if self.sources:
#             for s in self.sources: s.set_param(param)
#         if self.sink:
#             self.sink.set_param(param)
# 
#         self.process = Process(target=self.run_in_process, args=(Scheduler.Instance(),))
#         self.process.start()
# 
#     def run_in_process(self, scheduler):
#        self.execute()
#        self.tear_down()
#        e = self.get_event_finished() 
#        scheduler.publish(e)
# 
#     def tear_down(self):
#         peachbox.Spark.Instance().stop()
# 
#     def get_event_finished(self):
#         e = Event(self.__class__.__name__ + "Finished")
#         status = e.status()
#         try:
#             status['payload'] = self.payload 
#         except AttributeError:
#             pass
#         return e


# Path: peachbox/task/tests/test_scheduled_task.py
import unittest
import time
import peachbox.connector.source
import peachbox.connector.sink
import peachbox
from peachbox.task import ScheduledTask


class TestConnector(peachbox.connector.Connector):
    def set_param(self, param):
        self.param = param

class MyTask(ScheduledTask):
    def __init__(self):
        self.source  = TestConnector()
        self.sources = [TestConnector(), TestConnector()]
        self.sink    = TestConnector()

    def execute(self):
        print "In execute"


class TestTask(unittest.TestCase):