primitive 0.2.25__py3-none-any.whl → 0.2.26__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.
primitive/__about__.py CHANGED
@@ -1,4 +1,4 @@
1
1
  # SPDX-FileCopyrightText: 2024-present Dylan Stein <dylan@primitive.tech>
2
2
  #
3
3
  # SPDX-License-Identifier: MIT
4
- __version__ = "0.2.25"
4
+ __version__ = "0.2.26"
@@ -1,5 +1,6 @@
1
1
  import sys
2
2
  from time import sleep
3
+ from typing import Optional
3
4
 
4
5
  import psutil
5
6
  from loguru import logger
@@ -12,7 +13,7 @@ from primitive.utils.exceptions import P_CLI_100
12
13
 
13
14
 
14
15
  class Monitor(BaseAction):
15
- def start(self):
16
+ def start(self, job_run_id: Optional[str] = None):
16
17
  logger.remove()
17
18
  logger.add(
18
19
  sink=sys.stderr,
@@ -24,21 +25,33 @@ class Monitor(BaseAction):
24
25
  logger.info("[*] primitive monitor")
25
26
  logger.info(f"[*] Version: {__version__}")
26
27
 
27
- try:
28
- # hey stupid:
29
- # do not set is_available to True here, it will mess up the reservation logic
30
- # only set is_available after we've checked that no active reservation is present
31
- # setting is_available of the parent also effects the children,
32
- # which may have active reservations as well
33
- self.primitive.hardware.check_in_http(is_online=True)
34
- except Exception as exception:
35
- logger.exception(f"Error checking in hardware: {exception}")
36
- sys.exit(1)
28
+ # TODO: tighten logic for determining if we're running in a container
29
+ RUNNING_IN_CONTAINER = False
30
+ if job_run_id is not None:
31
+ logger.info("[*] Running in container...")
32
+ RUNNING_IN_CONTAINER = True
33
+
34
+ # can't check if if it is a container
35
+ if not RUNNING_IN_CONTAINER:
36
+ try:
37
+ # hey stupid:
38
+ # do not set is_available to True here, it will mess up the reservation logic
39
+ # only set is_available after we've checked that no active reservation is present
40
+ # setting is_available of the parent also effects the children,
41
+ # which may have active reservations as well
42
+ self.primitive.hardware.check_in_http(is_online=True)
43
+ except Exception as exception:
44
+ logger.exception(f"Error checking in hardware: {exception}")
45
+ sys.exit(1)
37
46
 
38
47
  # Initialize the database
39
48
  sqlite.init()
40
49
 
41
50
  try:
51
+ if job_run_id is not None:
52
+ JobRun.objects.create(job_run_id=job_run_id, pid=None)
53
+ logger.debug(f"Creating job run in database: {job_run_id}")
54
+
42
55
  active_reservation_id = None
43
56
  active_reservation_pk = None
44
57
 
@@ -95,6 +108,13 @@ class Monitor(BaseAction):
95
108
  sleep(1)
96
109
  continue
97
110
 
111
+ if RUNNING_IN_CONTAINER:
112
+ # if we get here and we're running in a container,
113
+ # it means the job run is complete and there is nothing left in the database
114
+ # so we can exit
115
+ logger.debug("Running in container, initial job complete.")
116
+ sys.exit(0)
117
+
98
118
  # Second, check for active reservations
99
119
  hardware = self.primitive.hardware.get_own_hardware_details()
100
120
  if hardware["activeReservation"]:
@@ -189,9 +209,10 @@ class Monitor(BaseAction):
189
209
  except KeyboardInterrupt:
190
210
  logger.info("[*] Stopping primitive monitor...")
191
211
  try:
192
- self.primitive.hardware.check_in_http(
193
- is_available=False, is_online=False, stopping_agent=True
194
- )
212
+ if not RUNNING_IN_CONTAINER:
213
+ self.primitive.hardware.check_in_http(
214
+ is_available=False, is_online=False, stopping_agent=True
215
+ )
195
216
 
196
217
  except P_CLI_100 as exception:
197
218
  logger.error("[*] Error stopping primitive monitor.")
@@ -1,13 +1,15 @@
1
+ from typing import TYPE_CHECKING, Optional
2
+
1
3
  import click
2
- import typing
3
4
 
4
- if typing.TYPE_CHECKING:
5
+ if TYPE_CHECKING:
5
6
  from ..client import Primitive
6
7
 
7
8
 
8
9
  @click.command("monitor")
10
+ @click.option("--job-run-id", type=str, help="Explicit Job Run to pull")
9
11
  @click.pass_context
10
- def cli(context):
12
+ def cli(context, job_run_id: Optional[str] = None):
11
13
  """monitor"""
12
14
  primitive: Primitive = context.obj.get("PRIMITIVE")
13
- primitive.monitor.start()
15
+ primitive.monitor.start(job_run_id=job_run_id)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: primitive
3
- Version: 0.2.25
3
+ Version: 0.2.26
4
4
  Project-URL: Documentation, https://github.com//primitivecorp/primitive-cli#readme
5
5
  Project-URL: Issues, https://github.com//primitivecorp/primitive-cli/issues
6
6
  Project-URL: Source, https://github.com//primitivecorp/primitive-cli
@@ -1,4 +1,4 @@
1
- primitive/__about__.py,sha256=emMCm4cHzvmdYDOL83iUzQz3eDl0L-1JkrP95MpoyT8,130
1
+ primitive/__about__.py,sha256=oMpyVg2UpvXjSCtuQGv9QEUGqwIl1DtBLRAtQa5pBhE,130
2
2
  primitive/__init__.py,sha256=bwKdgggKNVssJFVPfKSxqFMz4IxSr54WWbmiZqTMPNI,106
3
3
  primitive/cli.py,sha256=g7EtHI9MATAB0qQu5w-WzbXtxz_8zu8z5E7sETmMkKU,2509
4
4
  primitive/client.py,sha256=h8WZVnQylVe0vbpuyC8YZHl2JyITSPC-1HbUcmrE5pc,3623
@@ -57,8 +57,8 @@ primitive/jobs/graphql/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3
57
57
  primitive/jobs/graphql/fragments.py,sha256=1_ZttT7dx36KDC3DClJz9M8LMpsPwXySBygHSiUEcGg,619
58
58
  primitive/jobs/graphql/mutations.py,sha256=8ASvCmwQh7cMeeiykOdYaYVryG8FRIuVF6v_J8JJZuw,219
59
59
  primitive/jobs/graphql/queries.py,sha256=BrU_GnLjK0bTAmWsLSmGEUea7EM8MqTKxN1Qp6sSjwc,1597
60
- primitive/monitor/actions.py,sha256=GUQrwuan82pOJ5gI2FvQYzgDoP4fs28PdcI_fg_aXRs,8692
61
- primitive/monitor/commands.py,sha256=dZsD8WKGU4OYO_AlKawfeRNVTMN0xJ-DFRkmKTS464s,258
60
+ primitive/monitor/actions.py,sha256=Fem8i-I1CZnLGNCHq8gKqURTHUtfmYEJ9h5zAv1wD18,9726
61
+ primitive/monitor/commands.py,sha256=VDlEL_Qpm_ysHxug7VpI0cVAZ0ny6AS91Y58D7F1zkU,409
62
62
  primitive/organizations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
63
63
  primitive/organizations/actions.py,sha256=kVHOhG1oS2sI5p8uldSo5L-RUZsnG36eaulVuKLyZ-M,1863
64
64
  primitive/organizations/commands.py,sha256=_dwgVEJCqMa5VgB_7P1wLPFc0AuT1p9dtyR9JRr4kpw,487
@@ -96,8 +96,8 @@ primitive/utils/memory_size.py,sha256=4xfha21kW82nFvOTtDFx9Jk2ZQoEhkfXii-PGNTpIU
96
96
  primitive/utils/printer.py,sha256=f1XUpqi5dkTL3GWvYRUGlSwtj2IxU1q745T4Fxo7Tn4,370
97
97
  primitive/utils/shell.py,sha256=jWzb7ky7p987dJas6ZvarK3IJNZ5cwBXcryRWb9Uh6U,2072
98
98
  primitive/utils/text.py,sha256=XiESMnlhjQ534xE2hMNf08WehE1SKaYFRNih0MmnK0k,829
99
- primitive-0.2.25.dist-info/METADATA,sha256=KzAEz2pPIFN5lBO7_7jERQ7oIL1trv05Jjqdp8icC9w,3569
100
- primitive-0.2.25.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
101
- primitive-0.2.25.dist-info/entry_points.txt,sha256=p1K8DMCWka5FqLlqP1sPek5Uovy9jq8u51gUsP-z334,48
102
- primitive-0.2.25.dist-info/licenses/LICENSE.txt,sha256=B8kmQMJ2sxYygjCLBk770uacaMci4mPSoJJ8WoDBY_c,1098
103
- primitive-0.2.25.dist-info/RECORD,,
99
+ primitive-0.2.26.dist-info/METADATA,sha256=IJmRQR_Wu5dMULSvjr_n0Pp5CIFDMGlrixZAuxtVUJ0,3569
100
+ primitive-0.2.26.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
101
+ primitive-0.2.26.dist-info/entry_points.txt,sha256=p1K8DMCWka5FqLlqP1sPek5Uovy9jq8u51gUsP-z334,48
102
+ primitive-0.2.26.dist-info/licenses/LICENSE.txt,sha256=B8kmQMJ2sxYygjCLBk770uacaMci4mPSoJJ8WoDBY_c,1098
103
+ primitive-0.2.26.dist-info/RECORD,,