1cadumagalhaes commented on issue #46838:
URL: https://github.com/apache/airflow/issues/46838#issuecomment-2664324425

   So, in my instance I've set the notifier to get information from the 
task_instance context.
   
   <img width="531" alt="Image" 
src="https://github.com/user-attachments/assets/857553be-201a-4a98-9c44-5fc375268c68";
 />
   
   I've added a few new fields, so the developer/user can use them to overwrite 
any of these values
   ```py
           self.success = success
           self.success_color = success_color
           self.failure_color = failure_color
           self.mentions = mentions
           self.mention_everyone = mention_everyone
           self.mention_roles = mention_roles
           self.mention_channels = mention_channels
           self.application_id = application_id
           self.dag_name = None
           self.task_name = None
           self.duration = None
           self.failure_link = None
           self.success_link = None
           self.reactions = None
           self.proxy = None
           self.embeds = None
           self.description = description
   ```
   
   And I've used the task_instance to get some of the informations I wanted to 
display
   ```py
       def notify(self, context):
           """Send a message to a Discord channel."""
           task_instance = context.get("task_instance")
           if task_instance:
               self.dag_name = task_instance.dag_id.replace("_", "\\_")
               self.task_name = task_instance.task_id
               self.duration = str(task_instance.duration)
               self.failure_link = 
f"https://localhost:8080/dags/{task_instance.dag_id}/grid?task_id={task_instance.task_id}&tab=logs&dag_run_id={urlencode({'dag_run_id':
 task_instance.run_id.replace('+', '%2B')})}"
               self.success_link = 
f"https://localhost:8080/dags/{task_instance.dag_id}/grid?task_id={task_instance.task_id}&tab=logs&dag_run_id={urlencode({'dag_run_id':
 task_instance.run_id.replace('+', '%2B')})}"
   ```
   
   I'm not sure if this is the best approach for the project as a whole, since 
what I did basically was to generate the embed in the notifier and pass it to 
the hook. Maybe we could have a discussion on what could be important to 
display in a _suggested default_ notification from airflow, and let the users 
customize it if they want. 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to