Add more record handling code

This commit is contained in:
Adrian Moennich 2014-11-07 11:27:49 +01:00
parent cd2a3d03eb
commit d16f40cc09
5 changed files with 37 additions and 6 deletions

View File

@ -16,6 +16,7 @@
from __future__ import unicode_literals
__all__ = ('LiveSyncPluginBase', 'LiveSyncAgentBase')
__all__ = ('LiveSyncPluginBase', 'LiveSyncAgentBase', 'SimpleChange', 'process_records')
from .base import LiveSyncPluginBase, LiveSyncAgentBase
from .simplify import SimpleChange, process_records

View File

@ -21,6 +21,7 @@ from flask_pluginengine import depends, trim_docstring
from indico.core.plugins import IndicoPlugin
from indico.util.decorators import classproperty
from indico_livesync.models.queue import LiveSyncQueueEntry
from indico_livesync.plugin import LiveSyncPlugin
@ -59,3 +60,16 @@ class LiveSyncAgentBase(object):
return parts[1].strip()
except IndexError:
return 'no description available'
def __init__(self, agent):
"""
:param agent: a `LiveSyncAgent` instance
"""
self.agent = agent
def fetch_records(self, count=None):
return self.agent.queue.filter_by(processed=False).order_by(LiveSyncQueueEntry.timestamp).limit(count).all()
def run(self):
"""Runs the livsync export"""
raise NotImplementedError

View File

@ -16,11 +16,12 @@
from __future__ import unicode_literals
import transaction
from flask_pluginengine import current_plugin
from flask_script import Manager
from terminaltables import AsciiTable
from indico.core.db import db
from indico.core.db import db, DBMgr
from indico.core.db.sqlalchemy.util.session import update_session_options
from indico.util.console import cformat
@ -98,14 +99,21 @@ def create_agent(agent_type, name=None):
@cli_manager.command
def run(agent_id=None):
"""Runs the livesync agent"""
update_session_options(db)
if agent_id is None:
agents = LiveSyncAgent.find_all()
agent_list = LiveSyncAgent.find_all()
else:
agent = LiveSyncAgent.find_first(id=int(agent_id))
if agent is None:
print 'No such agent'
return
agents = [agent]
agent_list = [agent]
for agent in agents:
pass # TODO
for agent in agent_list:
print cformat('Running agent: %{white!}{}%{reset}').format(agent.name)
with DBMgr.getInstance().global_connection():
try:
agent.backend(agent).run()
finally:
transaction.abort()

View File

@ -32,6 +32,7 @@ def upgrade():
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('agent_id', sa.Integer(), nullable=False, index=True),
sa.Column('timestamp', UTCDateTime(), nullable=False),
sa.Column('processed', sa.Boolean(), nullable=False),
sa.Column('change', sa.SmallInteger(), nullable=False),
sa.Column('type', sa.String(), nullable=False),
sa.Column('category_id', sa.String()),

View File

@ -62,6 +62,13 @@ class LiveSyncQueueEntry(db.Model):
default=now_utc
)
#: if this record has already been processed
processed = db.Column(
db.Boolean,
nullable=False,
default=False
)
#: the change type, a :class:`ChangeType`
change = db.Column(
db.SmallInteger,