@@ -1099,12 +1099,13 @@ class ServerHeartbeatSucceededEvent(_ServerHeartbeatEvent):
1099
1099
.. versionadded:: 3.3
1100
1100
"""
1101
1101
1102
- __slots__ = ('__duration' , '__reply' )
1102
+ __slots__ = ('__duration' , '__reply' , '__awaited' )
1103
1103
1104
- def __init__ (self , duration , reply , * args ):
1105
- super (ServerHeartbeatSucceededEvent , self ).__init__ (* args )
1104
+ def __init__ (self , duration , reply , connection_id , awaited = False ):
1105
+ super (ServerHeartbeatSucceededEvent , self ).__init__ (connection_id )
1106
1106
self .__duration = duration
1107
1107
self .__reply = reply
1108
+ self .__awaited = awaited
1108
1109
1109
1110
@property
1110
1111
def duration (self ):
@@ -1116,10 +1117,20 @@ def reply(self):
1116
1117
"""An instance of :class:`~pymongo.ismaster.IsMaster`."""
1117
1118
return self .__reply
1118
1119
1120
+ @property
1121
+ def awaited (self ):
1122
+ """Whether the heartbeat was awaited.
1123
+
1124
+ If true, then :meth:`duration` reflects the sum of the round trip time
1125
+ to the server and the time that the server waited before sending a
1126
+ response.
1127
+ """
1128
+ return self .__awaited
1129
+
1119
1130
def __repr__ (self ):
1120
- return "<%s %s duration: %s, reply: %s>" % (
1131
+ return "<%s %s duration: %s, awaited: %s, reply: %s>" % (
1121
1132
self .__class__ .__name__ , self .connection_id ,
1122
- self .duration , self .reply )
1133
+ self .duration , self .awaited , self . reply )
1123
1134
1124
1135
1125
1136
class ServerHeartbeatFailedEvent (_ServerHeartbeatEvent ):
@@ -1129,12 +1140,13 @@ class ServerHeartbeatFailedEvent(_ServerHeartbeatEvent):
1129
1140
.. versionadded:: 3.3
1130
1141
"""
1131
1142
1132
- __slots__ = ('__duration' , '__reply' )
1143
+ __slots__ = ('__duration' , '__reply' , '__awaited' )
1133
1144
1134
- def __init__ (self , duration , reply , * args ):
1135
- super (ServerHeartbeatFailedEvent , self ).__init__ (* args )
1145
+ def __init__ (self , duration , reply , connection_id , awaited = False ):
1146
+ super (ServerHeartbeatFailedEvent , self ).__init__ (connection_id )
1136
1147
self .__duration = duration
1137
1148
self .__reply = reply
1149
+ self .__awaited = awaited
1138
1150
1139
1151
@property
1140
1152
def duration (self ):
@@ -1146,10 +1158,20 @@ def reply(self):
1146
1158
"""A subclass of :exc:`Exception`."""
1147
1159
return self .__reply
1148
1160
1161
+ @property
1162
+ def awaited (self ):
1163
+ """Whether the heartbeat was awaited.
1164
+
1165
+ If true, then :meth:`duration` reflects the sum of the round trip time
1166
+ to the server and the time that the server waited before sending a
1167
+ response.
1168
+ """
1169
+ return self .__awaited
1170
+
1149
1171
def __repr__ (self ):
1150
- return "<%s %s duration: %s, reply: %r>" % (
1172
+ return "<%s %s duration: %s, awaited: %s, reply: %r>" % (
1151
1173
self .__class__ .__name__ , self .connection_id ,
1152
- self .duration , self .reply )
1174
+ self .duration , self .awaited , self . reply )
1153
1175
1154
1176
1155
1177
class _EventListeners (object ):
@@ -1303,7 +1325,7 @@ def publish_server_heartbeat_started(self, connection_id):
1303
1325
_handle_exception ()
1304
1326
1305
1327
def publish_server_heartbeat_succeeded (self , connection_id , duration ,
1306
- reply ):
1328
+ reply , awaited ):
1307
1329
"""Publish a ServerHeartbeatSucceededEvent to all server heartbeat
1308
1330
listeners.
1309
1331
@@ -1312,15 +1334,18 @@ def publish_server_heartbeat_succeeded(self, connection_id, duration,
1312
1334
- `duration`: The execution time of the event in the highest possible
1313
1335
resolution for the platform.
1314
1336
- `reply`: The command reply.
1337
+ - `awaited`: True if the response was awaited.
1315
1338
"""
1316
- event = ServerHeartbeatSucceededEvent (duration , reply , connection_id )
1339
+ event = ServerHeartbeatSucceededEvent (duration , reply , connection_id ,
1340
+ awaited )
1317
1341
for subscriber in self .__server_heartbeat_listeners :
1318
1342
try :
1319
1343
subscriber .succeeded (event )
1320
1344
except Exception :
1321
1345
_handle_exception ()
1322
1346
1323
- def publish_server_heartbeat_failed (self , connection_id , duration , reply ):
1347
+ def publish_server_heartbeat_failed (self , connection_id , duration , reply ,
1348
+ awaited ):
1324
1349
"""Publish a ServerHeartbeatFailedEvent to all server heartbeat
1325
1350
listeners.
1326
1351
@@ -1329,8 +1354,10 @@ def publish_server_heartbeat_failed(self, connection_id, duration, reply):
1329
1354
- `duration`: The execution time of the event in the highest possible
1330
1355
resolution for the platform.
1331
1356
- `reply`: The command reply.
1357
+ - `awaited`: True if the response was awaited.
1332
1358
"""
1333
- event = ServerHeartbeatFailedEvent (duration , reply , connection_id )
1359
+ event = ServerHeartbeatFailedEvent (duration , reply , connection_id ,
1360
+ awaited )
1334
1361
for subscriber in self .__server_heartbeat_listeners :
1335
1362
try :
1336
1363
subscriber .failed (event )
0 commit comments