webcompat / webcompat-metrics-server

Server in charge of delivering different data to the webcompat-metrics-client
Mozilla Public License 2.0
6 stars 5 forks source link

Supply app context for Scheduler scripts that (should) populate the DB #90

Closed laghee closed 5 years ago

laghee commented 5 years ago

Logs from heroku show that writing to the DB is failing... seemingly because we're using the app factory pattern and then not supplying an app context to the scripts:

2019-02-22T14:10:53.041778+00:00 app[api]: Starting process with command `python3 bin/get_count.py needsdiagnosis` by user scheduler@addons.heroku.com
2019-02-22T14:10:57.894234+00:00 heroku[scheduler.5408]: Starting process with command `python3 bin/get_count.py needsdiagnosis`
2019-02-22T14:10:58.546657+00:00 heroku[scheduler.5408]: State changed from starting to up
2019-02-22T14:11:06.721387+00:00 app[scheduler.5408]: Traceback (most recent call last):
2019-02-22T14:11:06.721415+00:00 app[scheduler.5408]:   File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/util/_collections.py", line 999, in __call__
2019-02-22T14:11:06.722549+00:00 app[scheduler.5408]:     return self.registry[key]
2019-02-22T14:11:06.724908+00:00 app[scheduler.5408]: KeyError: 140529743968000
2019-02-22T14:11:06.724942+00:00 app[scheduler.5408]:
2019-02-22T14:11:06.724944+00:00 app[scheduler.5408]: During handling of the above exception, another exception occurred:
2019-02-22T14:11:06.724946+00:00 app[scheduler.5408]:
2019-02-22T14:11:06.724980+00:00 app[scheduler.5408]: Traceback (most recent call last):
2019-02-22T14:11:06.725016+00:00 app[scheduler.5408]:   File "bin/get_count.py", line 114, in <module>
2019-02-22T14:11:06.725301+00:00 app[scheduler.5408]:     sys.exit(main())
2019-02-22T14:11:06.725443+00:00 app[scheduler.5408]:   File "bin/get_count.py", line 95, in main
2019-02-22T14:11:06.725870+00:00 app[scheduler.5408]:     db.session.add(iss_count)
2019-02-22T14:11:06.726170+00:00 app[scheduler.5408]:   File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/orm/scoping.py", line 153, in do
2019-02-22T14:11:06.726422+00:00 app[scheduler.5408]:     return getattr(self.registry(), name)(*args, **kwargs)
2019-02-22T14:11:06.729346+00:00 app[scheduler.5408]:   File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/util/_collections.py", line 1001, in __call__
2019-02-22T14:11:06.730089+00:00 app[scheduler.5408]:     return self.registry.setdefault(key, self.createfunc())
2019-02-22T14:11:06.730130+00:00 app[scheduler.5408]:   File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/orm/session.py", line 2950, in __call__
2019-02-22T14:11:06.731946+00:00 app[scheduler.5408]:     return self.class_(**local_kw)
2019-02-22T14:11:06.741327+00:00 app[scheduler.5408]:   File "/app/.heroku/python/lib/python3.6/site-packages/flask_sqlalchemy/__init__.py", line 141, in __init__
2019-02-22T14:11:06.741689+00:00 app[scheduler.5408]:     self.app = app = db.get_app()
2019-02-22T14:11:06.741728+00:00 app[scheduler.5408]:   File "/app/.heroku/python/lib/python3.6/site-packages/flask_sqlalchemy/__init__.py", line 912, in get_app
2019-02-22T14:11:06.742502+00:00 app[scheduler.5408]:     'No application found. Either work inside a view function or push'
2019-02-22T14:11:06.744062+00:00 app[scheduler.5408]: RuntimeError: No application found. Either work inside a view function or push an application context. See http://flask-sqlalchemy.pocoo.org/contexts/