Skip to content

Commit

Permalink
Added mq progress module stubs.
Browse files Browse the repository at this point in the history
  • Loading branch information
chintal committed Jan 21, 2016
1 parent 1cb8c7b commit 809269e
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 3 deletions.
2 changes: 2 additions & 0 deletions tendril/frontend/blueprints/production/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ def new_production_order():
# Check for Authorization
# Nothing right now.
# Create Order

# TODO detach at this point
fe_workspace_path = os.path.join(TEMPDIR, 'frontend')
if not os.path.exists(fe_workspace_path):
os.makedirs(fe_workspace_path)
Expand Down
7 changes: 7 additions & 0 deletions tendril/frontend/pages/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,10 @@ def favicon():
os.path.join(app.root_path, 'static', 'images'),
'favicon.ico', mimetype='image/vnd.microsoft.icon'
)


@app.route('/progress/<taskid>')
def progress(taskid):
stage = {'taskid': taskid}
return render_template('pages/progress.html', stage=stage,
pagetitle='Task Progress')
23 changes: 23 additions & 0 deletions tendril/frontend/parts/tasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env python
# encoding: utf-8

# Copyright (C) 2016 Chintalagiri Shashank
#
# This file is part of tendril.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

"""
Docstring for tasks
"""
11 changes: 11 additions & 0 deletions tendril/frontend/templates/pages/progress.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{#
Copyright (c) 2015 Chintalagiri Shashank
Released under the MIT license
#}


{% extends "base_templates/base.html" %}

{% block main %}

{% endblock %}
15 changes: 15 additions & 0 deletions tendril/production/db/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,24 @@

from tendril.utils.db import DeclBase
from tendril.utils.db import BaseMixin
from tendril.utils.db import TimestampMixin

from tendril.utils import log
logger = log.get_logger(__name__, log.DEFAULT)


# class ProductionOrder(DeclBase, BaseMixin, TimestampMixin):
# pass


# # TODO Figure out inheritence
# class ProductionActionBase(DeclBase):
# pass
#
#
# class ProductionActionCard(ProductionActionBase):
# pass
#
#
# class ProductionActionDelta(ProductionActionBase):
# pass
20 changes: 17 additions & 3 deletions tendril/production/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ def order_lines(self):


class ProductionOrder(object):
def __init__(self, sno=None):
def __init__(self, sno=None, session=None):
self._sno = sno
self._card_actions = []
self._delta_actions = []
Expand All @@ -350,7 +350,7 @@ def __init__(self, sno=None):
self._ordered_by = None

try:
self.load_from_db()
self.load(session=session)
self._defined = True
except ProductionOrderNotFound:
self._defined = False
Expand Down Expand Up @@ -604,9 +604,23 @@ def _load_legacy(self):
self._load_order_yaml_data()
self._load_snomap_legacy()

def load_from_db(self):
def _load_from_db(self, session):
raise ProductionOrderNotFound

def load_from_db(self, session=None):
if not session:
with get_session() as session:
self._load_from_db(session)
else:
self._load_from_db(session)

def load(self, session=None):
# Retrieve old production orders. If process is called on a loaded
# production order, it'll overwrite whatever came before.
try:
self.load_from_db(session=session)
except ProductionOrderNotFound:
pass
self._load_legacy()

@property
Expand Down
5 changes: 5 additions & 0 deletions tendril/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,11 @@ def load_config(options):
"os.path.join(INSTANCE_ROOT, 'refdocs')",
"Folder for the refdocs filesystem"
),
ConfigOption(
'MQ_SERVER',
'None',
'Message Queue Server URL'
)
]

load_config(config_options_fs)
Expand Down
64 changes: 64 additions & 0 deletions tendril/utils/mq.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/usr/bin/env python
# encoding: utf-8

# Copyright (C) 2016 Chintalagiri Shashank
#
# This file is part of tendril.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

"""
Docstring for mq
"""


import xmlrpclib
import atexit
import uuid


from tendril.utils.config import MQ_SERVER


def _connect_to_mq_server():
s = xmlrpclib.Server(MQ_SERVER + '/control')
return s

mq_server = _connect_to_mq_server()
owned_keys = []


def create_mq(key=None):
if key is None:
key = uuid.uuid4()
mq_server.create_mq(key)
owned_keys.append(key)
return key


def publish(key, data):
mq_server.publish(key, data)
owned_keys.append(key)


def delete_mq(key):
mq_server.delete_mq(key)
owned_keys.append(key)


def cleanup():
for key in owned_keys:
delete_mq(key)

atexit.register(cleanup)

0 comments on commit 809269e

Please sign in to comment.