Skip to content

Commit

Permalink
Update with try catch
Browse files Browse the repository at this point in the history
  • Loading branch information
vladyslav-huriev committed Feb 1, 2024
1 parent 901f654 commit 2846fa0
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 58 deletions.
56 changes: 29 additions & 27 deletions Salesforce/client/http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,34 +241,36 @@ async def update_limiters(self) -> None:

client_uuid = self.get_unique_client_key(self.client_id, self.client_secret)

# try:
async with (self.session(client_uuid) as session):
async with session.get(request_url, headers=headers, json={}) as response:
await self._handle_error_response(response)

result = await response.json()

daily_requests: int | None = result.get("DailyApiRequests", {}).get("Max")
logger.info("Found limits for DailyApiRequests {0}".format(daily_requests))
if daily_requests is not None:
self.set_rate_limiter(client_uuid, AsyncLimiter(daily_requests, 60 * 60 * 24), LimiterType.DAILY)

hourly_managed_content_public_requests: int | None = result.get(
"HourlyManagedContentPublicRequests", {}
).get("Max")
logger.info(
"Found limits for HourlyManagedContentPublicRequests {0}".format(
hourly_managed_content_public_requests
)
)
if hourly_managed_content_public_requests is not None:
self.set_rate_limiter(
client_uuid,
AsyncLimiter(hourly_managed_content_public_requests, 60 * 60),
LimiterType.HOURLY_MANAGED,
try:
async with self.session(client_uuid) as session:
async with session.get(request_url, headers=headers, json={}) as response:
await self._handle_error_response(response)

result = await response.json()

daily_requests: int | None = result.get("DailyApiRequests", {}).get("Max")
logger.info("Found limits for DailyApiRequests {0}".format(daily_requests))
if daily_requests is not None:
self.set_rate_limiter(
client_uuid, AsyncLimiter(daily_requests, 60 * 60 * 24), LimiterType.DAILY
)

hourly_managed_content_public_requests: int | None = result.get(
"HourlyManagedContentPublicRequests", {}
).get("Max")
logger.info(
"Found limits for HourlyManagedContentPublicRequests {0}".format(
hourly_managed_content_public_requests
)
)
# except Exception:
# logger.info("Cannot update daily and hourly limits for connector")
if hourly_managed_content_public_requests is not None:
self.set_rate_limiter(
client_uuid,
AsyncLimiter(hourly_managed_content_public_requests, 60 * 60),
LimiterType.HOURLY_MANAGED,
)
except Exception:
logger.info("Cannot update daily and hourly limits for connector")

Check warning on line 273 in Salesforce/client/http_client.py

View check run for this annotation

Codecov / codecov/patch

Salesforce/client/http_client.py#L272-L273

Added lines #L272 - L273 were not covered by tests

async def get_log_files(self, start_from: datetime | None = None) -> SalesforceEventLogFilesResponse:
"""
Expand Down
71 changes: 42 additions & 29 deletions Salesforce/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Salesforce/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ aiolimiter = "^1.1.0"
aiocsv = "^1.2.4"

[tool.poetry.dev-dependencies]
pytest = "*"
pytest = "7.4.3"
pytest-cov = "*"
pytest-asyncio = "*"
pytest-xdist = "*"
Expand All @@ -27,7 +27,7 @@ Faker = "^13.12.0"
aioresponses = "^0.7.4"
autoflake = "^1.4"
isort = "^5.10.1"
black = "^22.3.0"
black = { version = "^24.1.1", extras = ["colorama"] }
mypy = "^1.8.0"
types-aiofiles = "^23.1.0.4"
types-python-dateutil = "^2.8.19.13"
Expand Down

0 comments on commit 2846fa0

Please sign in to comment.