Skip to content

Commit 17db48f

Browse files
committed
Add 'restart' parameter to test_component and update REST API documentation
1 parent 6b72d08 commit 17db48f

4 files changed

Lines changed: 25 additions & 6 deletions

File tree

docs/python-api.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,13 +277,14 @@ Manages InterSystems IRIS productions and business services, particularly for no
277277
- `target`: Name of the business service in production
278278
- Returns: Business service instance
279279

280-
- `test_component(target: str, message=None, classname: str=None, body=None) -> object`
280+
- `test_component(target: str, message=None, classname: str=None, body=None, restart: bool=False) -> object`
281281
- Test a production component
282282
- Parameters:
283283
- `target`: Component name
284-
- `message`: Optional message instance
284+
- `message`: Optional message instance (local mode only)
285285
- `classname`: Optional message class name
286-
- `body`: Optional message body
286+
- `body`: Optional message body (JSON string or dict)
287+
- `restart`: If `True`, the target component is stopped and restarted before the test message is dispatched (remote mode only)
287288
- Returns: Component response
288289

289290
**Production Logging:**

docs/rest-api.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,8 @@ Sends a test message to a target component and returns the response synchronousl
307307
{
308308
"target": "Python.MyOperation",
309309
"classname": "Python.MyMsg",
310-
"body": {"key": "value"}
310+
"body": {"key": "value"},
311+
"restart": true
311312
}
312313
```
313314

@@ -316,6 +317,7 @@ Sends a test message to a target component and returns the response synchronousl
316317
| `target` | Yes | Config name of the component to invoke |
317318
| `classname` | No | Python message class name. If omitted an empty `Ens.Request` is used. |
318319
| `body` | No | Message body — either a **JSON object** or a **JSON string**. Defaults to `{}`. |
320+
| `restart` | No | If `true`, the target component is stopped and restarted before the message is dispatched. Useful to pick up code changes without restarting the whole production. |
319321

320322
**Response**
321323

src/iop/_remote.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,20 @@ def test_component(
191191
message=None, # ignored remotely — not serialisable over HTTP
192192
classname: Optional[str] = None,
193193
body: Optional[Union[str, dict]] = None,
194+
restart: bool = True,
194195
) -> dict:
195-
"""Returns a dict: {"classname": "...", "body": "...", "truncated": false}"""
196+
"""Returns a dict: {"classname": "...", "body": "...", "truncated": false}.
197+
198+
If *restart* is True the target component is stopped and restarted on
199+
the server before the test message is dispatched.
200+
"""
196201
payload: dict = {"target": target or ""}
197202
if classname:
198203
payload["classname"] = classname
199204
if body is not None:
200205
payload["body"] = body
206+
if restart:
207+
payload["restart"] = True
201208
try:
202209
return self._check_error(self._post("/test", payload))
203210
except requests.exceptions.HTTPError as exc:

src/iop/cls/IOP/Service/Remote/Rest/v1.cls

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,8 @@ ClassMethod GetExport() As %Status
250250
}
251251

252252
/// POST /test
253-
/// Body: {"target":"Python.MyOp", "classname":"Python.MyMsg", "body":"{}", "namespace":"USER"}
253+
/// Body: {"target":"Python.MyOp", "classname":"Python.MyMsg", "body":"{}", "namespace":"USER", "restart":true}
254+
/// If "restart" is true the target component is stopped and restarted before the test message is dispatched. (Default true)
254255
/// Returns: {"classname":"...", "body":"...", "session_id":"..."}
255256
ClassMethod PostTest() As %Status
256257
{
@@ -262,9 +263,17 @@ ClassMethod PostTest() As %Status
262263
Set target = dyna.%Get("target")
263264
Set classname = dyna.%Get("classname")
264265
Set body = dyna.%Get("body")
266+
Set restart = dyna.%Get("restart")
267+
If restart = "" { Set restart = 1 }
265268
Set ns = ..ResolveNs(dyna)
266269
If ns '= "" { Do ..NamespaceCheck(ns) New $NAMESPACE Set $NAMESPACE = ns }
267270

271+
// Optionally restart the target component before testing
272+
If restart {
273+
$$$ThrowOnError(##class(Ens.Director).EnableConfigItem(target, 0, 1))
274+
$$$ThrowOnError(##class(Ens.Director).EnableConfigItem(target, 1, 1))
275+
}
276+
268277
// Normalize body: if it arrived as a JSON object, serialize it to a string
269278
If $isobject(body) { Set body = body.%ToJSON() }
270279

0 commit comments

Comments
 (0)