def task_fail_slack_alert(context):
    slack_webhook_token = BaseHook.get_connection(SLACK_CONN_ID).password
    if var_loader.get_git_user() != "cloud-bulldozer":
        print("Task Failed")
        return
    if context.get('task_instance').task_id != "final_status":
        print(context.get('task_instance').task_id, "Task failed")
        return

    slack_msg = """
            :red_circle: DAG Failed {mem} 
            *Task*: {task}  
            *Dag*: {dag} 
            *Execution Time*: {exec_date}  
            *Log Url*: {log_url} 
            """.format(
        task=context.get('task_instance').task_id,
        dag=context.get('task_instance').dag_id,
        mem=alert_members(context),
        ti=context.get('task_instance'),
        exec_date=context.get('execution_date'),
        log_url=get_hyperlink(context),
    )
    failed_alert = SlackWebhookOperator(task_id='slack_test',
                                        http_conn_id='slack',
                                        webhook_token=slack_webhook_token,
                                        message=slack_msg,
                                        username='******',
                                        link_names=True)
    return failed_alert.execute(context=context)
예제 #2
0
 def _get_schedule(self, variant, platform):
     schedules = self.yaml['dagConfig']['schedules']
     if bool(
             schedules.get("enabled", False)
             and var_loader.get_git_user() == "cloud-bulldozer"):
         return variant.get('schedule',
                            schedules.get(platform, schedules['default']))
     else:
         return None
예제 #3
0
    def __init__(self, dag, config: DagConfig, release: OpenshiftRelease, task):
        
        # General DAG Configuration
        self.dag = dag
        self.release = release
        self.config = config
        self.exec_config = executor.get_executor_config_with_cluster_access(self.config, self.release)
    
        # Specific Task Configuration
        self.vars = var_loader.build_task_vars(release, task="index")

        # Upstream task this is to index
        self.task = task 
        self.env = {
            "RELEASE_STREAM": self.release.release_stream,
            "TASK": self.task
        }

        self.git_user = var_loader.get_git_user()
        if self.git_user == 'cloud-bulldozer':
            self.env["ES_INDEX"] = "perf_scale_ci"
        else:
            self.env["ES_INDEX"] = f"{self.git_user}_playground"
 def _git_name(self):
     git_username = var_loader.get_git_user()
     if git_username == 'cloud-bulldozer':
         return f"perf-ci"
     else:
         return f"{git_username}"
 def test_get_git_user(self):
     environ['GIT_REPO'] = "https://github.com/FOO/repo"
     assert var_loader.get_git_user() == "foo"