Skip to content
This repository has been archived by the owner on Dec 29, 2017. It is now read-only.

Commit

Permalink
Merge pull request #12 from ovv/scheduler
Browse files Browse the repository at this point in the history
scheduler plugin
  • Loading branch information
ovv authored Jun 10, 2017
2 parents 112d0a2 + 1612d08 commit 1080384
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
1 change: 1 addition & 0 deletions requirements/requirements.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
PyYAML
aiohttp-xmlrpc
Distance
apscheduler
4 changes: 4 additions & 0 deletions requirements/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
#
aiohttp-xmlrpc==0.4.1
aiohttp==2.0.7 # via aiohttp-xmlrpc
apscheduler==3.3.1
async-timeout==1.2.1 # via aiohttp
chardet==3.0.2 # via aiohttp
distance==0.1.3
lxml==3.7.3 # via aiohttp-xmlrpc
multidict==2.1.4 # via aiohttp, yarl
pytz==2017.2 # via apscheduler, tzlocal
pyyaml==3.12
six==1.10.0 # via apscheduler
slimurl==0.7.8 # via aiohttp-xmlrpc
tzlocal==1.4 # via apscheduler
yarl==0.10.1 # via aiohttp
64 changes: 64 additions & 0 deletions sirbot/plugins/scheduler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import logging

from sirbot.core import hookimpl, Plugin
from apscheduler.schedulers.asyncio import AsyncIOScheduler

logger = logging.getLogger(__name__)


@hookimpl
def plugins(loop):
return SchedulerPlugin(loop)


class SchedulerPlugin(Plugin):
__name__ = 'scheduler'
__version__ = '0.0.1'

def __init__(self, loop):
super().__init__(loop)
self._config = None
self._facades = None
self._scheduler = None

self._loop = loop
self._started = False

async def configure(self, config, router, session, facades):
logger.debug('Configuring scheduler plugin')
self._config = config
self._facades = facades

self._scheduler = AsyncIOScheduler(event_loop=self._loop)

async def start(self):
self._scheduler.start()
self._started = True

def facade(self):
return SchedulerFacade(
scheduler=self._scheduler,
facades=self._facades
)

@property
def started(self):
return self._started


class SchedulerFacade:

def __init__(self, scheduler, facades):
self.scheduler = scheduler
self._facades = facades

def add_job(self, func, trigger, args=None, *job_args, **job_kwargs):

if not args:
args = list()
elif type(args) is tuple:
args = list(args)

args.insert(0, self._facades.new())
self.scheduler.add_job(func, trigger=trigger, args=args,
*job_args, **job_kwargs)

0 comments on commit 1080384

Please sign in to comment.