MCPcopy Index your code
hub / github.com/couchbase/couchbase-python-client / pop

Method pop

acouchbase/datastructures.py:965–1028  ·  view source on GitHub ↗

Pop an item from the queue. :param value: Value to remove :raise: :cb_exc:`DocumentNotFoundException` if the set does not exist. .. seealso:: :meth:`set_add`, :meth:`map_add`

(self, timeout: Optional[timedelta] = None)

Source from the content-addressed store, hash-verified

963 create_type=True)
964
965 async def pop(self, timeout: Optional[timedelta] = None) -> Any:
966 """
967 Pop an item from the queue.
968
969 :param value: Value to remove
970 :raise: :cb_exc:`DocumentNotFoundException` if the set does not exist.
971
972 .. seealso:: :meth:`set_add`, :meth:`map_add`
973 """
974 op_type = DatastructureOperationType.QueuePop
975 async with ObservableRequestHandler(op_type, self._impl.observability_instruments) as ds_obs_handler:
976 ds_obs_handler.create_kv_span(self._impl._request_builder._collection_dtls.get_details_as_dict())
977 if timeout is None:
978 timeout = timedelta(seconds=10)
979
980 timeout_millis = timeout.total_seconds() * 1000
981
982 interval_millis = float(50)
983 start = time.perf_counter()
984 time_left = timeout_millis
985 parent_span = ds_obs_handler.wrapped_span
986 lookup_in_op_type = KeyValueOperationType.LookupIn
987 mutate_in_op_type = KeyValueOperationType.MutateIn
988 while True:
989 try:
990
991 async with ObservableRequestHandler(lookup_in_op_type,
992 self._impl.observability_instruments) as obs_handler:
993 op = subdoc_get('[-1]')
994 lookup_in_req, tc = self._impl.request_builder.build_lookup_in_request(self._key,
995 (op,),
996 obs_handler,
997 parent_span=parent_span)
998 sd_res = await self._impl.lookup_in(lookup_in_req, tc, obs_handler)
999 val = sd_res.value[0].get('value', None)
1000
1001 async with ObservableRequestHandler(mutate_in_op_type,
1002 self._impl.observability_instruments) as obs_handler:
1003 try:
1004 op = remove('[-1]')
1005 mutate_in_opts = MutateInOptions(cas=sd_res.cas, parent_span=parent_span)
1006 mutate_in_req = self._impl.request_builder.build_mutate_in_request(self._key,
1007 (op,),
1008 obs_handler,
1009 mutate_in_opts)
1010 await self._impl.mutate_in(mutate_in_req, obs_handler)
1011 return val
1012 except CasMismatchException:
1013 pass
1014
1015 interval_millis += 500
1016 if interval_millis > 1000:
1017 interval_millis = 1000
1018
1019 time_left = timeout_millis - ((time.perf_counter() - start) * 1000)
1020 if interval_millis > time_left:
1021 interval_millis = time_left
1022

Callers 15

__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
runMethod · 0.45
__init__Method · 0.45
use_callbackMethod · 0.45
use_errbackMethod · 0.45
fn_failureMethod · 0.45
use_callbackMethod · 0.45
use_errbackMethod · 0.45

Calls 13

removeFunction · 0.90
MutateInOptionsClass · 0.90
QueueEmptyClass · 0.90
get_details_as_dictMethod · 0.80
create_kv_spanMethod · 0.45
lookup_inMethod · 0.45
getMethod · 0.45
mutate_inMethod · 0.45

Tested by 7

test_queueMethod · 0.36
get_environmentMethod · 0.36
test_user_and_groupsMethod · 0.36
test_kv_ds_queueMethod · 0.36
test_kv_ds_queueMethod · 0.36