|
|
|
@ -16,11 +16,9 @@
|
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
from urllib.request import urlopen
|
|
|
|
|
|
|
|
|
|
from flask_babel import lazy_gettext as N_
|
|
|
|
|
|
|
|
|
|
from cps import config, logger
|
|
|
|
|
from cps import config, logger, db, ub
|
|
|
|
|
from cps.services.worker import CalibreTask
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -28,18 +26,12 @@ class TaskReconnectDatabase(CalibreTask):
|
|
|
|
|
def __init__(self, task_message=N_('Reconnecting Calibre database')):
|
|
|
|
|
super(TaskReconnectDatabase, self).__init__(task_message)
|
|
|
|
|
self.log = logger.create()
|
|
|
|
|
self.listen_address = config.get_config_ipaddress()
|
|
|
|
|
self.listen_port = config.config_port
|
|
|
|
|
self.calibre_db = db.CalibreDB(expire_on_commit=False, init=True)
|
|
|
|
|
|
|
|
|
|
def run(self, worker_thread):
|
|
|
|
|
address = self.listen_address if self.listen_address else 'localhost'
|
|
|
|
|
port = self.listen_port if self.listen_port else 8083
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
urlopen('http://' + address + ':' + str(port) + '/reconnect')
|
|
|
|
|
self._handleSuccess()
|
|
|
|
|
except Exception as ex:
|
|
|
|
|
self._handleError('Unable to reconnect Calibre database: ' + str(ex))
|
|
|
|
|
self.calibre_db.reconnect_db(config, ub.app_DB_path)
|
|
|
|
|
self.calibre_db.session.close()
|
|
|
|
|
self._handleSuccess()
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def name(self):
|
|
|
|
|