我用Python编写了一个ETL作业。我必须在不同的环境(本地、DEV、TST、PROD)中运行它,因此我需要找到一种使用环境变量来设置作业计划的方法,这样我就可以为每个环境设置不同的计划,而不必将代码从一个环境接触到另一个环境。今天我使用ap调度器。我的密码里有这样的东西:
from apscheduler.schedulers.blocking import BlockingScheduler
def etl_job():
sched = BlockingScheduler(daemon=True)
sched.add_job(etl_job,'interval',minutes=7)
sched.start()现在有人知道要解决这个问题了吗?谢谢!
发布于 2021-05-06 02:23:17
我是如何解决这个问题的:
环境变量(json格式)
schedule='{"jobsSchedule": [{"job_name": "job_1","schedule": "*/1 * * * *"},{"job_name":"job_2","schedule": "*/2 * * * *"}]}'读取env变量
jobCrontabSchedule = json.loads(os.getenv('schedule'))安排每一项工作
for job in jobCrontabSchedule['jobsSchedule']:
print ("Scheduling the job: "+job['job_name']+" with the schedule: "+job['schedule'])
sched.add_job(globals()[job['job_name']], CronTrigger.from_crontab(job['schedule']))发布于 2020-09-30 15:17:39
设置env变量并使用python读取它的示例(我假设这就是您要问的)。
export INTERVAL=5
import os
print(os.environ.get("INTERVAL"))然而,有几件事你可能想要记住:
时提供这些变量的迁移。
https://stackoverflow.com/questions/64128321
复制相似问题