Skip to content

Commit f38df92

Browse files
committed
fixup! fixup! fixup! jira
wip
1 parent d25b50d commit f38df92

File tree

2 files changed

+60
-8
lines changed

2 files changed

+60
-8
lines changed

examples/jira/python/jira_endpoints.py

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,20 @@
88
from typing import Dict, Any, List, Optional
99
import logging
1010
from atlassian import Jira
11-
from mxcp.runtime import config, db
11+
from mxcp.runtime import config, db, on_init, on_shutdown
1212

1313
logger = logging.getLogger(__name__)
1414

15+
# Global JIRA client for reuse across all function calls
16+
jira_client: Optional[Jira] = None
1517

16-
def _get_jira_client() -> Jira:
17-
"""Get configured JIRA client from secrets."""
18+
19+
@on_init
20+
def setup_jira_client():
21+
"""Initialize JIRA client when server starts."""
22+
global jira_client
23+
logger.info("Initializing JIRA client...")
24+
1825
jira_config = config.get_secret("jira")
1926
if not jira_config:
2027
raise ValueError("JIRA configuration not found. Please configure JIRA secrets in your user config.")
@@ -24,12 +31,31 @@ def _get_jira_client() -> Jira:
2431
if missing_keys:
2532
raise ValueError(f"Missing JIRA configuration keys: {', '.join(missing_keys)}")
2633

27-
return Jira(
34+
jira_client = Jira(
2835
url=jira_config["url"],
2936
username=jira_config["username"],
3037
password=jira_config["password"],
3138
cloud=True
3239
)
40+
41+
logger.info("JIRA client initialized successfully")
42+
43+
44+
@on_shutdown
45+
def cleanup_jira_client():
46+
"""Clean up JIRA client when server stops."""
47+
global jira_client
48+
if jira_client:
49+
# JIRA client doesn't need explicit cleanup, but we'll clear the reference
50+
jira_client = None
51+
logger.info("JIRA client cleaned up")
52+
53+
54+
def _get_jira_client() -> Jira:
55+
"""Get the global JIRA client."""
56+
if jira_client is None:
57+
raise RuntimeError("JIRA client not initialized. Make sure the server is started properly.")
58+
return jira_client
3359

3460

3561
def jql_query(query: str, start: Optional[int] = 0, limit: Optional[int] = None) -> List[Dict[str, Any]]:

examples/salesforce/python/salesforce_endpoints.py

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,20 @@
99
import logging
1010
import json
1111
import simple_salesforce
12-
from mxcp.runtime import config
12+
from mxcp.runtime import config, on_init, on_shutdown
1313

1414
logger = logging.getLogger(__name__)
1515

16+
# Global Salesforce client for reuse across all function calls
17+
sf_client: Optional[simple_salesforce.Salesforce] = None
1618

17-
def _get_salesforce_client() -> simple_salesforce.Salesforce:
18-
"""Get configured Salesforce client from secrets."""
19+
20+
@on_init
21+
def setup_salesforce_client():
22+
"""Initialize Salesforce client when server starts."""
23+
global sf_client
24+
logger.info("Initializing Salesforce client...")
25+
1926
sf_config = config.get_secret("salesforce")
2027
if not sf_config:
2128
raise ValueError("Salesforce configuration not found. Please configure Salesforce secrets in your user config.")
@@ -25,13 +32,32 @@ def _get_salesforce_client() -> simple_salesforce.Salesforce:
2532
if missing_keys:
2633
raise ValueError(f"Missing Salesforce configuration keys: {', '.join(missing_keys)}")
2734

28-
return simple_salesforce.Salesforce(
35+
sf_client = simple_salesforce.Salesforce(
2936
username=sf_config["username"],
3037
password=sf_config["password"],
3138
security_token=sf_config["security_token"],
3239
instance_url=sf_config["instance_url"],
3340
client_id=sf_config["client_id"]
3441
)
42+
43+
logger.info("Salesforce client initialized successfully")
44+
45+
46+
@on_shutdown
47+
def cleanup_salesforce_client():
48+
"""Clean up Salesforce client when server stops."""
49+
global sf_client
50+
if sf_client:
51+
# Salesforce client doesn't need explicit cleanup, but we'll clear the reference
52+
sf_client = None
53+
logger.info("Salesforce client cleaned up")
54+
55+
56+
def _get_salesforce_client() -> simple_salesforce.Salesforce:
57+
"""Get the global Salesforce client."""
58+
if sf_client is None:
59+
raise RuntimeError("Salesforce client not initialized. Make sure the server is started properly.")
60+
return sf_client
3561

3662

3763
def soql(query: str) -> List[Dict[str, Any]]:

0 commit comments

Comments
 (0)