mirror of
https://github.com/lucaspalomodevelop/indico-plugins.git
synced 2026-03-16 00:34:37 +00:00
57 lines
2.2 KiB
Python
57 lines
2.2 KiB
Python
# This file is part of Indico.
|
|
# Copyright (C) 2002 - 2015 European Organization for Nuclear Research (CERN).
|
|
#
|
|
# Indico is free software; you can redistribute it and/or
|
|
# modify it under the terms of the GNU General Public License as
|
|
# published by the Free Software Foundation; either version 3 of the
|
|
# License, or (at your option) any later version.
|
|
#
|
|
# Indico 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
|
|
# General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with Indico; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
from indico.core.db import DBMgr, db
|
|
from indico.modules.scheduler.tasks.periodic import PeriodicUniqueTask
|
|
from indico.util.date_time import now_utc
|
|
|
|
from indico_livesync.models.agents import LiveSyncAgent
|
|
from indico_livesync.util import clean_old_entries
|
|
|
|
|
|
class LiveSyncTask(PeriodicUniqueTask):
|
|
DISABLE_ZODB_HOOK = True
|
|
|
|
@property
|
|
def logger(self):
|
|
return self.getLogger()
|
|
|
|
def extend_runtime(self):
|
|
# Make the task manager believe the task is running since a much shorter time
|
|
self.setOnRunningListSince(now_utc())
|
|
DBMgr.getInstance().commit()
|
|
|
|
def run(self):
|
|
from indico_livesync.plugin import LiveSyncPlugin
|
|
|
|
plugin = LiveSyncPlugin.instance # RuntimeError if not active
|
|
with plugin.plugin_context():
|
|
clean_old_entries()
|
|
|
|
for agent in LiveSyncAgent.find_all():
|
|
if agent.backend is None:
|
|
self.logger.warning('Skipping agent {}; backend not found'.format(agent.name))
|
|
continue
|
|
if not agent.initial_data_exported:
|
|
self.logger.warning('Skipping agent {}; initial export not performed yet'.format(agent.name))
|
|
continue
|
|
with DBMgr.getInstance().global_connection():
|
|
self.logger.info('Running agent {}'.format(agent.name))
|
|
agent.create_backend(self).run()
|
|
db.session.commit()
|