MCPcopy Create free account
hub / github.com/StackStorm/st2 / TriggerWatcher

Class TriggerWatcher

st2common/st2common/services/triggerwatcher.py:32–172  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30
31
32class TriggerWatcher(ConsumerMixin):
33
34 sleep_interval = 0 # sleep to co-operatively yield after processing each message
35
36 def __init__(
37 self,
38 create_handler,
39 update_handler,
40 delete_handler,
41 trigger_types=None,
42 queue_suffix=None,
43 exclusive=False,
44 ):
45 """
46 :param create_handler: Function which is called on TriggerDB create event.
47 :type create_handler: ``callable``
48
49 :param update_handler: Function which is called on TriggerDB update event.
50 :type update_handler: ``callable``
51
52 :param delete_handler: Function which is called on TriggerDB delete event.
53 :type delete_handler: ``callable``
54
55 :param trigger_types: If provided, handler function will only be called
56 if the trigger in the message payload is included
57 in this list.
58 :type trigger_types: ``list``
59
60 :param exclusive: If the Q is exclusive to a specific connection which is then
61 single connection created by TriggerWatcher. When the connection
62 breaks the Q is removed by the message broker.
63 :type exclusive: ``bool``
64 """
65 # TODO: Handle trigger type filtering using routing key
66 self._create_handler = create_handler
67 self._update_handler = update_handler
68 self._delete_handler = delete_handler
69 self._trigger_types = trigger_types
70 self._trigger_watch_q = self._get_queue(queue_suffix, exclusive=exclusive)
71
72 self.connection = None
73 self._load_thread = None
74 self._updates_thread = None
75
76 self._handlers = {
77 publishers.CREATE_RK: create_handler,
78 publishers.UPDATE_RK: update_handler,
79 publishers.DELETE_RK: delete_handler,
80 }
81
82 def get_consumers(self, Consumer, channel):
83 return [
84 Consumer(
85 queues=[self._trigger_watch_q],
86 accept=["pickle"],
87 callbacks=[self.process_task],
88 )
89 ]

Callers 4

__init__Method · 0.90
__init__Method · 0.90
__init__Method · 0.90
__init__Method · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected