Exemplo n.º 1
0
def serve(config_file):
    df = 0
    config = Config(config_file)
    Storage.set_engine(DictionaryEngine())
    storage = Storage()
    Task.set_storage(storage)

    serverSensor = SensorListener(storage, config)
    serverSensor.start()

    if config.section_enabled("grpc"):
        print("gRPC server enabled")
        from node_listener.grpc.server import GRPCServer
        grpc_server = GRPCServer(config, storage)
        Dump.module_status({'name': 'gRPC', "status": 2})
        grpc_server.start()

    while True:
        time.sleep(2)
Exemplo n.º 2
0
def serve(config_file):
    config = Config(config_file)

    Storage.set_engine(DictionaryEngine())
    storage = Storage()
    fifo = queue.Queue(maxsize=int(config["grpc"]["queue_size"]))
    queue_bus = QueueBus(fifo)
    storage.on('set', queue_bus.add_to_queue)

    Task.set_storage(storage)

    serverSensor = SensorListener(storage, config)
    serverSensor.start()

    svr = grpc.server(
        futures.ThreadPoolExecutor(
            max_workers=int(config["grpc"]["max_workers"])))
    add_ProviderServicer_to_server(Provider(storage, fifo), svr)
    svr.add_insecure_port(config["grpc"]["address"])
    svr.start()
    svr.wait_for_termination()
Exemplo n.º 3
0
 def test_execute_schould_call_callback_and_save_result(self):
     callback = MagicMock()
     callback.return_value = "value"
     storage = MagicMock()
     storage_key = "meow"
     Task.set_storage(storage)
     task = Task(callback, storage_key)
     task.execute()
     callback.assert_called()
     storage.set.assert_called_with(storage_key, "value")
Exemplo n.º 4
0
import time
from node_listener.storage.storage import Storage
from node_listener.storage.dictionary_engine import DictionaryEngine
from node_listener.scheduler.task import Task
from node_listener.service.sensor_listener import SensorListener
from node_listener.service.config import Config

config = Config('../../config.ini')

Storage.set_engine(DictionaryEngine())
storage = Storage()

Task.set_storage(storage)

serverSensor = SensorListener(storage, config)
serverSensor.start()

while True:
    print("****************")
    # pprint.pprint(storage.get_all())
    time.sleep(2)

Exemplo n.º 5
0
 def _get_task(self, worker, name):
     return Task(worker.execute, name)
Exemplo n.º 6
0
 def test_task_schould_be_created(self):
     callback = 'ooo'
     storage_key = 'store_key'
     task = Task(callback, storage_key)
     assert_equal(task.func, callback)
     assert_equal(task.storage_key, storage_key)
Exemplo n.º 7
0
 def test_storage_schould_be_set(self):
     storage = MagicMock()
     Task.set_storage(storage)
     assert_equal(Task.storage, storage)
Exemplo n.º 8
0
from node_listener.scheduler.task import Task
from node_listener.scheduler.executor import Executor


class DumpStorage(object):
    def __init__(self, storage):
        self.storage = storage

    def execute(self):
        pprint(self.storage.get_all())


Storage.set_engine(DictionaryEngine())
storage = Storage()

Task.set_storage(storage)

config = ConfigParser()
config.read("../../config.ini")

apikey = config["openweather"]["apikey"]
cities = {3103402: "Bielsko-Biała"}

w = OpenweatherWorker(cities, apikey)

executor = Executor()
executor.every_seconds(15, Task(w.execute, 'weather'))
executor.every_seconds(5, DumpStorage(storage), True)

executor.start()