diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ba78a8d0..29b1bb58b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/datajoint/jobs.py b/datajoint/jobs.py index cd7f50224..2763d51f4 100644 --- a/datajoint/jobs.py +++ b/datajoint/jobs.py @@ -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. diff --git a/tests/test_autopopulate.py b/tests/test_autopopulate.py index 1ba2785fc..bc0c9bb18 100644 --- a/tests/test_autopopulate.py +++ b/tests/test_autopopulate.py @@ -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(