From 32504b17513c64aa1895146c80609d76af22bd1c Mon Sep 17 00:00:00 2001 From: Thinh Nguyen Date: Mon, 9 Jan 2023 15:50:16 -0600 Subject: [PATCH 1/4] add "ignore" function to set key's status to "ignore" in jobs table --- datajoint/jobs.py | 26 ++++++++++++++++++++++++++ tests/test_autopopulate.py | 12 ++++-------- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/datajoint/jobs.py b/datajoint/jobs.py index cd7f50224..c12f254d1 100644 --- a/datajoint/jobs.py +++ b/datajoint/jobs.py @@ -87,6 +87,32 @@ 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". + + :param table_name: `database`.`table_name` + :param key: the dict of the job's primary key + :return: 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( From 45fb43e6aa8f80700c2ee554361ddc80893ad7fa Mon Sep 17 00:00:00 2001 From: Thinh Nguyen Date: Mon, 9 Jan 2023 16:27:23 -0600 Subject: [PATCH 2/4] formatting --- datajoint/jobs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datajoint/jobs.py b/datajoint/jobs.py index c12f254d1..698a02141 100644 --- a/datajoint/jobs.py +++ b/datajoint/jobs.py @@ -90,7 +90,7 @@ def reserve(self, table_name, key): 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". + job key, identified by its hash, with status "ignore". :param table_name: `database`.`table_name` :param key: the dict of the job's primary key From 3f70c81ea233cb9d4916b29f99c8102c7537dad1 Mon Sep 17 00:00:00 2001 From: Thinh Nguyen Date: Mon, 13 Feb 2023 09:06:39 -0600 Subject: [PATCH 3/4] update docstring format --- datajoint/jobs.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/datajoint/jobs.py b/datajoint/jobs.py index 698a02141..2763d51f4 100644 --- a/datajoint/jobs.py +++ b/datajoint/jobs.py @@ -92,9 +92,14 @@ 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". - :param table_name: `database`.`table_name` - :param key: the dict of the job's primary key - :return: True if ignore job successfully. False = the jobs is already taken + 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, From 67275b0d8b1cda94fbdf54dc317698e5dcf40078 Mon Sep 17 00:00:00 2001 From: Thinh Nguyen Date: Mon, 13 Feb 2023 09:07:53 -0600 Subject: [PATCH 4/4] update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f7922862..21fa55243 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * Bugfix - Activating a schema requires all tables to exist even if `create_tables=False` PR [#1058](https://github.com/datajoint/datajoint-python/pull/1058) * Update - Populate call with `reserve_jobs=True` to exclude `error` and `ignore` keys - PR [#1062](https://github.com/datajoint/datajoint-python/pull/1062) * Add - Support for inserting data with CSV files - PR [#1067](https://github.com/datajoint/datajoint-python/pull/1067) +* Add - Method to set job keys to "ignore" status - PR [#1068](https://github.com/datajoint/datajoint-python/pull/1068) ### 0.13.8 -- Sep 21, 2022 * Add - New documentation structure based on markdown PR [#1052](https://github.com/datajoint/datajoint-python/pull/1052)