Beispiel #1
0
 def start_task(self, name: str, params: object = {}):
     log.debug("Starting task " + name)
     mgr = get_plugin("task-manager")
     task = mgr.get_task(name)
     i = mgr.celery.control.inspect()
     availability = i.ping()
     log.debug(availability)
     assert availability is not None
     self._running_task = task.delay(**params)
     log.debug(self._running_task)
     log.debug(f"Started task with id {self._running_task.id}")
     return self._running_task
Beispiel #2
0
    async def _subscriber_loop(self, session, channel_name):
        plugin = get_plugin("task-manager")
        if plugin.broadcast is None:
            return

        await session.send_json(
            {"info": f"Trying to connect to channel {channel_name}"})
        if not hasattr(plugin.broadcast._backend, "_subscriber"):
            await plugin.broadcast.connect()
        async with plugin.broadcast.subscribe(
                channel=channel_name) as subscriber:
            await session.send_json(
                {"info": f"Subscribed to channel {channel_name}"})
            async for event in subscriber:
                await session.send_json(loads(event.message))
            await session.send_json({"info": f"Closing subscription"})
Beispiel #3
0
    def wrapper(func):
        task_name = _name_for_task(func, **kwargs)
        kwargs["name"] = task_name
        mgr = None
        try:
            mgr = get_plugin("task-manager")
        except (ImportError, AttributeError, ValueError):
            # Queue the task for later registration
            _tasks_to_register[task_name] = (func, args, kwargs)
        if mgr is not None:
            # Register the task right now
            mgr.register_task(func, *args, **kwargs)

        def _run_task(*args, **kwargs):
            """Function to run a task that is already registered to the running Sparrow application."""
            mgr = get_plugin("task-manager")
            func = mgr.get_task(task_name)
            return func(*args, **kwargs)

        return _run_task
Beispiel #4
0
 def _run_task(*args, **kwargs):
     """Function to run a task that is already registered to the running Sparrow application."""
     mgr = get_plugin("task-manager")
     func = mgr.get_task(task_name)
     return func(*args, **kwargs)
Beispiel #5
0
 def manager(self):
     return get_plugin("task-manager")
Beispiel #6
0
async def tasks(request):
    mgr = get_plugin("task-manager")
    return APIResponse({
        "tasks": mgr.task_info(),
        "enabled": mgr._task_worker_enabled
    })