Skip to content

Commit 080b6c0

Browse files
committed
Use insert1 in _insert_job_with_status instead of explicit SQL
1 parent 83b7f49 commit 080b6c0

File tree

1 file changed

+13
-21
lines changed

1 file changed

+13
-21
lines changed

src/datajoint/jobs.py

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -438,27 +438,19 @@ def ignore(self, key: dict) -> None:
438438

439439
def _insert_job_with_status(self, key: dict, status: str) -> None:
440440
"""Insert a new job with the given status."""
441-
pk_attrs = [name for name, _ in self._get_fk_derived_primary_key()]
442-
columns = pk_attrs + ["status", "priority", "created_time", "scheduled_time", "user", "host", "pid", "connection_id"]
443-
444-
pk_values = [f"'{key[attr]}'" if isinstance(key[attr], str) else str(key[attr]) for attr in pk_attrs]
445-
other_values = [
446-
f"'{status}'",
447-
str(DEFAULT_PRIORITY),
448-
"NOW(6)",
449-
"NOW(6)",
450-
f"'{self._user}'",
451-
f"'{platform.node()}'",
452-
str(os.getpid()),
453-
str(self.connection.connection_id),
454-
]
455-
456-
sql = f"""
457-
INSERT INTO {self.full_table_name}
458-
({', '.join(f'`{c}`' for c in columns)})
459-
VALUES ({', '.join(pk_values + other_values)})
460-
"""
461-
self.connection.query(sql)
441+
now = datetime.now()
442+
row = {
443+
**key,
444+
"status": status,
445+
"priority": DEFAULT_PRIORITY,
446+
"created_time": now,
447+
"scheduled_time": now,
448+
"user": self._user,
449+
"host": platform.node(),
450+
"pid": os.getpid(),
451+
"connection_id": self.connection.connection_id,
452+
}
453+
self.insert1(row)
462454

463455
def progress(self) -> dict:
464456
"""

0 commit comments

Comments
 (0)