简体   繁体   English

每个环境的web2py配置不适用于计划程序/脚本

[英]web2py configurations per environment does not work with scheduler / scripts

I have been using the recommended method for setting up DB connections per environment in web2py: 我一直在使用推荐的方法在web2py中为每个环境设置数据库连接:

settings = dict()
if request.env.http_host == 'http://127.0.0.1:8000'
     settings['development']=True
else:
     settings['development']=False
if settings['development']:
     db = DAL('sqlite://....')
else:
     db = DAL('mysql://....')

When using the scheduler in the non-development environment the db connections fail as it is using the port 8000 config. 在非开发环境中使用调度程序时,数据库连接会因为使用端口8000配置而失败。

Similarly when attempting to run a script I get the same errors. 类似地,当尝试运行脚本时,也会出现相同的错误。 This is my last attempt: 这是我最后的尝试:

python web2py.py -S app -M -N -R -L options.py -P 443 applications/testscript.py

"Can't connect to MySQL server on '127.0.0.1' (10061)"�

Is there a recommended way to inject a config per environment that will apply outside of web access? 是否有建议的方法为每个环境注入将在Web访问之外应用的配置?

Temporarily insert the following on a page: 在页面上临时插入以下内容:

{{=response.toolbar()}}

Then on both development and production, click the "request" button and inspect the values in request.env to identify things that differ between the two environments. 然后在开发和生产上,单击“请求”按钮并检查request.env的值,以识别两种环境之间的差异。 Some likely candidates are "server_signature", "server_software", and "web2py_path". 一些可能的候选对象是“ server_signature”,“ server_software”和“ web2py_path”。

I had the same concern and I first though of request.env.server_name . 我也有同样的担忧,尽管我先是request.env.server_name But: 但:

  • this variable does not exist when starting the scheduler 启动调度程序时此变量不存在
  • it could be replaced by request.env.cmd_options.server_name but first, this one does not exist for the server and second, after its startup, the scheduler does not find it any more... 可以用request.env.cmd_options.server_name替换它,但首先,该服务器不存在此名称,其次,启动后,调度程序不再找到它...

Then I found this Q/A and tried to solve it following Anthony's advice: 然后我找到了这个问/答,并尝试按照安东尼的建议解决它:

  • "server_signature" does not exist when starting up the scheduler 启动调度程序时不存在“ server_signature”
  • "server_software" does not exist when starting up the scheduler 启动调度程序时不存在“ server_software”

Finally, "web2py_path" does the job even if for me, testing against a full installation path is not really a 'clean' solution... 最后,即使对我来说,“ web2py_path”也能完成工作,但针对完整的安装路径进行测试并不是真正的“干净”解决方案...

if request.env.web2py_path == '/your/path/on/server/to/web2py'
    settings['development']=False
else:
    settings['development']=True

Now it should work, but I fell into this one : Can not run the web2py scheduler using postgresql database 现在它应该可以工作了,但是我陷入了这一困境无法使用postgresql数据库运行web2py调度程序

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM