Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add "ignore" function to set key's status to "ignore" in jobs table #1068

Merged
merged 5 commits into from
Feb 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- Deprecated - `table._update()` PR [#1073](https://github.com/datajoint/datajoint-python/pull/1073)
- Deprecated - old-style foreign key syntax PR [#1073](https://github.com/datajoint/datajoint-python/pull/1073)
- Deprecated - `dj.migrate_dj011_external_blob_storage_to_dj012()` PR [#1073](https://github.com/datajoint/datajoint-python/pull/1073)
* Added - Method to set job keys to "ignore" status - PR [#1068](https://github.com/datajoint/datajoint-python/pull/1068)

### 0.13.8 -- Sep 21, 2022
- Added - New documentation structure based on markdown PR [#1052](https://github.com/datajoint/datajoint-python/pull/1052)
Expand Down
31 changes: 31 additions & 0 deletions datajoint/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,37 @@ def reserve(self, table_name, key):
return False
return True

def ignore(self, table_name, key):
"""
Set a job to be ignored for computation. When a job is ignored, the job table contains an entry for the
job key, identified by its hash, with status "ignore".

Args:
table_name:
Table name (str) - `database`.`table_name`
key:
The dict of the job's primary key

Returns:
True if ignore job successfully. False = the jobs is already taken
"""
job = dict(
table_name=table_name,
key_hash=key_hash(key),
status="ignore",
host=platform.node(),
pid=os.getpid(),
connection_id=self.connection.connection_id,
key=key,
user=self._user,
)
try:
with config(enable_python_native_blobs=True):
self.insert1(job, ignore_extra_fields=True)
except DuplicateError:
return False
return True

def complete(self, table_name, key):
"""
Log a completed job. When a job is completed, its reservation entry is deleted.
Expand Down
12 changes: 4 additions & 8 deletions tests/test_autopopulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,10 @@ def test_populate_exclude_error_and_ignore_jobs(self):

keys = self.experiment.key_source.fetch("KEY", limit=2)
for idx, key in enumerate(keys):
schema.schema.jobs.insert1(
{
"table_name": self.experiment.table_name,
"key_hash": dj.hash.key_hash(key),
"status": "error" if idx == 0 else "ignore",
"key": key,
}
)
if idx == 0:
schema.schema.jobs.ignore(self.experiment.table_name, key)
else:
schema.schema.jobs.error(self.experiment.table_name, key, "")

self.experiment.populate(reserve_jobs=True)
assert_equal(
Expand Down