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