在x时间后失败时重试功能 [英] Retry function on failure after x amount of time
问题描述
问题:
我有一个通过VIA Cronjob触发的功能.此cronjob在晚上10:00触发该功能,但可以说该功能正常处理所需的数据不存在.我想失败,但是要让函数重试1个小时.我该如何处理这个问题?
代码:
def check_question do
case question = Repo.get_by(Question, active: true, closed: true) do
question when not(is_nil(question)) ->
case ActiveQuestion.ready_for_answer_status(conn, question) do
end
_ ->
# RETRY CODE HERE
end
end
因此您可以从这段代码中看到.如果查询找不到问题,我将case语句发送给失败,但是在失败的情况下,我想在1小时内返回该函数.如何用Elixir/Phoenix做到这一点?感谢您的帮助!
我更喜欢将任务加入像 exq (支持redis)或cron作业中的 ecto_job (支持PostgreSQL). /p>
从那里开始,它会自动重试到某个最大值,并且两次重试之间会有延迟.
它还具有避免服务器重新启动等优点.
PROBLEM:
I have a function that gets triggered VIA Cronjob. This cronjob fires the function at 10:00pm but let's say the data required is not present for the function to properly be handled. I want to fail but then have the function retry an 1 hour. How would I handle this problem?
CODE:
def check_question do
case question = Repo.get_by(Question, active: true, closed: true) do
question when not(is_nil(question)) ->
case ActiveQuestion.ready_for_answer_status(conn, question) do
end
_ ->
# RETRY CODE HERE
end
end
So as you can see from this bit of code. If the query does not find the question I send the case statement to a failure but inside that fail case I want to return the function in 1 hour. How can I achieve this with Elixir/Phoenix? Thanks for the help!
I prefer to enqueue tasks into a job system like Exq (redis backed) or ecto_job (postgresql backed) from the cron job.
From there it will automatically retry up to some maximum with a delay between retries.
It also has the benefit of surviving server reboots etc.
这篇关于在x时间后失败时重试功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!