##// END OF EJS Templates
events: reduce usage of threadglobals in global imports for gevent
super-admin -
r5068:d9f07e87 default
parent child Browse files
Show More
@@ -1,83 +1,85 b''
1 1 # Copyright (C) 2016-2020 RhodeCode GmbH
2 2 #
3 3 # This program is free software: you can redistribute it and/or modify
4 4 # it under the terms of the GNU Affero General Public License, version 3
5 5 # (only), as published by the Free Software Foundation.
6 6 #
7 7 # This program is distributed in the hope that it will be useful,
8 8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 10 # GNU General Public License for more details.
11 11 #
12 12 # You should have received a copy of the GNU Affero General Public License
13 13 # along with this program. If not, see <http://www.gnu.org/licenses/>.
14 14 #
15 15 # This program is dual-licensed. If you wish to learn more about the
16 16 # RhodeCode Enterprise Edition, including its added features, Support services,
17 17 # and proprietary license terms, please see https://rhodecode.com/licenses/
18 18
19 19 import logging
20 from pyramid.threadlocal import get_current_registry
20
21 21 from rhodecode.events.base import RhodeCodeIntegrationEvent
22 22
23 23 from rhodecode.events.base import ( # pragma: no cover
24 24 FtsBuild
25 25 )
26 26
27 27 from rhodecode.events.user import ( # pragma: no cover
28 28 UserPreCreate,
29 29 UserPostCreate,
30 30 UserPreUpdate,
31 31 UserRegistered,
32 32 UserPermissionsChange,
33 33 )
34 34
35 35 from rhodecode.events.repo import ( # pragma: no cover
36 36 RepoEvent,
37 37 RepoCommitCommentEvent, RepoCommitCommentEditEvent,
38 38 RepoPreCreateEvent, RepoCreateEvent,
39 39 RepoPreDeleteEvent, RepoDeleteEvent,
40 40 RepoPrePushEvent, RepoPushEvent,
41 41 RepoPrePullEvent, RepoPullEvent,
42 42 )
43 43
44 44 from rhodecode.events.repo_group import ( # pragma: no cover
45 45 RepoGroupEvent,
46 46 RepoGroupCreateEvent,
47 47 RepoGroupUpdateEvent,
48 48 RepoGroupDeleteEvent,
49 49 )
50 50
51 51 from rhodecode.events.pullrequest import ( # pragma: no cover
52 52 PullRequestEvent,
53 53 PullRequestCreateEvent,
54 54 PullRequestUpdateEvent,
55 55 PullRequestCommentEvent,
56 56 PullRequestCommentEditEvent,
57 57 PullRequestReviewEvent,
58 58 PullRequestMergeEvent,
59 59 PullRequestCloseEvent,
60 60 )
61 61
62 62
63 63 log = logging.getLogger(__name__)
64 64
65 65
66 66 def trigger(event, registry=None):
67 67 """
68 68 Helper method to send an event. This wraps the pyramid logic to send an
69 69 event.
70 70 """
71 71 # For the first step we are using pyramids thread locals here. If the
72 72 # event mechanism works out as a good solution we should think about
73 73 # passing the registry as an argument to get rid of it.
74 from pyramid.threadlocal import get_current_registry
75
74 76 event_name = event.__class__
75 77 log.debug('event %s sent for execution', event_name)
76 78 registry = registry or get_current_registry()
77 79 registry.notify(event)
78 80 log.debug('event %s triggered using registry %s', event_name, registry)
79 81
80 82 # Send the events to integrations directly
81 83 from rhodecode.integrations import integrations_event_handler
82 84 if isinstance(event, RhodeCodeIntegrationEvent):
83 85 integrations_event_handler(event)
General Comments 0
You need to be logged in to leave comments. Login now