Skip to content

Commit

Permalink
feat: add retry/timeout to base class signatures
Browse files Browse the repository at this point in the history
Toward #221
  • Loading branch information
tseaver committed Oct 13, 2020
1 parent 9f5bbb4 commit 5a1ef50
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 15 deletions.
5 changes: 4 additions & 1 deletion google/cloud/firestore_v1/base_client.py
Expand Up @@ -28,6 +28,7 @@

import google.api_core.client_options # type: ignore
import google.api_core.path_template # type: ignore
from google.api_core import retry as retries # type: ignore
from google.api_core.gapic_v1 import client_info # type: ignore
from google.cloud.client import ClientWithProject # type: ignore

Expand Down Expand Up @@ -358,13 +359,15 @@ def get_all(
references: list,
field_paths: Iterable[str] = None,
transaction: BaseTransaction = None,
retry: retries.Retry = None,
timeout: float = None,
) -> Union[
AsyncGenerator[DocumentSnapshot, Any], Generator[DocumentSnapshot, Any, Any]
]:
raise NotImplementedError

def collections(
self,
self, retry: retries.Retry = None, timeout: float = None,
) -> Union[
AsyncGenerator[BaseCollectionReference, Any],
Generator[BaseCollectionReference, Any, Any],
Expand Down
20 changes: 16 additions & 4 deletions google/cloud/firestore_v1/base_collection.py
Expand Up @@ -15,6 +15,8 @@
"""Classes for representing collections for the Google Cloud Firestore API."""
import random

from google.api_core import retry as retries # type: ignore

from google.cloud.firestore_v1 import _helpers
from google.cloud.firestore_v1.document import DocumentReference
from typing import (
Expand Down Expand Up @@ -147,12 +149,16 @@ def _parent_info(self) -> Tuple[Any, str]:
return parent_path, expected_prefix

def add(
self, document_data: dict, document_id: str = None
self,
document_data: dict,
document_id: str = None,
retry: retries.Retry = None,
timeout: float = None,
) -> Union[Tuple[Any, Any], Coroutine[Any, Any, Tuple[Any, Any]]]:
raise NotImplementedError

def list_documents(
self, page_size: int = None
self, page_size: int = None, retry: retries.Retry = None, timeout: float = None,
) -> Union[
Generator[DocumentReference, Any, Any], AsyncGenerator[DocumentReference, Any]
]:
Expand Down Expand Up @@ -374,14 +380,20 @@ def end_at(
return query.end_at(document_fields)

def get(
self, transaction: Transaction = None
self,
transaction: Transaction = None,
retry: retries.Retry = None,
timeout: float = None,
) -> Union[
Generator[DocumentSnapshot, Any, Any], AsyncGenerator[DocumentSnapshot, Any]
]:
raise NotImplementedError

def stream(
self, transaction: Transaction = None
self,
transaction: Transaction = None,
retry: retries.Retry = None,
timeout: float = None,
) -> Union[Iterator[DocumentSnapshot], AsyncIterator[DocumentSnapshot]]:
raise NotImplementedError

Expand Down
37 changes: 31 additions & 6 deletions google/cloud/firestore_v1/base_document.py
Expand Up @@ -16,6 +16,8 @@

import copy

from google.api_core import retry as retries # type: ignore

from google.cloud.firestore_v1 import _helpers
from google.cloud.firestore_v1 import field_path as field_path_module
from typing import Any, Iterable, NoReturn, Tuple
Expand Down Expand Up @@ -178,26 +180,49 @@ def collection(self, collection_id: str) -> Any:
child_path = self._path + (collection_id,)
return self._client.collection(*child_path)

def create(self, document_data: dict) -> NoReturn:
def create(
self, document_data: dict, retry: retries.Retry = None, timeout: float = None,
) -> NoReturn:
raise NotImplementedError

def set(self, document_data: dict, merge: bool = False) -> NoReturn:
def set(
self,
document_data: dict,
merge: bool = False,
retry: retries.Retry = None,
timeout: float = None,
) -> NoReturn:
raise NotImplementedError

def update(
self, field_updates: dict, option: _helpers.WriteOption = None
self,
field_updates: dict,
option: _helpers.WriteOption = None,
retry: retries.Retry = None,
timeout: float = None,
) -> NoReturn:
raise NotImplementedError

def delete(self, option: _helpers.WriteOption = None) -> NoReturn:
def delete(
self,
option: _helpers.WriteOption = None,
retry: retries.Retry = None,
timeout: float = None,
) -> NoReturn:
raise NotImplementedError

def get(
self, field_paths: Iterable[str] = None, transaction=None
self,
field_paths: Iterable[str] = None,
transaction=None,
retry: retries.Retry = None,
timeout: float = None,
) -> "DocumentSnapshot":
raise NotImplementedError

def collections(self, page_size: int = None) -> NoReturn:
def collections(
self, page_size: int = None, retry: retries.Retry = None, timeout: float = None,
) -> NoReturn:
raise NotImplementedError

def on_snapshot(self, callback) -> NoReturn:
Expand Down
14 changes: 12 additions & 2 deletions google/cloud/firestore_v1/base_query.py
Expand Up @@ -21,6 +21,7 @@
import copy
import math

from google.api_core import retry as retries # type: ignore
from google.protobuf import wrappers_pb2

from google.cloud.firestore_v1 import _helpers
Expand Down Expand Up @@ -800,10 +801,14 @@ def _to_protobuf(self) -> StructuredQuery:

return query.StructuredQuery(**query_kwargs)

def get(self, transaction=None) -> NoReturn:
def get(
self, transaction=None, retry: retries.Retry = None, timeout: float = None,
) -> NoReturn:
raise NotImplementedError

def stream(self, transaction=None) -> NoReturn:
def stream(
self, transaction=None, retry: retries.Retry = None, timeout: float = None,
) -> NoReturn:
raise NotImplementedError

def on_snapshot(self, callback) -> NoReturn:
Expand Down Expand Up @@ -1099,6 +1104,11 @@ def _validate_partition_query(self):
if self._offset:
raise ValueError("Can't partition query with offset.")

def get_partitions(
self, partition_count, retry: retries.Retry = None, timeout: float = None,
) -> NoReturn:
raise NotImplementedError


class QueryPartition:
"""Represents a bounded partition of a collection group query.
Expand Down
9 changes: 7 additions & 2 deletions google/cloud/firestore_v1/base_transaction.py
Expand Up @@ -14,6 +14,7 @@

"""Helpers for applying Google Cloud Firestore changes in a transaction."""

from google.api_core import retry as retries # type: ignore

from google.cloud.firestore_v1 import types
from typing import Any, Coroutine, NoReturn, Optional, Union
Expand Down Expand Up @@ -141,10 +142,14 @@ def _rollback(self) -> NoReturn:
def _commit(self) -> Union[list, Coroutine[Any, Any, list]]:
raise NotImplementedError

def get_all(self, references: list) -> NoReturn:
def get_all(
self, references: list, retry: retries.Retry = None, timeout: float = None,
) -> NoReturn:
raise NotImplementedError

def get(self, ref_or_query) -> NoReturn:
def get(
self, ref_or_query, retry: retries.Retry = None, timeout: float = None,
) -> NoReturn:
raise NotImplementedError


Expand Down

0 comments on commit 5a1ef50

Please sign in to comment.