Skip to content

Commit 001ed49

Browse files
Merge pull request #1068 from ttngu207/jobs.ignore
add "ignore" function to set key's status to "ignore" in jobs table
2 parents baf445a + a26af83 commit 001ed49

File tree

3 files changed

+36
-8
lines changed

3 files changed

+36
-8
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
- Deprecated - `table._update()` PR [#1073](https://github.com/datajoint/datajoint-python/pull/1073)
1414
- Deprecated - old-style foreign key syntax PR [#1073](https://github.com/datajoint/datajoint-python/pull/1073)
1515
- Deprecated - `dj.migrate_dj011_external_blob_storage_to_dj012()` PR [#1073](https://github.com/datajoint/datajoint-python/pull/1073)
16+
* Added - Method to set job keys to "ignore" status - PR [#1068](https://github.com/datajoint/datajoint-python/pull/1068)
1617

1718
### 0.13.8 -- Sep 21, 2022
1819
- Added - New documentation structure based on markdown PR [#1052](https://github.com/datajoint/datajoint-python/pull/1052)

datajoint/jobs.py

+31
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,37 @@ def reserve(self, table_name, key):
8787
return False
8888
return True
8989

90+
def ignore(self, table_name, key):
91+
"""
92+
Set a job to be ignored for computation. When a job is ignored, the job table contains an entry for the
93+
job key, identified by its hash, with status "ignore".
94+
95+
Args:
96+
table_name:
97+
Table name (str) - `database`.`table_name`
98+
key:
99+
The dict of the job's primary key
100+
101+
Returns:
102+
True if ignore job successfully. False = the jobs is already taken
103+
"""
104+
job = dict(
105+
table_name=table_name,
106+
key_hash=key_hash(key),
107+
status="ignore",
108+
host=platform.node(),
109+
pid=os.getpid(),
110+
connection_id=self.connection.connection_id,
111+
key=key,
112+
user=self._user,
113+
)
114+
try:
115+
with config(enable_python_native_blobs=True):
116+
self.insert1(job, ignore_extra_fields=True)
117+
except DuplicateError:
118+
return False
119+
return True
120+
90121
def complete(self, table_name, key):
91122
"""
92123
Log a completed job. When a job is completed, its reservation entry is deleted.

tests/test_autopopulate.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,10 @@ def test_populate_exclude_error_and_ignore_jobs(self):
6060

6161
keys = self.experiment.key_source.fetch("KEY", limit=2)
6262
for idx, key in enumerate(keys):
63-
schema.schema.jobs.insert1(
64-
{
65-
"table_name": self.experiment.table_name,
66-
"key_hash": dj.hash.key_hash(key),
67-
"status": "error" if idx == 0 else "ignore",
68-
"key": key,
69-
}
70-
)
63+
if idx == 0:
64+
schema.schema.jobs.ignore(self.experiment.table_name, key)
65+
else:
66+
schema.schema.jobs.error(self.experiment.table_name, key, "")
7167

7268
self.experiment.populate(reserve_jobs=True)
7369
assert_equal(

0 commit comments

Comments
 (0)