Giter Club home page Giter Club logo

Comments (2)

lTimej avatar lTimej commented on June 1, 2024
监控指标:
    1.执行中失败的任务
    2.执行中的任务

from bk-sops.

lTimej avatar lTimej commented on June 1, 2024

执行失败任务sql

SELECT
	* 
FROM
	taskflow3_taskflowinstance AS t1
	INNER JOIN (
	SELECT
		pp.id 
	FROM
		pipeline_pipelineinstance AS pp
		INNER JOIN eri_state AS es ON pp.instance_id = es.root_id 
	WHERE
		es.NAME = "Failed" 
		AND pp.is_started = 1 
		AND pp.is_finished = 0 
		AND pp.is_revoked = 0 
		AND pp.is_expired = 0 
		AND is_deleted = 0 
	GROUP BY
		es.root_id,
		pp.id 
	ORDER BY
		pp.id 
	) AS t2 ON t1.pipeline_instance_id = t2.id;

执行失败任务ORM

# 过滤出失败的节点,根据节点分组
        states = [state["root_id"] for state in State.objects.filter(name="FAILED").annotate(count=Count("root_id")).values("root_id")]
        # 查出失败的节点任务
        tasks = TaskFlowInstance.objects.filter(
            pipeline_instance__instance_id__in=states,
            pipeline_instance__is_started=True,
            pipeline_instance__is_finished=False,
            pipeline_instance__is_revoked=False,
            pipeline_instance__is_expired=False,
            pipeline_instance__is_deleted=False,
            is_deleted=False,
        ).values(
            "project__name", 
            "pipeline_instance__name",
            "pipeline_instance__start_time",
        )

执行中任务sql

SELECT
	* 
FROM
	taskflow3_taskflowinstance AS t1
	INNER JOIN (
	SELECT
		pp.id,
		COUNT( es.root_id ) AS total_count,
		SUM( CASE WHEN es.NAME = 'Failed' THEN 1 ELSE 0 END ) AS failed_count,
		SUM( CASE WHEN es.NAME = 'FINISHED' THEN 1 ELSE 0 END ) AS finished_count 
	FROM
		pipeline_pipelineinstance AS pp
		INNER JOIN eri_state AS es ON pp.instance_id = es.root_id 
	WHERE
		pp.is_started = 1 
		AND pp.is_finished = 0 
		AND pp.is_revoked = 0 
		AND pp.is_expired = 0 
		AND is_deleted = 0 
	GROUP BY
		es.root_id,
		pp.id 
	HAVING
		failed_count = 0 
		AND finished_count < total_count 
	ORDER BY
		pp.id 
	) AS t2 ON t1.pipeline_instance_id = t2.id;

执行中任务ORM

states = [
            state["root_id"] 
            for state in (
                State.objects.values("root_id").
                annotate(total_count=Count("root_id")).
                annotate(failed_count=Count("root_id", filter=Q(name='FAILED'))).
                annotate(finished_count=Count("root_id",filter=Q(name='FINISHED')))
            )
            if state["failed_count"] == 0 and state["finished_count"] < state["total_count"]
        ]
        tasks = TaskFlowInstance.objects.filter(
            pipeline_instance__instance_id__in=states,
            pipeline_instance__is_started=True,
            pipeline_instance__is_finished=False,
            pipeline_instance__is_revoked=False,
            pipeline_instance__is_expired=False,
            pipeline_instance__is_deleted=False,
            is_deleted=False,
        ).values(
            "project__name", 
            "pipeline_instance__name",
            "pipeline_instance__start_time",
        )

from bk-sops.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.