雪花重试失败的任务

时间:2021-05-27 12:46:16

标签: snowflake-cloud-data-platform

我有一个预定的雪花任务,偶尔会因为上游数据可用性延迟而失败。是否可以设置为失败时自动重试n次。

如果有这个功能,我们可以直接使用雪花任务调度,而不是依赖外部调度器

提前致谢

1 个答案:

答案 0 :(得分:0)

如果您可以从 Snowflake 内部检查某些条件,您就可以完成您所需要的事情。

有一个 WHEN 子句来检查任务的条件。如果 WHEN 子句的计算结果为真,则任务运行。否则,它不会运行。

还有一个参数指定任务是否可以重叠运行 ALLOW_OVERLAPPING_EXECUTION。

假设您的任务每小时运行一次,通常需要一分钟才能完成。您可以设置:

SCHEDULE = '5 minutes'
ALLOW_OVERLAPPING_EXECUTION = false
WHEN = datediff(minute, <condition to check goes here> , current_timestamp()) > 60

至于 ,你可以做一些简单的事情:

create or replace table LAST_SUCCESSFUL_JOB_MYJOB(COMPLETION_TIME timestamp default current_timestamp);

insert into LAST_SUCCESSFUL_JOB_MYJOB (COMPLETION_TIME) values (current_timestamp);

-- Run this on completion of successful job run by the MYJOB task:
update LAST_SUCCESSFUL_JOB_MYJOB set COMPLETION_TIME = current_timestamp;

-- You should then be able to use something like this to test if the last 
-- successful job is older than 60 minutes.
select datediff(minute, (select COMPLETION_TIME from LAST_SUCCESSFUL_JOB_MYJOB limit 1), current_timestamp()) > 60;