mirror of https://gitlab.com/bashrc2/epicyon
Create a daemon to handle federated blocks
parent
fa6a0abcbd
commit
7abf819572
37
blocking.py
37
blocking.py
|
@ -11,6 +11,7 @@ import os
|
|||
import json
|
||||
import time
|
||||
from session import get_json_valid
|
||||
from session import create_session
|
||||
from utils import date_from_string_format
|
||||
from utils import date_utcnow
|
||||
from utils import remove_eol
|
||||
|
@ -1833,12 +1834,12 @@ def load_federated_blocks_endpoints(base_dir: str) -> []:
|
|||
return block_federated_endpoints
|
||||
|
||||
|
||||
def update_federated_blocks(session, base_dir: str,
|
||||
http_prefix: str,
|
||||
domain: str, domain_full: str,
|
||||
debug: bool, version: str,
|
||||
signing_priv_key_pem: str,
|
||||
max_api_blocks: int) -> []:
|
||||
def _update_federated_blocks(session, base_dir: str,
|
||||
http_prefix: str,
|
||||
domain: str, domain_full: str,
|
||||
debug: bool, version: str,
|
||||
signing_priv_key_pem: str,
|
||||
max_api_blocks: int) -> []:
|
||||
"""Creates block_api.txt
|
||||
"""
|
||||
block_federated = []
|
||||
|
@ -1939,3 +1940,27 @@ def save_block_federated_endpoints(base_dir: str,
|
|||
except OSError:
|
||||
print('EX: unable to write block_api_endpoints.txt')
|
||||
return result
|
||||
|
||||
|
||||
def run_federated_blocks_daemon(base_dir: str, httpd, debug: bool) -> None:
|
||||
"""Runs the daemon used to update federated blocks
|
||||
"""
|
||||
seconds_per_hour = 60 * 60
|
||||
time.sleep(60)
|
||||
|
||||
session = None
|
||||
while True:
|
||||
if httpd.session:
|
||||
session = httpd.session
|
||||
else:
|
||||
session = create_session(httpd.proxy_type)
|
||||
|
||||
if session:
|
||||
httpd.block_federated = \
|
||||
_update_federated_blocks(httpd.session, base_dir,
|
||||
httpd.http_prefix,
|
||||
httpd.domain, httpd.domain_full,
|
||||
debug, httpd.project_version,
|
||||
httpd.signing_priv_key_pem,
|
||||
httpd.max_api_blocks)
|
||||
time.sleep(seconds_per_hour * 6)
|
||||
|
|
17
daemon.py
17
daemon.py
|
@ -160,9 +160,9 @@ from media import path_is_transcript
|
|||
from media import path_is_audio
|
||||
from cwlists import get_cw_list_variable
|
||||
from cwlists import load_cw_lists
|
||||
from blocking import run_federated_blocks_daemon
|
||||
from blocking import save_block_federated_endpoints
|
||||
from blocking import load_federated_blocks_endpoints
|
||||
from blocking import update_federated_blocks
|
||||
from blocking import contains_military_domain
|
||||
from blocking import load_blocked_military
|
||||
from blocking import save_blocked_military
|
||||
|
@ -25283,17 +25283,10 @@ def run_daemon(no_of_books: int,
|
|||
# this is the instance actor private key
|
||||
httpd.signing_priv_key_pem = get_instance_actor_key(base_dir, domain)
|
||||
|
||||
# load federated blocklists
|
||||
if not unit_test:
|
||||
curr_session = create_session(proxy_type)
|
||||
if curr_session:
|
||||
httpd.block_federated = \
|
||||
update_federated_blocks(curr_session, base_dir,
|
||||
http_prefix,
|
||||
domain, httpd.domain_full,
|
||||
debug, project_version,
|
||||
httpd.signing_priv_key_pem,
|
||||
httpd.max_api_blocks)
|
||||
print('THREAD: Creating federated blocks thread')
|
||||
httpd.thrFederatedBlocksDaemon = \
|
||||
thread_with_trace(target=run_federated_blocks_daemon,
|
||||
args=(base_dir, httpd, debug), daemon=True)
|
||||
|
||||
# threads used for checking for actor changes when clicking on
|
||||
# avatar icon / person options
|
||||
|
|
Loading…
Reference in New Issue