Run event hook actions in another thread

This commit is contained in:
Fabio Manganiello 2018-11-28 01:01:16 +01:00
parent 984567694a
commit abbd8409ca
1 changed files with 5 additions and 2 deletions

View File

@ -2,6 +2,7 @@ import copy
import json import json
import logging import logging
import re import re
import threading
from platypush.config import Config from platypush.config import Config
from platypush.message.event import Event, EventMatchResult from platypush.message.event import Event, EventMatchResult
@ -148,13 +149,15 @@ class EventHook(object):
""" Checks the condition of the hook against a particular event and """ Checks the condition of the hook against a particular event and
runs the hook actions if the condition is met """ runs the hook actions if the condition is met """
def _thread_func(result):
self.actions.execute(event=event, **result.parsed_args)
result = self.matches_event(event) result = self.matches_event(event)
token = Config.get('token') token = Config.get('token')
if result.is_match: if result.is_match:
logger.info('Running hook {} triggered by an event'.format(self.name)) logger.info('Running hook {} triggered by an event'.format(self.name))
# TODO here event should actually be event.args threading.Thread(target=_thread_func, args=(result,)).start()
self.actions.execute(event=event, **result.parsed_args)
# vim:sw=4:ts=4:et: # vim:sw=4:ts=4:et: