<gh_stars>10-100
import aiojobs
import inspect
from .. import logger


class Scheduler:
    def __init__(self, **kwargs):
        self.scheduler = None
        self.jobs_limit = kwargs.get('jobs_limit', 200)

    async def startup(self):
        self.scheduler = await aiojobs.create_scheduler(exception_handler=None, limit=self.jobs_limit)

    async def shutdown(self):
        await self.scheduler.close()

    async def spawn(self, coro):
        return await self.scheduler.spawn(coro)

    async def spawn_tasks(self, tasks):
        for task in tasks:
            try:
                logger.debug(f'Executing worker {task.__name__}')
                if inspect.iscoroutinefunction(task) == True:
                    task = task()
                await self.scheduler.spawn(task)
            except Exception:
                logger.exception('exc')

import aiojobs
import inspect
from .. import logger


class Scheduler:
    def __init__(self, **kwargs):
        self.scheduler = None
        self.jobs_limit = kwargs.get('jobs_limit', 200)

    async def startup(self):
        self.scheduler = await aiojobs.create_scheduler(exception_handler=None, limit=self.jobs_limit)

    async def shutdown(self):
        await self.scheduler.close()

    async def spawn(self, coro):
        return await self.scheduler.spawn(coro)

    async def spawn_tasks(self, tasks):
        for task in tasks:
            try:
                logger.debug(f'Executing worker {task.__name__}')
                if inspect.iscoroutinefunction(task) == True:
                    task = task()
                await self.scheduler.spawn(task)
            except Exception:
                logger.exception('exc')