Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Click #151

Merged
merged 4 commits into from
May 1, 2019
Merged

Click #151

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
but it ensures that PKs cannot be resued. (#143)
+ The REST API for `DataPoint` has been implemented. (#122)
+ Example `docker-compose.yml` file now includes `depends_on`. (#99)
+ Command line stuff is now handled by `click`. (#150)


## 0.5.0 (2019-02-28)
Expand Down
48 changes: 39 additions & 9 deletions runserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,47 @@
import os
from pathlib import Path

import click

import trendlines.orm as orm
from trendlines.app_factory import create_app

PORT = 5000

# Load our configuration. We're using pathlib and `.resolve()` because
# Flask's working dir is src/trendlines and uses that when running
# `app.config.from_envvar`, so the path it attemps to load is
# `/proj_folder/src/trendlines/config/localhost.cfg` if `cfg_file` is not
# absolute.
cfg_file = Path('./config/localhost.cfg')
os.environ['TRENDLINES_CONFIG_FILE'] = str(cfg_file.resolve())

app = create_app()
app.run(debug=True, port=PORT, use_reloader=True)
def make_db_from_orm():
"""
Make the database directly from the ORM rather than via migrations.
"""
print("making...")
orm.db.init("internal.db", pragmas=orm.DB_OPTS)
orm.db.connect()
orm.db.create_tables([orm.Metric, orm.DataPoint])
orm.db.close()
print("Done.")


def runserver():
# Load our configuration. We're using pathlib and `.resolve()` because
# Flask's working dir is src/trendlines and uses that when running
# `app.config.from_envvar`, so the path it attemps to load is
# `/proj_folder/src/trendlines/config/localhost.cfg` if `cfg_file` is not
# absolute.
cfg_file = Path('./config/localhost.cfg')
os.environ['TRENDLINES_CONFIG_FILE'] = str(cfg_file.resolve())

app = create_app()
app.run(debug=True, port=PORT, use_reloader=True)


@click.command()
@click.option("--db-from-orm", is_flag=True)
def main(db_from_orm):
if db_from_orm:
make_db_from_orm()
else:
runserver()


if __name__ == "__main__":
main()
36 changes: 24 additions & 12 deletions runworker.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,31 @@
import os
from pathlib import Path

import click
from celery.bin import worker

from trendlines.celery_factory import create_celery

# Load our configuration. We're using pathlib and `.resolve()` because
# Flask's working dir is src/trendlines and uses that when running
# `app.config.from_envvar`, so the path it attemps to load is
# `/proj_folder/src/trendlines/config/localhost.cfg` if `cfg_file` is not
# absolute.
cfg_file = Path('./config/localhost.cfg')
os.environ['TRENDLINES_CONFIG_FILE'] = str(cfg_file.resolve())

# app.worker_main()
celery = create_celery()
worker = worker.worker(app=celery)
worker.run()

def runworker():
# Load our configuration. We're using pathlib and `.resolve()` because
# Flask's working dir is src/trendlines and uses that when running
# `app.config.from_envvar`, so the path it attemps to load is
# `/proj_folder/src/trendlines/config/localhost.cfg` if `cfg_file` is not
# absolute.
cfg_file = Path('./config/localhost.cfg')
os.environ['TRENDLINES_CONFIG_FILE'] = str(cfg_file.resolve())

# app.worker_main()
celery = create_celery()
this_worker = worker.worker(app=celery)
this_worker.run()


@click.command()
def main():
runworker()


if __name__ == "__main__":
main()