我是奥斯汀一家小型创业公司的数据人员。我所做的所有分析(迄今为止)都存储为一组从我的笔记本电脑运行的特别脚本。这是一个坏主意。将Python分析脚本部署到服务器
我要在这里画出我的计划来部署我的分析,我想知道是否有任何我曾经错过的明显漏洞,或者我应该考虑的其他事情。我认为概要我保持足够的原子,以便能够在需要的时间和地点插入事物,而且还允许我轻松地运行一个脚本。次要(长期)目标是将简单的Web前端向上放置,以允许用户(即我公司的员工)一次调用一个脚本,请参阅:Very simple web service: take inputs, email results。
我想将脚本部署到服务器,我正在考虑将我的脚本组织到一组python模块中。然后,我希望我的批处理脚本如下所示:
import analysis
batch_dict = analysis.build_batch_dict()
assert sorted(batch_dict.keys()) = ['Hourly', 'Monthly', 'Nightly', 'Weekly']
scripts_to_run = analysis.what_batch() # get from command line?
results_directory = analysis.make_results_directory()
failures = {}
for script in scripts_to_run:
try:
script.analyze()
script.export_results(results_directory)
except Exception as e:
failures.update(script.failed(e))
analysis.completed(failures)
我将重写我的分析以便它们由类处理。
class AnalysisHandler(object):
...
def analyze():
pass
def export_results(some_directory):
pass
def failed(exception):
pass
def run_with_non_default_args(*args, **kwargs):
pass
def something_else_im_missing_now():
pass
所有的脚本都会被继承自AnalysisHandler的东西处理。
服务器上的目录结构如下所示:
datalytics/
results/
02-14-2013/
script1/
/log
/error
/data
script2/
/log
/error
/data
.
.
.
<etc>
scripts/
script1/
bin/
data/
doc/
script_1/
tests/
setup.py
.
.
.
analysis/
__init__.py
analysis.py
batch.py (see above)
new_script.py
run_all_tests.py
run_some_tests.py
run_this_script.py
run_everything.py
某处有在这里一个问题...... – 2013-02-14 17:10:39
“我要在这里写生我的计划部署我的分析,我想知道,如果有,我已经错过任何明显的缺陷或者我应该考虑的其他事情。“我需要问号吗? – BenDundee 2013-02-14 17:12:16
时髦的权限问题可能会在创建目录时引发异常。从测试背景来看,我认为你最好将你的for循环封装在'with open(output)'等文件中,然后写出结果,并存储它们。在服务器崩溃的情况下,你至少想知道运行的是什么,以及是否有可能你的脚本卡在无限的东西中,并啃掉所有内存等。 – pyInTheSky 2013-02-14 17:23:42