Mercurial > libervia-backend
annotate sat/tools/sat_defer.py @ 3971:9b1d74a6b48c
tests (e2e/cli): add tests for JET:
rel 378
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 31 Oct 2022 04:09:38 +0100 |
parents | 7550ae9cfbac |
children | 524856bd7b19 |
rev | line source |
---|---|
3028 | 1 #!/usr/bin/env python3 |
3137 | 2 |
1448
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 |
3480
7550ae9cfbac
Renamed the project from "Salut à Toi" to "Libervia":
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
4 # Libervia: an XMPP client |
3479 | 5 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org) |
1448
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 # (at your option) any later version. |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 # GNU Affero General Public License for more details. |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 """tools related to deferred""" |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 from sat.core.log import getLogger |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
23 |
1448
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 log = getLogger(__name__) |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 from sat.core import exceptions |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 from twisted.internet import defer |
1549
e987325c14ef
core (tools): “DelayedDeferred” implementation, which is a Deferred launched after a delay
Goffi <goffi@goffi.org>
parents:
1448
diff
changeset
|
27 from twisted.internet import error as internet_error |
e987325c14ef
core (tools): “DelayedDeferred” implementation, which is a Deferred launched after a delay
Goffi <goffi@goffi.org>
parents:
1448
diff
changeset
|
28 from twisted.internet import reactor |
2911
cd391ea847cb
tools (sat_defer), plugin XEP-0060: added a function "stanza2NotFound" to convert item-not-found StanzaError to exceptions.NotFound in an errback
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
29 from twisted.words.protocols.jabber import error as jabber_error |
1448
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 from twisted.python import failure |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 from sat.core.constants import Const as C |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 from sat.memory import memory |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
34 KEY_DEFERREDS = "deferreds" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
35 KEY_NEXT = "next_defer" |
1448
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 |
2911
cd391ea847cb
tools (sat_defer), plugin XEP-0060: added a function "stanza2NotFound" to convert item-not-found StanzaError to exceptions.NotFound in an errback
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
38 def stanza2NotFound(failure_): |
cd391ea847cb
tools (sat_defer), plugin XEP-0060: added a function "stanza2NotFound" to convert item-not-found StanzaError to exceptions.NotFound in an errback
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
39 """Convert item-not-found StanzaError to exceptions.NotFound""" |
cd391ea847cb
tools (sat_defer), plugin XEP-0060: added a function "stanza2NotFound" to convert item-not-found StanzaError to exceptions.NotFound in an errback
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
40 failure_.trap(jabber_error.StanzaError) |
3028 | 41 if failure_.value.condition == 'item-not-found': |
2911
cd391ea847cb
tools (sat_defer), plugin XEP-0060: added a function "stanza2NotFound" to convert item-not-found StanzaError to exceptions.NotFound in an errback
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
42 raise exceptions.NotFound(failure_.value.text or failure_.value.condition) |
cd391ea847cb
tools (sat_defer), plugin XEP-0060: added a function "stanza2NotFound" to convert item-not-found StanzaError to exceptions.NotFound in an errback
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
43 return failure_ |
cd391ea847cb
tools (sat_defer), plugin XEP-0060: added a function "stanza2NotFound" to convert item-not-found StanzaError to exceptions.NotFound in an errback
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
44 |
cd391ea847cb
tools (sat_defer), plugin XEP-0060: added a function "stanza2NotFound" to convert item-not-found StanzaError to exceptions.NotFound in an errback
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
45 |
1549
e987325c14ef
core (tools): “DelayedDeferred” implementation, which is a Deferred launched after a delay
Goffi <goffi@goffi.org>
parents:
1448
diff
changeset
|
46 class DelayedDeferred(object): |
e987325c14ef
core (tools): “DelayedDeferred” implementation, which is a Deferred launched after a delay
Goffi <goffi@goffi.org>
parents:
1448
diff
changeset
|
47 """A Deferred-like which is launched after a delay""" |
e987325c14ef
core (tools): “DelayedDeferred” implementation, which is a Deferred launched after a delay
Goffi <goffi@goffi.org>
parents:
1448
diff
changeset
|
48 |
e987325c14ef
core (tools): “DelayedDeferred” implementation, which is a Deferred launched after a delay
Goffi <goffi@goffi.org>
parents:
1448
diff
changeset
|
49 def __init__(self, delay, result): |
e987325c14ef
core (tools): “DelayedDeferred” implementation, which is a Deferred launched after a delay
Goffi <goffi@goffi.org>
parents:
1448
diff
changeset
|
50 """ |
e987325c14ef
core (tools): “DelayedDeferred” implementation, which is a Deferred launched after a delay
Goffi <goffi@goffi.org>
parents:
1448
diff
changeset
|
51 @param delay(float): delay before launching the callback, in seconds |
e987325c14ef
core (tools): “DelayedDeferred” implementation, which is a Deferred launched after a delay
Goffi <goffi@goffi.org>
parents:
1448
diff
changeset
|
52 @param result: result used with the callback |
e987325c14ef
core (tools): “DelayedDeferred” implementation, which is a Deferred launched after a delay
Goffi <goffi@goffi.org>
parents:
1448
diff
changeset
|
53 """ |
e987325c14ef
core (tools): “DelayedDeferred” implementation, which is a Deferred launched after a delay
Goffi <goffi@goffi.org>
parents:
1448
diff
changeset
|
54 self._deferred = defer.Deferred() |
e987325c14ef
core (tools): “DelayedDeferred” implementation, which is a Deferred launched after a delay
Goffi <goffi@goffi.org>
parents:
1448
diff
changeset
|
55 self._timer = reactor.callLater(delay, self._deferred.callback, result) |
e987325c14ef
core (tools): “DelayedDeferred” implementation, which is a Deferred launched after a delay
Goffi <goffi@goffi.org>
parents:
1448
diff
changeset
|
56 |
e987325c14ef
core (tools): “DelayedDeferred” implementation, which is a Deferred launched after a delay
Goffi <goffi@goffi.org>
parents:
1448
diff
changeset
|
57 def cancel(self): |
e987325c14ef
core (tools): “DelayedDeferred” implementation, which is a Deferred launched after a delay
Goffi <goffi@goffi.org>
parents:
1448
diff
changeset
|
58 try: |
e987325c14ef
core (tools): “DelayedDeferred” implementation, which is a Deferred launched after a delay
Goffi <goffi@goffi.org>
parents:
1448
diff
changeset
|
59 self._timer.cancel() |
e987325c14ef
core (tools): “DelayedDeferred” implementation, which is a Deferred launched after a delay
Goffi <goffi@goffi.org>
parents:
1448
diff
changeset
|
60 except internet_error.AlreadyCalled: |
e987325c14ef
core (tools): “DelayedDeferred” implementation, which is a Deferred launched after a delay
Goffi <goffi@goffi.org>
parents:
1448
diff
changeset
|
61 pass |
e987325c14ef
core (tools): “DelayedDeferred” implementation, which is a Deferred launched after a delay
Goffi <goffi@goffi.org>
parents:
1448
diff
changeset
|
62 self._deferred.cancel() |
e987325c14ef
core (tools): “DelayedDeferred” implementation, which is a Deferred launched after a delay
Goffi <goffi@goffi.org>
parents:
1448
diff
changeset
|
63 |
e987325c14ef
core (tools): “DelayedDeferred” implementation, which is a Deferred launched after a delay
Goffi <goffi@goffi.org>
parents:
1448
diff
changeset
|
64 def addCallbacks(self, *args, **kwargs): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
65 self._deferred.addCallbacks(*args, **kwargs) |
1549
e987325c14ef
core (tools): “DelayedDeferred” implementation, which is a Deferred launched after a delay
Goffi <goffi@goffi.org>
parents:
1448
diff
changeset
|
66 |
e987325c14ef
core (tools): “DelayedDeferred” implementation, which is a Deferred launched after a delay
Goffi <goffi@goffi.org>
parents:
1448
diff
changeset
|
67 def addCallback(self, *args, **kwargs): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
68 self._deferred.addCallback(*args, **kwargs) |
1549
e987325c14ef
core (tools): “DelayedDeferred” implementation, which is a Deferred launched after a delay
Goffi <goffi@goffi.org>
parents:
1448
diff
changeset
|
69 |
e987325c14ef
core (tools): “DelayedDeferred” implementation, which is a Deferred launched after a delay
Goffi <goffi@goffi.org>
parents:
1448
diff
changeset
|
70 def addErrback(self, *args, **kwargs): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
71 self._deferred.addErrback(*args, **kwargs) |
1549
e987325c14ef
core (tools): “DelayedDeferred” implementation, which is a Deferred launched after a delay
Goffi <goffi@goffi.org>
parents:
1448
diff
changeset
|
72 |
e987325c14ef
core (tools): “DelayedDeferred” implementation, which is a Deferred launched after a delay
Goffi <goffi@goffi.org>
parents:
1448
diff
changeset
|
73 def addBoth(self, *args, **kwargs): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
74 self._deferred.addBoth(*args, **kwargs) |
1549
e987325c14ef
core (tools): “DelayedDeferred” implementation, which is a Deferred launched after a delay
Goffi <goffi@goffi.org>
parents:
1448
diff
changeset
|
75 |
e987325c14ef
core (tools): “DelayedDeferred” implementation, which is a Deferred launched after a delay
Goffi <goffi@goffi.org>
parents:
1448
diff
changeset
|
76 def chainDeferred(self, *args, **kwargs): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
77 self._deferred.chainDeferred(*args, **kwargs) |
1549
e987325c14ef
core (tools): “DelayedDeferred” implementation, which is a Deferred launched after a delay
Goffi <goffi@goffi.org>
parents:
1448
diff
changeset
|
78 |
e987325c14ef
core (tools): “DelayedDeferred” implementation, which is a Deferred launched after a delay
Goffi <goffi@goffi.org>
parents:
1448
diff
changeset
|
79 def pause(self): |
e987325c14ef
core (tools): “DelayedDeferred” implementation, which is a Deferred launched after a delay
Goffi <goffi@goffi.org>
parents:
1448
diff
changeset
|
80 self._deferred.pause() |
e987325c14ef
core (tools): “DelayedDeferred” implementation, which is a Deferred launched after a delay
Goffi <goffi@goffi.org>
parents:
1448
diff
changeset
|
81 |
e987325c14ef
core (tools): “DelayedDeferred” implementation, which is a Deferred launched after a delay
Goffi <goffi@goffi.org>
parents:
1448
diff
changeset
|
82 def unpause(self): |
e987325c14ef
core (tools): “DelayedDeferred” implementation, which is a Deferred launched after a delay
Goffi <goffi@goffi.org>
parents:
1448
diff
changeset
|
83 self._deferred.unpause() |
e987325c14ef
core (tools): “DelayedDeferred” implementation, which is a Deferred launched after a delay
Goffi <goffi@goffi.org>
parents:
1448
diff
changeset
|
84 |
e987325c14ef
core (tools): “DelayedDeferred” implementation, which is a Deferred launched after a delay
Goffi <goffi@goffi.org>
parents:
1448
diff
changeset
|
85 |
1448
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
86 class RTDeferredSessions(memory.Sessions): |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
87 """Real Time Deferred Sessions""" |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
88 |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
89 def __init__(self, timeout=120): |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
90 """Manage list of Deferreds in real-time, allowing to get intermediate results |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
91 |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
92 @param timeout (int): nb of seconds before deferreds cancellation |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
93 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
94 super(RTDeferredSessions, self).__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
95 timeout=timeout, resettable_timeout=False |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
96 ) |
1448
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
97 |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
98 def newSession(self, deferreds, profile): |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
99 """Launch a new session with a list of deferreds |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
100 |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
101 @param deferreds(list[defer.Deferred]): list of deferred to call |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
102 @param profile: %(doc_profile)s |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
103 @param return (tupe[str, defer.Deferred]): tuple with session id and a deferred wich fire *WITHOUT RESULT* when all results are received |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
104 """ |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
105 data = {KEY_NEXT: defer.Deferred()} |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
106 session_id, session_data = super(RTDeferredSessions, self).newSession( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
107 data, profile=profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
108 ) |
1448
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
109 if isinstance(deferreds, dict): |
3028 | 110 session_data[KEY_DEFERREDS] = list(deferreds.values()) |
111 iterator = iter(deferreds.items()) | |
1448
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
112 else: |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
113 session_data[KEY_DEFERREDS] = deferreds |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
114 iterator = enumerate(deferreds) |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
115 |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
116 for idx, d in iterator: |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
117 d._RTDeferred_index = idx |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
118 d._RTDeferred_return = None |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
119 d.addCallback(self._callback, d, session_id, profile) |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
120 d.addErrback(self._errback, d, session_id, profile) |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
121 return session_id |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
122 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
123 def _purgeSession( |
3028 | 124 self, session_id, reason="timeout", no_warning=False, got_result=False |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
125 ): |
1448
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
126 """Purge the session |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
127 |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
128 @param session_id(str): id of the session to purge |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
129 @param reason (unicode): human readable reason why the session is purged |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
130 @param no_warning(bool): if True, no warning will be put in logs |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
131 @param got_result(bool): True if the session is purged after normal ending (i.e.: all the results have been gotten). |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
132 reason and no_warning are ignored if got_result is True. |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
133 @raise KeyError: session doesn't exists (anymore ?) |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
134 """ |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
135 if not got_result: |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
136 try: |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
137 timer, session_data, profile = self._sessions[session_id] |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
138 except ValueError: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
139 raise exceptions.InternalError( |
3028 | 140 "was expecting timer, session_data and profile; is profile set ?" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
141 ) |
1448
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
142 |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
143 # next_defer must be called before deferreds, |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
144 # else its callback will be called by _gotResult |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
145 next_defer = session_data[KEY_NEXT] |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
146 if not next_defer.called: |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
147 next_defer.errback(failure.Failure(defer.CancelledError(reason))) |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
148 |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
149 deferreds = session_data[KEY_DEFERREDS] |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
150 for d in deferreds: |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
151 d.cancel() |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
152 |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
153 if not no_warning: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
154 log.warning( |
3028 | 155 "RTDeferredList cancelled: {} (profile {})".format(reason, profile) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
156 ) |
1448
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
157 |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
158 super(RTDeferredSessions, self)._purgeSession(session_id) |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
159 |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
160 def _gotResult(self, session_id, profile): |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
161 """Method called after each callback or errback |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
162 |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
163 manage the next_defer deferred |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
164 """ |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
165 session_data = self.profileGet(session_id, profile) |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
166 defer_next = session_data[KEY_NEXT] |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
167 if not defer_next.called: |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
168 defer_next.callback(None) |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
169 |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
170 def _callback(self, result, deferred, session_id, profile): |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
171 deferred._RTDeferred_return = (True, result) |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
172 self._gotResult(session_id, profile) |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
173 |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
174 def _errback(self, failure, deferred, session_id, profile): |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
175 deferred._RTDeferred_return = (False, failure) |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
176 self._gotResult(session_id, profile) |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
177 |
3028 | 178 def cancel(self, session_id, reason="timeout", no_log=False): |
1448
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
179 """Stop this RTDeferredList |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
180 |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
181 Cancel all remaining deferred, and call self.final_defer.errback |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
182 @param reason (unicode): reason of the cancellation |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
183 @param no_log(bool): if True, don't log the cancellation |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
184 """ |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
185 self._purgeSession(session_id, reason=reason, no_warning=no_log) |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
186 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
187 def getResults( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
188 self, session_id, on_success=None, on_error=None, profile=C.PROF_KEY_NONE |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
189 ): |
1448
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
190 """Get current results of a real-time deferred session |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
191 |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
192 result already gotten are deleted |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
193 @param session_id(str): session id |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
194 @param on_success: can be: |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
195 - None: add success normaly to results |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
196 - callable: replace result by the return value of on_success(result) (may be deferred) |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
197 @param on_error: can be: |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
198 - None: add error normaly to results |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
199 - C.IGNORE: don't put errors in results |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
200 - callable: replace failure by the return value of on_error(failure) (may be deferred) |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
201 @param profile=%(doc_profile)s |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
202 @param result(tuple): tuple(remaining, results) where: |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
203 - remaining[int] is the number of remaining deferred |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
204 (deferreds from which we don't have result yet) |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
205 - results is a dict where: |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
206 - key is the index of the deferred if deferred is a list, or its key if it's a dict |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
207 - value = (success, result) where: |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
208 - success is True if the deferred was successful |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
209 - result is the result in case of success, else the failure |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
210 If remaining == 0, the session is ended |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
211 @raise KeyError: the session is already finished or doesn't exists at all |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
212 """ |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
213 if profile == C.PROF_KEY_NONE: |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
214 raise exceptions.ProfileNotSetError |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
215 session_data = self.profileGet(session_id, profile) |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
216 |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
217 @defer.inlineCallbacks |
2765
378188abe941
misc: replaced all "dummy" by the more conventional and readable "__" ("_" being used for gettext)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
218 def next_cb(__): |
1448
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
219 # we got one or several results |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
220 results = {} |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
221 filtered_data = [] # used to keep deferreds without results |
1448
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
222 deferreds = session_data[KEY_DEFERREDS] |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
223 |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
224 for d in deferreds: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
225 if ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
226 d._RTDeferred_return |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
227 ): # we don't use d.called as called is True before the full callbacks chain has been called |
1448
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
228 # we have a result |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
229 idx = d._RTDeferred_index |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
230 success, result = d._RTDeferred_return |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
231 if success: |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
232 if on_success is not None: |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
233 if callable(on_success): |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
234 result = yield on_success(result) |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
235 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
236 raise exceptions.InternalError( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
237 "Unknown value of on_success: {}".format(on_success) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
238 ) |
1448
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
239 |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
240 else: |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
241 if on_error is not None: |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
242 if on_error == C.IGNORE: |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
243 continue |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
244 elif callable(on_error): |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
245 result = yield on_error(result) |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
246 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
247 raise exceptions.InternalError( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
248 "Unknown value of on_error: {}".format(on_error) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
249 ) |
1448
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
250 results[idx] = (success, result) |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
251 else: |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
252 filtered_data.append(d) |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
253 |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
254 # we change the deferred with the filtered list |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
255 # in other terms, we don't want anymore deferred from which we have got the result |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
256 session_data[KEY_DEFERREDS] = filtered_data |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
257 |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
258 if filtered_data: |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
259 # we create a new next_defer only if we are still waiting for results |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
260 session_data[KEY_NEXT] = defer.Deferred() |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
261 else: |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
262 # no more data to get, the result have been gotten, |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
263 # we can cleanly finish the session |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
264 self._purgeSession(session_id, got_result=True) |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
265 |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
266 defer.returnValue((len(filtered_data), results)) |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
267 |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
268 # we wait for a result |
227856b13d7a
core: new tools.sat_defer module, and implementation of RTDeferredSessions:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
269 return session_data[KEY_NEXT].addCallback(next_cb) |