From 69745d6322151c231a87e8648df0a54cebdb6815 Mon Sep 17 00:00:00 2001 From: yair Date: Wed, 16 Oct 2024 10:51:26 +0300 Subject: [PATCH] jira multiple sessions --- integrations/jira/jira/client.py | 17 +++++++++-------- integrations/jira/poetry.lock | 8 ++++---- integrations/jira/pyproject.toml | 4 ++-- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/integrations/jira/jira/client.py b/integrations/jira/jira/client.py index 1fe111f9b..f0bedad6c 100644 --- a/integrations/jira/jira/client.py +++ b/integrations/jira/jira/client.py @@ -1,4 +1,5 @@ import typing +from contextlib import asynccontextmanager from typing import Any, AsyncGenerator import aiohttp @@ -38,8 +39,14 @@ def __init__(self, jira_url: str, jira_email: str, jira_token: str) -> None: self.api_url = f"{self.jira_rest_url}/api/3" self.webhooks_url = f"{self.jira_rest_url}/webhooks/1.0/webhook" - def _create_session(self): - return aiohttp.ClientSession(auth=self.jira_api_auth, timeout=ClientTimeout(30)) + @asynccontextmanager + async def _create_session(self): + try: + session = aiohttp.ClientSession(auth=self.jira_api_auth, timeout=ClientTimeout(30)) + yield session + finally: + await session.close() + @staticmethod def _generate_base_req_params( @@ -55,14 +62,12 @@ async def _get_paginated_projects(self, params: dict[str, Any]) -> dict[str, Any async with session.get( f"{self.api_url}/project/search", params=params ) as project_response: - await session.close() project_response.raise_for_status() return await project_response.json() async def _get_paginated_issues(self, params: dict[str, Any]) -> dict[str, Any]: async with self._create_session() as session: async with session.get(f"{self.api_url}/search", params=params) as issue_response: - await session.close() issue_response.raise_for_status() return await issue_response.json() @@ -70,7 +75,6 @@ async def create_events_webhook(self, app_host: str) -> None: webhook_target_app_host = f"{app_host}/integration/webhook" async with self._create_session() as session: async with session.get(f"{self.webhooks_url}") as webhook_check_response: - await session.close() webhook_check_response.raise_for_status() webhook_check = await webhook_check_response.json() @@ -87,7 +91,6 @@ async def create_events_webhook(self, app_host: str) -> None: async with self._create_session() as session: async with session.post(f"{self.webhooks_url}", json=body) as webhook_create_response: - await session.close() webhook_create_response.raise_for_status() logger.info("Ocean real time reporting webhook created") @@ -96,7 +99,6 @@ async def get_single_project(self, project_key: str) -> dict[str, Any]: async with session.get( f"{self.api_url}/project/{project_key}" ) as project_response: - await session.close() project_response.raise_for_status() return await project_response.json() @@ -126,7 +128,6 @@ async def get_paginated_projects( async def get_single_issue(self, issue_key: str) -> dict[str, Any]: async with self._create_session() as session: async with session.get(f"{self.api_url}/issue/{issue_key}") as issue_response: - await session.close() issue_response.raise_for_status() return await issue_response.json() diff --git a/integrations/jira/poetry.lock b/integrations/jira/poetry.lock index ef44545a6..10f7dd38d 100644 --- a/integrations/jira/poetry.lock +++ b/integrations/jira/poetry.lock @@ -1334,13 +1334,13 @@ testing = ["pytest", "pytest-benchmark"] [[package]] name = "port-ocean" -version = "0.12.2.dev14" +version = "0.12.2.dev15" description = "Port Ocean is a CLI tool for managing your Port projects." optional = false python-versions = "<4.0,>=3.11" files = [ - {file = "port_ocean-0.12.2.dev14-py3-none-any.whl", hash = "sha256:fd83d95235d035422ef0fae9fbdac064c262a2303deae837d087660872689bb0"}, - {file = "port_ocean-0.12.2.dev14.tar.gz", hash = "sha256:bdd9c0f1f941f0c3226cd25d9f1b3e415cc5e59acf3f84ba9fa22162ae2e5fc6"}, + {file = "port_ocean-0.12.2.dev15-py3-none-any.whl", hash = "sha256:0c400772ed6786ee457ae55835699a074bbc902839b6ab992ef00fd1d23ea395"}, + {file = "port_ocean-0.12.2.dev15.tar.gz", hash = "sha256:aeb27db1f25ee626d9ea4f7eb49d1a6503fc365e910438b015a0b1fa5e7417cb"}, ] [package.dependencies] @@ -2445,4 +2445,4 @@ propcache = ">=0.2.0" [metadata] lock-version = "2.0" python-versions = "^3.11" -content-hash = "d04313a4c49637a16b84892c8ca4353c00358ebc852a0f6bfaba4cd75ca2e592" +content-hash = "a294b3f42090967a07e69dd6d95d2e5795d7c766ed3fea6449c933afcb63c1e5" diff --git a/integrations/jira/pyproject.toml b/integrations/jira/pyproject.toml index 2f7863979..a737ef6c6 100644 --- a/integrations/jira/pyproject.toml +++ b/integrations/jira/pyproject.toml @@ -1,12 +1,12 @@ [tool.poetry] name = "jira" -version = "0.1.89-dev022" +version = "0.1.89-dev023" description = "Integration to bring information from Jira into Port" authors = ["Mor Paz "] [tool.poetry.dependencies] python = "^3.11" -port_ocean = {version = "0.12.2-dev14", extras = ["cli"]} +port_ocean = {version = "0.12.2-dev15", extras = ["cli"]} httpx = "^0.27.0" [tool.poetry.group.dev.dependencies]