Skip to content

Commit 32504b1

Browse files
authored
add "ignore" function to set key's status to "ignore" in jobs table
1 parent 3b6e845 commit 32504b1

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

datajoint/jobs.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,32 @@ 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+
:param table_name: `database`.`table_name`
96+
:param key: the dict of the job's primary key
97+
:return: True if ignore job successfully. False = the jobs is already taken
98+
"""
99+
job = dict(
100+
table_name=table_name,
101+
key_hash=key_hash(key),
102+
status="ignore",
103+
host=platform.node(),
104+
pid=os.getpid(),
105+
connection_id=self.connection.connection_id,
106+
key=key,
107+
user=self._user,
108+
)
109+
try:
110+
with config(enable_python_native_blobs=True):
111+
self.insert1(job, ignore_extra_fields=True)
112+
except DuplicateError:
113+
return False
114+
return True
115+
90116
def complete(self, table_name, key):
91117
"""
92118
Log a completed job. When a job is completed, its reservation entry is deleted.

tests/test_autopopulate.py

Lines changed: 4 additions & 8 deletions
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)