clerk-sdk 0.2.1__py3-none-any.whl → 0.2.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -24,8 +24,10 @@ global_ws: Union[ClientConnection, None] = None
24
24
  clerk_client = RPAClerk()
25
25
  wss_uri = "wss://agent-manager.f-one.group/action"
26
26
 
27
- CLIENT_TIMEOUT_MINS = 1
28
- MAX_CLIENT_AVAILABILITY_RETRIES = 60
27
+ REMOTE_DEVICE_ALLOCATION_TIMEOUT = int(os.getenv("REMOTE_DEVICE_ALLOCATION_TIMEOUT", 1))
28
+ REMOTE_DEVICE_ALLOCATION_MAX_TRIES = int(
29
+ os.getenv("REMOTE_DEVICE_ALLOCATION_MAX_TRIES", 60)
30
+ )
29
31
 
30
32
 
31
33
  def _allocate_remote_device(
@@ -39,21 +41,21 @@ def _allocate_remote_device(
39
41
  remote_device = clerk_client.allocate_remote_device(
40
42
  group_name=group_name, run_id=run_id
41
43
  )
44
+ os.environ["REMOTE_DEVICE_ID"] = remote_device.id
45
+ os.environ["REMOTE_DEVICE_NAME"] = remote_device.name
46
+ logger.debug(f"Remote device allocated: {remote_device.name}")
47
+ return remote_device
48
+
42
49
  except NoClientsAvailable:
43
50
  logger.warning(
44
- f"No clients are available for {group_name} group. Initiating a {CLIENT_TIMEOUT_MINS} minute wait. Retry count: {retries}"
51
+ f"No clients are available for {group_name} group. Initiating a {REMOTE_DEVICE_ALLOCATION_TIMEOUT} minute wait. Retry count: {retries}"
45
52
  )
46
- retries += 1
47
- if retries == MAX_CLIENT_AVAILABILITY_RETRIES:
53
+ if retries >= REMOTE_DEVICE_ALLOCATION_MAX_TRIES:
48
54
  raise ClientAvailabilityTimeout(
49
- f"No clients available for {group_name} group after {CLIENT_TIMEOUT_MINS*MAX_CLIENT_AVAILABILITY_RETRIES} minutes"
55
+ f"No clients available for {group_name} group after {REMOTE_DEVICE_ALLOCATION_TIMEOUT * REMOTE_DEVICE_ALLOCATION_MAX_TRIES} minutes"
50
56
  )
51
- time.sleep(CLIENT_TIMEOUT_MINS)
52
-
53
- os.environ["REMOTE_DEVICE_ID"] = remote_device.id
54
- os.environ["REMOTE_DEVICE_NAME"] = remote_device.name
55
- logger.debug(f"Remote device allocated: {remote_device.name}")
56
- return remote_device
57
+ time.sleep(REMOTE_DEVICE_ALLOCATION_TIMEOUT * 60)
58
+ retries += 1
57
59
 
58
60
 
59
61
  def _deallocate_target(
@@ -65,7 +67,9 @@ def _deallocate_target(
65
67
  os.environ.pop("REMOTE_DEVICE_NAME", None)
66
68
 
67
69
 
68
- def gui_automation():
70
+ def gui_automation(
71
+ reserve_client: bool = False,
72
+ ):
69
73
  """
70
74
  Decorator that:
71
75
  • Allocates a remote device,
@@ -88,6 +92,7 @@ def gui_automation():
88
92
  @functools.wraps(func)
89
93
  def wrapper(payload: ClerkCodePayload, *args, **kwargs):
90
94
  global global_ws
95
+ force_deallocate = False
91
96
  os.environ["PROC_ID"] = payload.run_id
92
97
 
93
98
  remote_device = _allocate_remote_device(
@@ -116,9 +121,11 @@ def gui_automation():
116
121
 
117
122
  except Exception as e:
118
123
  os.environ.pop("PROC_ID", None)
124
+ force_deallocate = True
119
125
  raise
120
126
  finally:
121
- _deallocate_target(clerk_client, remote_device, payload.run_id)
127
+ if not reserve_client or force_deallocate:
128
+ _deallocate_target(clerk_client, remote_device, payload.run_id)
122
129
 
123
130
  if global_ws and global_ws.state is State.OPEN:
124
131
  close_task = event_loop.create_task(close_ws_connection(global_ws))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: clerk-sdk
3
- Version: 0.2.1
3
+ Version: 0.2.4
4
4
  Summary: Library for interacting with Clerk
5
5
  Home-page: https://github.com/F-ONE-Group/clerk_pypi
6
6
  Author: F-ONE Group
@@ -14,7 +14,7 @@ clerk/gui_automation/client_actor/client_actor.py,sha256=Me3NHc0nMA7Y5CUcnE0ZHT1
14
14
  clerk/gui_automation/client_actor/exception.py,sha256=zdnImHZ88yf52Xq3aMHivEU3aJg-r2c-r8x8XZnI3ic,407
15
15
  clerk/gui_automation/client_actor/model.py,sha256=wVpFCi1w2kh4kAV8oNx489vf_SLUQnqhc02rFD5NIJA,6335
16
16
  clerk/gui_automation/decorators/__init__.py,sha256=OCgXStEumscgT-RyVy5OKS7ml1w9y-lEnjCVnxuRnQs,43
17
- clerk/gui_automation/decorators/gui_automation.py,sha256=efB38zIcHsDubfnRgc_o1MgYEJAH7Sfv9oqKB7toZW4,4690
17
+ clerk/gui_automation/decorators/gui_automation.py,sha256=O0zZTNeJT_eH1AfWt3h7BWWsuZhqoGo_eIzsu0pmzoQ,5061
18
18
  clerk/gui_automation/exceptions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
19
19
  clerk/gui_automation/exceptions/agent_manager.py,sha256=KFWFWQ7X_8Z9XG__SMzb1jKI3yNoVTPJAXzW5O-fSXc,101
20
20
  clerk/gui_automation/exceptions/websocket.py,sha256=-MdwSwlf1hbnu55aDgk3L1znkTZ6xJS6po5VpEGD9ck,117
@@ -42,8 +42,8 @@ clerk/models/response_model.py,sha256=R62daUN1YVOwgnrh_epvFRsQcOwT7R4u97l73egvm-
42
42
  clerk/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
43
43
  clerk/utils/logger.py,sha256=_jYOSEc1WCsY9DvU8cIWUPmz41QNjpHTEZ7WrUnmFPA,3650
44
44
  clerk/utils/save_artifact.py,sha256=Lwl3l3QqKnSFLFpfEEa-dJ-dV9OxvCU3ADkuYZ18U-Q,1117
45
- clerk_sdk-0.2.1.dist-info/licenses/LICENSE,sha256=GTVQl3vH6ht70wJXKC0yMT8CmXKHxv_YyO_utAgm7EA,1065
46
- clerk_sdk-0.2.1.dist-info/METADATA,sha256=QEgrEZmgLaFSscyy0ob9Sr5Y4npmMXFbxF-kPxsk8lE,3508
47
- clerk_sdk-0.2.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
48
- clerk_sdk-0.2.1.dist-info/top_level.txt,sha256=99eQiU6d05_-f41tmSFanfI_SIJeAdh7u9m3LNSfcv4,6
49
- clerk_sdk-0.2.1.dist-info/RECORD,,
45
+ clerk_sdk-0.2.4.dist-info/licenses/LICENSE,sha256=GTVQl3vH6ht70wJXKC0yMT8CmXKHxv_YyO_utAgm7EA,1065
46
+ clerk_sdk-0.2.4.dist-info/METADATA,sha256=QXyRQO8-rueo0kDZJqTiFqQotcnfzQG2JD7O-_LtdUI,3508
47
+ clerk_sdk-0.2.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
48
+ clerk_sdk-0.2.4.dist-info/top_level.txt,sha256=99eQiU6d05_-f41tmSFanfI_SIJeAdh7u9m3LNSfcv4,6
49
+ clerk_sdk-0.2.4.dist-info/RECORD,,