DolphinScheduler定期清除工作流

背景

由于工作流实例以及任务实例过多,准备只保留两天的任务记录

需要的表

t_ds_process_instance 工作流实例表
t_ds_task_instance  任务实例表
t_ds_relation_process_instance  工作流和任务实例关联表  保存着工作流和任务实例id

1.2 sql编写

创建工作流实例临时表保存两天的id

drop table if exists tmp_t_ds_process_instance_1;
create table tmp_t_ds_process_instance_1 as
SELECT id process_instance_id
FROM t_ds_process_instance
WHERE DATE(end_time) < CURDATE() - INTERVAL 2 DAY
union
select id process_instance_id
from t_ds_process_instance
where DATE(start_time) < CURDATE() - INTERVAL 2 DAY;

创建任务实例临时表保存两天的id

drop table if exists tmp_t_ds_process_instance_2;
create table tmp_t_ds_process_instance_2 as
select  
a.id as task_instance_id
from t_ds_task_instance a, tmp_t_ds_process_instance_1 b
where a.process_instance_id = b.process_instance_id;

保留两天工作流实例日志

DELETE  a from t_ds_process_instance a  where exists (
select 1 from tmp_t_ds_process_instance_1 b where a.id = b.process_instance_id
);

保留两天的任务实例日志

delete a from t_ds_task_instance a where exists (
select 1 from tmp_t_ds_process_instance_2 b where a.id = b.task_instance_id
);

删除关联的任务日志

delete a from t_ds_relation_process_instance a where exists ( select  1 from tmp_t_ds_process_instance_1 b where a.parent_process_instance_id = b.process_instance_id
);
delete a from t_ds_relation_process_instance a where exists ( select  1 from tmp_t_ds_process_instance_1 b where a.process_instance_id = b.process_instance_id
);
delete a from t_ds_relation_process_instance a where exists (select 1 from tmp_t_ds_process_instance_2 b where a.parent_task_instance_id = b.task_instance_id
);

删除临时表

drop table if exists tmp_t_ds_process_instance_1;
drop table if exists tmp_t_ds_process_instance_2;

1.3 海豚上创建任务定时运行

在这里插入图片描述

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
根据提供的引用内容,以下是使用DolphinScheduler自动生成工作流JSON的示例代码: ```java import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; public class WorkflowJsonGenerator { public static void main(String[] args) { // 读取工作流模板文件 File templateFile = new File("workflow_template.json"); StringBuilder templateContent = new StringBuilder(); try (BufferedReader reader = new BufferedReader(new FileReader(templateFile))) { String line; while ((line = reader.readLine()) != null) { templateContent.append(line); } } catch (Exception e) { e.printStackTrace(); } // 生成多个工作流JSON List<String> workflowJsonList = new ArrayList<>(); for (int i = 1; i <= 10; i++) { String workflowJson = templateContent.toString().replace("{{workflow_name}}", "Workflow " + i); workflowJsonList.add(workflowJson); } // 输出工作流JSON for (String workflowJson : workflowJsonList) { System.out.println(workflowJson); } } } ``` 这段代码做了以下几件事情: 1. 读取工作流模板文件(假设文件名为"workflow_template.json")的内容。 2. 根据模板内容生成多个工作流JSON,将模板中的"{{workflow_name}}"替换为具体的工作流名称。 3. 将生成的工作流JSON输出到控制台。 请注意,这只是一个示例代码,你需要根据实际情况进行修改和适配。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值