class_docstr: Create a monitoring service that alerts on Task failures / completion in a Slack channel
class_docstr_tok: ["Create","a","monitoring","service","that","alerts","on","Task","failures","\/","completion","in","a","Slack","channel"]
docstr: # type: (Task) -> ()
  Called on every Task that we monitor.
  This is where we send the Slack alert
  
  :return: None
docstr_tok: ["#","type",":","(","Task",")","-",">","(",")","Called","on","every","Task","that","we","monitor",".","This","is","where","we","send","the","Slack","alert",":","return",":","None"]
code: def process_task(self, task):
      """
      # type: (Task) -> ()
      Called on every Task that we monitor.
      This is where we send the Slack alert
  
      :return: None
      """
      # skipping failed tasks with low number of iterations
      if (
          self.min_num_iterations
          and task.get_last_iteration() < self.min_num_iterations
      ):
          print(
              "Skipping {} experiment id={}, number of iterations {} < {}".format(
                  task.status,
                  task.id,
                  task.get_last_iteration(),
                  self.min_num_iterations,
              )
          )
          return
      if any(f(task) for f in self.filters):
          if self.verbose:
              print(
                  "Experiment id={} {} did not pass all filters".format(
                      task.id, task.status
                  )
              )
          return
  
      print(
          'Experiment id={} {}, raising alert on channel "{}"'.format(
              task.id, task.status, self.channel
          )
      )
  
      console_output = task.get_reported_console_output(
          number_of_reports=3
      )
      message = (
          "{}Experiment ID <{}|{}> *{}*\nProject: *{}*  -  Name: *{}*\n"
          "```\n{}\n```".format(
              self._message_prefix,
              task.get_output_log_web_page(),
              task.id,
              task.status,
              task.get_project_name(),
              task.name,
              ("\n".join(console_output))[-2048:],
          )
      )
      self.post_message(message, retries=5)
  
file_path: clearml/examples/services/monitoring/slack_alerts.py
imports: import argparse
  import os
  from pathlib import Path
  from time import sleep
  from typing import Optional, Callable, List, Union
  from slack_sdk import WebClient
  from slack_sdk.errors import SlackApiError
  from clearml import Task
  from clearml.automation.monitor import Monitor
label_desc: Use image node_id 5 for calling the SlackMonitor obj's underlying member method code with example usage: obj.process_task(task) without return types