Skip to content

Commit 1bbdaff

Browse files
committed
chore: change notif signature: notif_kwargs -> notify_on
1 parent e1603f4 commit 1bbdaff

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

datajoint_utilities/dj_worker/worker.py

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def my_process():
3535
import warnings
3636
from datetime import datetime
3737
import datajoint as dj
38-
from typing import List, Any, Optional, Dict
38+
from typing import List, Any, Optional
3939

4040
from .. import dict_to_uuid
4141
from ..dj_notification.loghandler import PopulateHandler
@@ -200,18 +200,18 @@ def _setup_notifiers(self, notifiers: List[Any]) -> None:
200200
h.addFilter(_f)
201201
self._handler_level_filters[h] = _f
202202

203-
def __call__(self, process, *, notif_kwargs: Optional[Dict[str, bool]] = None, **kwargs):
203+
def __call__(self, process, *, notify_on: Optional[List[str]] = None, **kwargs):
204204
"""
205205
Register a process step. For AutoPopulate tables, optional per-step notification config
206-
can be provided via notif_kwargs. If not provided, the table is not watched.
206+
can be provided via notify_on. If not provided, the table is not watched.
207207
208-
:param notif_kwargs: Optional dict with any of {'on_start','on_success','on_error'} set to bool.
209-
At least one True must be provided to watch; missing keys default to False.
208+
:param notify_on: Optional list of status strings to notify on: ['start', 'success', 'error'].
209+
Empty list or None means don't watch. Invalid statuses are ignored.
210210
"""
211-
self.add_step(process, notif_kwargs=notif_kwargs, **kwargs)
211+
self.add_step(process, notify_on=notify_on, **kwargs)
212212

213213
def add_step(self, callable: callable, position_: int = None, *,
214-
notif_kwargs: Optional[Dict[str, bool]] = None, **kwargs) -> None:
214+
notify_on: Optional[List[str]] = None, **kwargs) -> None:
215215
"""
216216
Add a new process to the list of processes to be executed by this worker.
217217
@@ -225,9 +225,8 @@ def add_step(self, callable: callable, position_: int = None, *,
225225
- A function or method
226226
position_ (int, optional): Position to insert the process in the execution order.
227227
If None, appends to the end. Defaults to None.
228-
notif_kwargs (dict, optional): Per-table notification settings. Use any subset of
229-
{'on_start','on_success','on_error'} with boolean values. Missing keys default to False.
230-
If not provided, the table is not watched. At least one True must be supplied to watch.
228+
notify_on (List[str], optional): List of status strings to notify on: ['start', 'success', 'error'].
229+
Empty list or None means don't watch. Invalid statuses are ignored. Only applies to AutoPopulate tables.
231230
**kwargs: Additional keyword arguments to pass to the process when executed.
232231
233232
Raises:
@@ -249,16 +248,22 @@ def add_step(self, callable: callable, position_: int = None, *,
249248
return
250249

251250
# Handle notification settings for AutoPopulate tables
252-
if self._populate_handler and notif_kwargs is not None:
253-
# Filter to allowed keys and default missing to False; warn on unknown keys
254-
allowed_keys = {"on_start", "on_success", "on_error"}
255-
invalid_keys = set(notif_kwargs.keys()) - allowed_keys
256-
if invalid_keys:
251+
if self._populate_handler and notify_on is not None and len(notify_on) > 0:
252+
# Convert list of status strings to dict format for watch_table
253+
valid_statuses = {"start", "success", "error"}
254+
notify_set = {s.lower() for s in notify_on if isinstance(s, str)}
255+
invalid_statuses = notify_set - valid_statuses
256+
if invalid_statuses:
257257
logger.warning(
258-
f"Ignoring unknown notification keys {sorted(invalid_keys)}; allowed keys are {sorted(allowed_keys)}"
258+
f"Ignoring invalid notification statuses {sorted(invalid_statuses)}; valid statuses are {sorted(valid_statuses)}"
259259
)
260-
flags = {k: bool(notif_kwargs.get(k, False)) for k in allowed_keys}
261-
# Require at least one True to watch
260+
# Build flags dict: True for statuses in list, False otherwise
261+
flags = {
262+
"on_start": "start" in notify_set,
263+
"on_success": "success" in notify_set,
264+
"on_error": "error" in notify_set,
265+
}
266+
# Only watch if at least one status is requested
262267
if any(flags.values()):
263268
full_table_name = callable.full_table_name
264269
self._populate_handler.watch_table(full_table_name, **flags)

0 commit comments

Comments
 (0)