primitive 0.2.27__py3-none-any.whl → 0.2.29__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.27"
4
+ __version__ = "0.2.29"
@@ -4,13 +4,12 @@ from time import sleep
4
4
  from loguru import logger
5
5
 
6
6
  from primitive.__about__ import __version__
7
+ from primitive.agent.runner import Runner
8
+ from primitive.agent.uploader import Uploader
9
+ from primitive.db import sqlite
10
+ from primitive.db.models import JobRun
7
11
  from primitive.utils.actions import BaseAction
8
12
 
9
- from ..db import sqlite
10
- from ..db.models import JobRun
11
- from .runner import Runner
12
- from .uploader import Uploader
13
-
14
13
 
15
14
  class Agent(BaseAction):
16
15
  def execute(
primitive/db/sqlite.py CHANGED
@@ -5,8 +5,8 @@ from loguru import logger
5
5
  from sqlalchemy import Engine, create_engine
6
6
  from sqlalchemy.orm import Session as SQLAlchemySession
7
7
 
8
- from ..utils.cache import get_cache_dir
9
- from .base import Base
8
+ from primitive.db.base import Base
9
+ from primitive.utils.cache import get_cache_dir
10
10
 
11
11
 
12
12
  def init() -> None:
@@ -49,8 +49,10 @@ class Monitor(BaseAction):
49
49
 
50
50
  try:
51
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}")
52
+ if not JobRun.objects.filter_by(job_run_id=job_run_id).exists():
53
+ logger.debug(f"Job run {job_run_id} does not exist in database.")
54
+ logger.debug(f"Creating job run in database: {job_run_id}")
55
+ JobRun.objects.create(job_run_id=job_run_id, pid=None)
54
56
 
55
57
  active_reservation_id = None
56
58
  active_reservation_pk = None
@@ -59,6 +61,22 @@ class Monitor(BaseAction):
59
61
  # FIRST, check for jobs in the database that are running
60
62
  db_job_runs = JobRun.objects.all()
61
63
  for job_run in db_job_runs:
64
+ # first check if the job run completed already
65
+ status = self.primitive.jobs.get_job_status(job_run.job_run_id)
66
+ if status is None or status.data is None:
67
+ logger.error(
68
+ f"Error fetching status of <JobRun {job_run.job_run_id}>."
69
+ )
70
+ continue
71
+
72
+ status_value = status.data["jobRun"]["status"]
73
+ if status_value == "completed":
74
+ logger.debug(
75
+ f"Job run {job_run.job_run_id} is completed. Removing from database."
76
+ )
77
+ JobRun.objects.filter_by(job_run_id=job_run.job_run_id).delete()
78
+ continue
79
+
62
80
  if job_run.pid is None:
63
81
  pid_sleep_amount = 0.1
64
82
  logger.debug(
@@ -68,6 +86,7 @@ class Monitor(BaseAction):
68
86
  f"Sleeping {pid_sleep_amount} seconds before checking again..."
69
87
  )
70
88
  sleep(pid_sleep_amount)
89
+ pid_sleep_amount += 0.1
71
90
  continue
72
91
 
73
92
  logger.debug(
@@ -109,11 +128,14 @@ class Monitor(BaseAction):
109
128
  continue
110
129
 
111
130
  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)
131
+ if len(db_job_runs) == 0:
132
+ # if we get here and we're running in a container,
133
+ # it means the job run is complete and there is nothing left in the database
134
+ # so we can exit
135
+ logger.debug("Running in container, initial job complete.")
136
+ sys.exit(0)
137
+ else:
138
+ continue
117
139
 
118
140
  # Second, check for active reservations
119
141
  hardware = self.primitive.hardware.get_own_hardware_details()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: primitive
3
- Version: 0.2.27
3
+ Version: 0.2.29
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,9 +1,9 @@
1
- primitive/__about__.py,sha256=DiY29pKV2K5D1JKr9jAi4jEELMktClhq9SkZurDA7L0,130
1
+ primitive/__about__.py,sha256=HaB4AohTz2I2snoLFoXHdHwP9yvCohtADZo1dibKpG4,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
5
5
  primitive/agent/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
- primitive/agent/actions.py,sha256=bTzEaMOs5kK8cnJw6VvrGeJNrXmu8rr_-2-87k8uNkg,3786
6
+ primitive/agent/actions.py,sha256=5etkxo1ylmNlgFY3AELnVoTEZamhN-wCb8pdskA2mWM,3831
7
7
  primitive/agent/commands.py,sha256=cK7d3OcN5Z65gQWVZFQ-Y9ddw9Pes4f9OVBpeMsj5sE,255
8
8
  primitive/agent/runner.py,sha256=CoRyReO3jPV8B7vILVWdszFD4GVop7HsVEUo1hoRXjo,14556
9
9
  primitive/agent/uploader.py,sha256=ZzrzsajNBogwEC7mT6Ejy0h2Jd9axMYGzt9pbCvVMlk,3171
@@ -20,7 +20,7 @@ primitive/daemons/launch_service.py,sha256=iuklHeuEqadlf8U1n9xFg4ZG1EKdK2jyaPI-V
20
20
  primitive/daemons/ui.py,sha256=Af3OJWJ0jdGlb1nfA5yaGYdhBEqqpM8zP2U2vUQdCbw,1236
21
21
  primitive/db/base.py,sha256=mH7f2d_jiyxJSSx9Gk53QBXRa3LiKBsBjkFgvmtH1WA,83
22
22
  primitive/db/models.py,sha256=GfnJdAq4Tb68CI4BKAuJDZVqioGavveaAHbCPeLNngw,2840
23
- primitive/db/sqlite.py,sha256=chX4ih_TCn1Y-jJn8WGOC2prqBUIpRUJrUwQ2KaYsko,1659
23
+ primitive/db/sqlite.py,sha256=EJx80xPJ4PP2bso6qPaKys1-jfRTmYi_qYxPaFWM4iI,1679
24
24
  primitive/exec/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
25
25
  primitive/exec/actions.py,sha256=4d_TCjNDcVFoZ9Zw7ZuBa6hKMv2Xzm7_UX_8wcX1aSk,4124
26
26
  primitive/exec/commands.py,sha256=66LO2kkJC-ynNZQpUCXv4Ol15QoacdSZAHblePDcmLo,510
@@ -57,7 +57,7 @@ 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=kgXzj45B-mFZke06pOHdKJ4RTDo32_YRV5hMpS65Pjk,9706
60
+ primitive/monitor/actions.py,sha256=tAeMMOzqdUl6_m6BW_YWEd72Tl9NnfTLPCZyOFR2GUs,10856
61
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
@@ -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.27.dist-info/METADATA,sha256=CaxlEEfLCa1XxJ6ydce8TLWbPShjNVzfrJgUxHn6PXo,3569
100
- primitive-0.2.27.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
101
- primitive-0.2.27.dist-info/entry_points.txt,sha256=p1K8DMCWka5FqLlqP1sPek5Uovy9jq8u51gUsP-z334,48
102
- primitive-0.2.27.dist-info/licenses/LICENSE.txt,sha256=B8kmQMJ2sxYygjCLBk770uacaMci4mPSoJJ8WoDBY_c,1098
103
- primitive-0.2.27.dist-info/RECORD,,
99
+ primitive-0.2.29.dist-info/METADATA,sha256=0bHCQZiRhrgQn7R-xu4zx5Es_7B6wjSCugoAOynW1pI,3569
100
+ primitive-0.2.29.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
101
+ primitive-0.2.29.dist-info/entry_points.txt,sha256=p1K8DMCWka5FqLlqP1sPek5Uovy9jq8u51gUsP-z334,48
102
+ primitive-0.2.29.dist-info/licenses/LICENSE.txt,sha256=B8kmQMJ2sxYygjCLBk770uacaMci4mPSoJJ8WoDBY_c,1098
103
+ primitive-0.2.29.dist-info/RECORD,,