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 json
|
||||||
import time
|
import time
|
||||||
from session import get_json_valid
|
from session import get_json_valid
|
||||||
|
from session import create_session
|
||||||
from utils import date_from_string_format
|
from utils import date_from_string_format
|
||||||
from utils import date_utcnow
|
from utils import date_utcnow
|
||||||
from utils import remove_eol
|
from utils import remove_eol
|
||||||
|
|
@ -1833,12 +1834,12 @@ def load_federated_blocks_endpoints(base_dir: str) -> []:
|
||||||
return block_federated_endpoints
|
return block_federated_endpoints
|
||||||
|
|
||||||
|
|
||||||
def update_federated_blocks(session, base_dir: str,
|
def _update_federated_blocks(session, base_dir: str,
|
||||||
http_prefix: str,
|
http_prefix: str,
|
||||||
domain: str, domain_full: str,
|
domain: str, domain_full: str,
|
||||||
debug: bool, version: str,
|
debug: bool, version: str,
|
||||||
signing_priv_key_pem: str,
|
signing_priv_key_pem: str,
|
||||||
max_api_blocks: int) -> []:
|
max_api_blocks: int) -> []:
|
||||||
"""Creates block_api.txt
|
"""Creates block_api.txt
|
||||||
"""
|
"""
|
||||||
block_federated = []
|
block_federated = []
|
||||||
|
|
@ -1939,3 +1940,27 @@ def save_block_federated_endpoints(base_dir: str,
|
||||||
except OSError:
|
except OSError:
|
||||||
print('EX: unable to write block_api_endpoints.txt')
|
print('EX: unable to write block_api_endpoints.txt')
|
||||||
return result
|
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 media import path_is_audio
|
||||||
from cwlists import get_cw_list_variable
|
from cwlists import get_cw_list_variable
|
||||||
from cwlists import load_cw_lists
|
from cwlists import load_cw_lists
|
||||||
|
from blocking import run_federated_blocks_daemon
|
||||||
from blocking import save_block_federated_endpoints
|
from blocking import save_block_federated_endpoints
|
||||||
from blocking import load_federated_blocks_endpoints
|
from blocking import load_federated_blocks_endpoints
|
||||||
from blocking import update_federated_blocks
|
|
||||||
from blocking import contains_military_domain
|
from blocking import contains_military_domain
|
||||||
from blocking import load_blocked_military
|
from blocking import load_blocked_military
|
||||||
from blocking import save_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
|
# this is the instance actor private key
|
||||||
httpd.signing_priv_key_pem = get_instance_actor_key(base_dir, domain)
|
httpd.signing_priv_key_pem = get_instance_actor_key(base_dir, domain)
|
||||||
|
|
||||||
# load federated blocklists
|
print('THREAD: Creating federated blocks thread')
|
||||||
if not unit_test:
|
httpd.thrFederatedBlocksDaemon = \
|
||||||
curr_session = create_session(proxy_type)
|
thread_with_trace(target=run_federated_blocks_daemon,
|
||||||
if curr_session:
|
args=(base_dir, httpd, debug), daemon=True)
|
||||||
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)
|
|
||||||
|
|
||||||
# threads used for checking for actor changes when clicking on
|
# threads used for checking for actor changes when clicking on
|
||||||
# avatar icon / person options
|
# avatar icon / person options
|
||||||
|
|
|
||||||
1
tests.py
1
tests.py
|
|
@ -5673,6 +5673,7 @@ def _test_functions():
|
||||||
'run_post_schedule',
|
'run_post_schedule',
|
||||||
'run_post_schedule_watchdog',
|
'run_post_schedule_watchdog',
|
||||||
'str2bool',
|
'str2bool',
|
||||||
|
'run_federated_blocks_daemon',
|
||||||
'run_newswire_daemon',
|
'run_newswire_daemon',
|
||||||
'run_newswire_watchdog',
|
'run_newswire_watchdog',
|
||||||
'run_federated_shares_watchdog',
|
'run_federated_shares_watchdog',
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue