Commit 3222e028 authored by echel0n's avatar echel0n
Browse files

Added SiCKRAGE API endpoint for declaring AMQP server queue

AMQP consumer now declares server queue prior to connecting using SiCKRAGE API endpoint
parent 04f01e40
......@@ -45,15 +45,22 @@ class AMQPBase(object):
IOLoop.current().add_callback(self.connect)
def connect(self):
# check for api token
if not sickrage.app.api.token or not sickrage.app.config.general.server_id:
IOLoop.current().call_later(5, self.reconnect)
return
# refresh api token if needed
if sickrage.app.api.token_time_remaining < (int(sickrage.app.api.token['expires_in']) / 2):
if not sickrage.app.api.refresh_token():
IOLoop.current().call_later(5, self.reconnect)
return
# declare server amqp queue
if not sickrage.app.api.server.declare_amqp_queue(sickrage.app.config.general.server_id):
IOLoop.current().call_later(5, self.reconnect)
# connect to amqp server
try:
credentials = pika.credentials.PlainCredentials(username='sickrage', password=sickrage.app.api.token["access_token"])
......
import collections
import errno
import time
import traceback
from urllib.parse import urljoin
import errno
import oauthlib.oauth2
import requests
import requests.exceptions
......@@ -15,7 +15,6 @@ from sqlalchemy import orm
import sickrage
from sickrage.core.api.exceptions import APIError
from sickrage.core.databases.cache import CacheDB
from sickrage.core.helpers import get_internal_ip, get_external_ip
class API(object):
......@@ -319,6 +318,9 @@ class API(object):
def get_server_certificate(self, server_id):
return self.api.request('GET', f'server/{server_id}/certificate')
def declare_amqp_queue(self, server_id):
return self.api.request('GET', f'server/{server_id}/declare-amqp-queue')
def upload_config(self, server_id, pkey_sig, config):
data = {
'server-id': server_id,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment