【发布时间】:2021-06-07 06:07:30
【问题描述】:
我有一个 python 函数,它应该运行给定的日期和时间,它从 url 中获取视频,将其转换为给定的格式并将其上传到存储中。
这个计划函数同步依赖于其他 3 个函数(它们具有关注点分离)
Def getVideo(url):
#1. download the video from an URL
Return scraped_video
Def convertVideo(scraped_video):
#2. Convert the video to a given format
Return file_ouput_path
Def sendVideo(file):
#3. Upload the video to a given Gdrive or Dropbox
GrabAndConvertThenSend(url, notification_email):
Try:
Temp_video = getVideo(url)
file_ouput_path = convertVideo(Temp_video)
sendVideo(file_output_path)
# send notification email with the link
# Schedule the next run
Except Exception as e:
Print(e)
函数 GrabAndConvertThenSend() 通过 APScheduler 处理以在给定日期运行
1.如何实现重试?
有时,由于网络问题或 API 可用性,主要功能可能会中止。 例如:该函数已经下载了视频,但未能将其上传到存储中。
如何在不重新下载视频的情况下从停止的地方恢复? 我坚持将状态(下载,转换,上传)存储在数据库中,这样对吗?
2。像这样链接函数是正确的方法吗?还是我应该依赖事件/侦听器, 甚至排队作业(当任务 A 完成时,它会将任务 B 排队),但是如何实现这一点,因为我的函数有一个单独的关注点
【问题讨论】:
-
您可以使用celery 和
flower进行任务状态监控,并使用redis 或rabbitmq 作为后端和消息代理,或者您可以使用prefect.io
标签: python python-3.x message-queue job-scheduling apscheduler