class_docstr: Trigger Task execution if an event happens in the system.
  
  Examples:
  
  - New model is published/tagged,
  - New Dataset is created,
  - General Task failed,
  - Task metric below/above threshold, alert every X minutes
class_docstr_tok: ["Trigger","Task","execution","if","an","event","happens","in","the","system",".","Examples",":","-","New","model","is","published\/tagged",",","-","New","Dataset","is","created",",","-","General","Task","failed",",","-","Task","metric","below\/above","threshold",",","alert","every","X","minutes"]
docstr: Create a cron job alike scheduling for a pre existing Task or function.
  Trigger the Task/function execution on changes in the dataset repository (notice this is not the hyper-datasets).
  Notice, it is recommended to give the trigger a descriptive unique name. If not provided, a task ID is used.
  
  Notice `task_overrides` can except reference to the trigger model ID:
  example: task_overrides={'Args/dataset_id': '${dataset.id}'}.
  
  Notice if schedule_function is passed, use the following function interface:
  
  .. code-block:: py
  
     def schedule_function(dataset_id):
         pass
  
  
  :param schedule_task_id: Task/task ID to be cloned and scheduled for execution
  :param schedule_queue: Queue name or ID to put the Task into (i.e. schedule)
  :param schedule_function: Optional, instead of providing Task ID to be scheduled,
      provide a function to be called. Notice the function is called from the scheduler context
      (i.e. running on the same machine as the scheduler)
  :param name: Name or description for the cron Task (should be unique if provided otherwise randomly generated)
  :param trigger_project: Only monitor datasets from this specific project (not recursive)
  :param trigger_name: Trigger only on datasets with name matching (regexp)
  :param trigger_on_publish: Trigger when dataset is published.
  :param trigger_on_tags: Trigger when all tags in the list are present
  :param trigger_on_archive: Trigger when dataset is archived
  :param trigger_required_tags: Trigger only on datasets with the
      following additional tags (must include all tags)
  :param target_project: Specify target project to put the cloned scheduled Task in.
  :param add_tag: Add tag to the executed Task. Provide specific tag (str) or
      pass True (default) to use the trigger name as tag
  :param single_instance: If True, do not launch the Task job if the previous instance is still running
      (skip until the next scheduled time period). Default False.
  :param reuse_task: If True, re-enqueue the same Task (i.e. do not clone it) every time, default False.
  :param task_parameters: Configuration parameters to the executed Task.
      For example: {'Args/batch': '12'} Notice: not available when reuse_task=True/
  :param task_overrides: Change task definition.
      For example {'script.version_num': None, 'script.branch': 'main'}. Notice: not available when reuse_task=True
  :return: True if job is successfully added to the scheduling list
docstr_tok: ["Create","a","cron","job","alike","scheduling","for","a","pre","existing","Task","or","function",".","Trigger","the","Task\/function","execution","on","changes","in","the","dataset","repository","(","notice","this","is","not","the","hyper-datasets",")",".","Notice",",","it","is","recommended","to","give","the","trigger","a","descriptive","unique","name",".","If","not","provided",",","a","task","ID","is","used",".","Notice","`","task_overrides","`","can","except","reference","to","the","trigger","model","ID",":","example",":","task_overrides=","{","'Args\/dataset_id","'",":","'","$","{","dataset.id","}","'","}",".","Notice","if","schedule_function","is","passed",",","use","the","following","function","interface",":","..","code-block",":",":","py","def","schedule_function","(","dataset_id",")",":","pass",":","param","schedule_task_id",":","Task\/task","ID","to","be","cloned","and","scheduled","for","execution",":","param","schedule_queue",":","Queue","name","or","ID","to","put","the","Task","into","(","i.e",".","schedule",")",":","param","schedule_function",":","Optional",",","instead","of","providing","Task","ID","to","be","scheduled",",","provide","a","function","to","be","called",".","Notice","the","function","is","called","from","the","scheduler","context","(","i.e",".","running","on","the","same","machine","as","the","scheduler",")",":","param","name",":","Name","or","description","for","the","cron","Task","(","should","be","unique","if","provided","otherwise","randomly","generated",")",":","param","trigger_project",":","Only","monitor","datasets","from","this","specific","project","(","not","recursive",")",":","param","trigger_name",":","Trigger","only","on","datasets","with","name","matching","(","regexp",")",":","param","trigger_on_publish",":","Trigger","when","dataset","is","published",".",":","param","trigger_on_tags",":","Trigger","when","all","tags","in","the","list","are","present",":","param","trigger_on_archive",":","Trigger","when","dataset","is","archived",":","param","trigger_required_tags",":","Trigger","only","on","datasets","with","the","following","additional","tags","(","must","include","all","tags",")",":","param","target_project",":","Specify","target","project","to","put","the","cloned","scheduled","Task","in",".",":","param","add_tag",":","Add","tag","to","the","executed","Task",".","Provide","specific","tag","(","str",")","or","pass","True","(","default",")","to","use","the","trigger","name","as","tag",":","param","single_instance",":","If","True",",","do","not","launch","the","Task","job","if","the","previous","instance","is","still","running","(","skip","until","the","next","scheduled","time","period",")",".","Default","False",".",":","param","reuse_task",":","If","True",",","re-enqueue","the","same","Task","(","i.e",".","do","not","clone","it",")","every","time",",","default","False",".",":","param","task_parameters",":","Configuration","parameters","to","the","executed","Task",".","For","example",":","{","'Args\/batch","'",":","'12","'","}","Notice",":","not","available","when","reuse_task=True\/",":","param","task_overrides",":","Change","task","definition",".","For","example","{","'script.version_num","'",":","None",",","'script.branch","'",":","'main","'","}",".","Notice",":","not","available","when","reuse_task=True",":","return",":","True","if","job","is","successfully","added","to","the","scheduling","list"]
code: def add_dataset_trigger(
      self,
      schedule_task_id=None,  # type: Union[str, Task]
      schedule_queue=None,  # type: str
      schedule_function=None,  # type: Callable[[str], None]
      trigger_project=None,  # type: str
      trigger_name=None,  # type: Optional[str]
      trigger_on_publish=None,  # type: bool
      trigger_on_tags=None,  # type: Optional[List[str]]
      trigger_on_archive=None,  # type: bool
      trigger_required_tags=None,  # type: Optional[List[str]]
      name=None,  # type: Optional[str]
      target_project=None,  # type: Optional[str]
      add_tag=True,  # type: Union[bool, str]
      single_instance=False,  # type: bool
      reuse_task=False,  # type: bool
      task_parameters=None,  # type: Optional[dict]
      task_overrides=None,  # type: Optional[dict]
  ):
      # type: (...) -> None
      """
      Create a cron job alike scheduling for a pre existing Task or function.
      Trigger the Task/function execution on changes in the dataset repository (notice this is not the hyper-datasets).
      Notice, it is recommended to give the trigger a descriptive unique name. If not provided, a task ID is used.
  
      Notice `task_overrides` can except reference to the trigger model ID:
      example: task_overrides={'Args/dataset_id': '${dataset.id}'}.
  
      Notice if schedule_function is passed, use the following function interface:
  
      .. code-block:: py
  
         def schedule_function(dataset_id):
             pass
  
  
      :param schedule_task_id: Task/task ID to be cloned and scheduled for execution
      :param schedule_queue: Queue name or ID to put the Task into (i.e. schedule)
      :param schedule_function: Optional, instead of providing Task ID to be scheduled,
          provide a function to be called. Notice the function is called from the scheduler context
          (i.e. running on the same machine as the scheduler)
      :param name: Name or description for the cron Task (should be unique if provided otherwise randomly generated)
      :param trigger_project: Only monitor datasets from this specific project (not recursive)
      :param trigger_name: Trigger only on datasets with name matching (regexp)
      :param trigger_on_publish: Trigger when dataset is published.
      :param trigger_on_tags: Trigger when all tags in the list are present
      :param trigger_on_archive: Trigger when dataset is archived
      :param trigger_required_tags: Trigger only on datasets with the
          following additional tags (must include all tags)
      :param target_project: Specify target project to put the cloned scheduled Task in.
      :param add_tag: Add tag to the executed Task. Provide specific tag (str) or
          pass True (default) to use the trigger name as tag
      :param single_instance: If True, do not launch the Task job if the previous instance is still running
          (skip until the next scheduled time period). Default False.
      :param reuse_task: If True, re-enqueue the same Task (i.e. do not clone it) every time, default False.
      :param task_parameters: Configuration parameters to the executed Task.
          For example: {'Args/batch': '12'} Notice: not available when reuse_task=True/
      :param task_overrides: Change task definition.
          For example {'script.version_num': None, 'script.branch': 'main'}. Notice: not available when reuse_task=True
      :return: True if job is successfully added to the scheduling list
      """
      if trigger_project:
          trigger_project_list = Task.get_projects(
              name="^{}/\\.datasets/.*".format(trigger_project),
              search_hidden=True,
              _allow_extra_fields_=True,
          )
          for project in trigger_project_list:
              trigger = DatasetTrigger(
                  base_task_id=schedule_task_id,
                  base_function=schedule_function,
                  queue=schedule_queue,
                  name=name,
                  target_project=target_project,
                  single_instance=single_instance,
                  task_parameters=task_parameters,
                  task_overrides=task_overrides,
                  add_tag=(
                      add_tag
                      if isinstance(add_tag, str)
                      else (name or schedule_task_id)
                  )
                  if add_tag
                  else None,
                  clone_task=not bool(reuse_task),
                  match_name=trigger_name,
                  project=project.id,
                  tags=trigger_on_tags,
                  required_tags=trigger_required_tags,
                  on_publish=trigger_on_publish,
                  on_archive=trigger_on_archive,
              )
              trigger.verify()
              self._dataset_triggers.append(trigger)
      else:
          trigger = DatasetTrigger(
              base_task_id=schedule_task_id,
              base_function=schedule_function,
              queue=schedule_queue,
              name=name,
              target_project=target_project,
              single_instance=single_instance,
              task_parameters=task_parameters,
              task_overrides=task_overrides,
              add_tag=(
                  add_tag
                  if isinstance(add_tag, str)
                  else (name or schedule_task_id)
              )
              if add_tag
              else None,
              clone_task=not bool(reuse_task),
              match_name=trigger_name,
              tags=trigger_on_tags,
              required_tags=trigger_required_tags,
              on_publish=trigger_on_publish,
              on_archive=trigger_on_archive,
          )
          trigger.verify()
          self._dataset_triggers.append(trigger)
  
imports: import json
  import logging
  from datetime import datetime
  from threading import enumerate
  from typing import List, Optional, Dict, Union, Callable
  from attr import attrs, attrib
  from .job import ClearmlJob
  from .scheduler import BaseScheduleJob, BaseScheduler, ExecutedJob
  from ..task import Task
  from ..backend_api.session.client import APIClient
  from ..backend_interface.util import datetime_to_isoformat, datetime_from_isoformat
label_desc: Use image node_id 3 for calling the TriggerScheduler obj's underlying member method code with example usage: obj.add_dataset_trigger(schedule_task_id, schedule_queue, schedule_function, trigger_project, trigger_name, trigger_on_publish, trigger_on_tags, trigger_on_archive, trigger_required_tags, name, target_project, add_tag, single_instance, reuse_task, task_parameters, task_overrides) without return types