14
14
15
15
"""CommandCursor class to iterate over command results."""
16
16
17
+ import datetime
18
+
17
19
from collections import deque
18
20
19
21
from bson .py3compat import integer_types
20
22
from pymongo import helpers , monitoring
21
- from pymongo .errors import AutoReconnect , CursorNotFound , NotMasterError
23
+ from pymongo .errors import AutoReconnect , NotMasterError , OperationFailure
22
24
from pymongo .message import _GetMore
23
25
24
26
@@ -101,16 +103,19 @@ def __send_message(self, operation):
101
103
raise
102
104
103
105
publish = monitoring .enabled ()
104
- duration = response .duration
106
+ cmd_duration = response .duration
105
107
rqst_id = response .request_id
108
+ if publish :
109
+ start = datetime .datetime .now ()
106
110
try :
107
111
doc = helpers ._unpack_response (response .data ,
108
112
self .__id ,
109
113
self .__collection .codec_options )
110
- except CursorNotFound as exc :
114
+ except OperationFailure as exc :
111
115
self .__killed = True
112
116
113
117
if publish :
118
+ duration = (datetime .datetime .now () - start ) + cmd_duration
114
119
monitoring .publish_command_failure (
115
120
duration , exc .details , "getMore" , rqst_id , self .__address )
116
121
@@ -121,13 +126,15 @@ def __send_message(self, operation):
121
126
self .__killed = True
122
127
123
128
if publish :
129
+ duration = (datetime .datetime .now () - start ) + cmd_duration
124
130
monitoring .publish_command_failure (
125
131
duration , exc .details , "getMore" , rqst_id , self .__address )
126
132
127
133
client ._reset_server_and_request_check (self .address )
128
134
raise
129
135
130
136
if publish :
137
+ duration = (datetime .datetime .now () - start ) + cmd_duration
131
138
# Must publish in getMore command response format.
132
139
res = {"cursor" : {"id" : doc ["cursor_id" ],
133
140
"ns" : self .__collection .full_name ,
0 commit comments