mirror of
https://github.com/norohind/jubilant-system-core.git
synced 2025-07-17 16:51:46 +03:00
Compare commits
6 Commits
8cd624aed3
...
5027ef748c
Author | SHA1 | Date | |
---|---|---|---|
5027ef748c | |||
20cd603b23 | |||
be3394ea74 | |||
a552fc0361 | |||
04cccabfa2 | |||
7939e24de2 |
@ -1,6 +1,5 @@
|
|||||||
import os
|
import os
|
||||||
import functools
|
import functools
|
||||||
import threading
|
|
||||||
from Hook import Hook
|
from Hook import Hook
|
||||||
import importlib.machinery
|
import importlib.machinery
|
||||||
import HookUtils
|
import HookUtils
|
||||||
@ -94,7 +93,7 @@ class HookSystem:
|
|||||||
|
|
||||||
threading.Thread(
|
threading.Thread(
|
||||||
name=f'bootstrap-hook-thread-{operation_id}',
|
name=f'bootstrap-hook-thread-{operation_id}',
|
||||||
target=lambda: HookSystem._call_hooks(operation_id, hooks, copy.deepcopy(get_latest())),
|
target=lambda: HookSystem._call_hooks(operation_id, hooks, get_latest()),
|
||||||
).start()
|
).start()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -103,5 +102,5 @@ class HookSystem:
|
|||||||
threading.Thread(
|
threading.Thread(
|
||||||
name=f'hook-{hook.__class__.__name__}-{operation_id}',
|
name=f'hook-{hook.__class__.__name__}-{operation_id}',
|
||||||
target=hook.update,
|
target=hook.update,
|
||||||
args=(operation_id, latest_records)
|
args=(operation_id, copy.deepcopy(latest_records))
|
||||||
).start()
|
).start()
|
||||||
|
33
main.py
33
main.py
@ -57,6 +57,11 @@ def shutdown_callback(sig: int, frame) -> None:
|
|||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
|
|
||||||
|
def threads_dump(sig: int, frame) -> None:
|
||||||
|
running_threads = ', '.join((thread.name for thread in threading.enumerate()))
|
||||||
|
logger.info(f'Running threads: {running_threads}')
|
||||||
|
|
||||||
|
|
||||||
def discover(back_count: int = 0):
|
def discover(back_count: int = 0):
|
||||||
"""Discover new squads
|
"""Discover new squads
|
||||||
:param back_count: int how many squads back we should check, it is helpful to recheck newly created squads
|
:param back_count: int how many squads back we should check, it is helpful to recheck newly created squads
|
||||||
@ -153,6 +158,11 @@ def main():
|
|||||||
global can_be_shutdown
|
global can_be_shutdown
|
||||||
signal.signal(signal.SIGTERM, shutdown_callback)
|
signal.signal(signal.SIGTERM, shutdown_callback)
|
||||||
signal.signal(signal.SIGINT, shutdown_callback)
|
signal.signal(signal.SIGINT, shutdown_callback)
|
||||||
|
try:
|
||||||
|
signal.signal(signal.SIGUSR1, threads_dump)
|
||||||
|
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
|
||||||
def help_cli() -> str:
|
def help_cli() -> str:
|
||||||
return """Possible arguments:
|
return """Possible arguments:
|
||||||
@ -160,7 +170,8 @@ def main():
|
|||||||
main.py update
|
main.py update
|
||||||
main.py update amount <amount: int>
|
main.py update amount <amount: int>
|
||||||
main.py update id <id: int>
|
main.py update id <id: int>
|
||||||
main.py daemon"""
|
main.py daemon
|
||||||
|
main.py hooks notify <inserted;deleted> <operation_id: int>"""
|
||||||
|
|
||||||
logger.debug(f'argv: {sys.argv}')
|
logger.debug(f'argv: {sys.argv}')
|
||||||
|
|
||||||
@ -243,6 +254,26 @@ def main():
|
|||||||
else:
|
else:
|
||||||
logger.info(f'Unknown argument {sys.argv[2]}')
|
logger.info(f'Unknown argument {sys.argv[2]}')
|
||||||
|
|
||||||
|
elif len(sys.argv) == 5:
|
||||||
|
# main.py hooks notify <inserted;deleted> <operation_id: int>
|
||||||
|
if sys.argv[1] == 'hooks' and sys.argv[2] == 'notify' and sys.argv[3] in ('inserted', 'deleted'):
|
||||||
|
try:
|
||||||
|
operation_id = int(sys.argv[4])
|
||||||
|
|
||||||
|
except ValueError:
|
||||||
|
operation_id = 0
|
||||||
|
print('operation_id must be integer')
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
logger.info(f'Notifying {sys.argv[3]} hooks with {operation_id=}')
|
||||||
|
|
||||||
|
if sys.argv[3] == 'inserted':
|
||||||
|
FAPI.hook_system.notify_inserted(operation_id)
|
||||||
|
|
||||||
|
else: # deleted
|
||||||
|
FAPI.hook_system.notify_deleted(operation_id)
|
||||||
|
|
||||||
|
exit(0)
|
||||||
else:
|
else:
|
||||||
print(help_cli())
|
print(help_cli())
|
||||||
exit(1)
|
exit(1)
|
||||||
|
@ -311,4 +311,6 @@ begin
|
|||||||
user_id = new.user_id,
|
user_id = new.user_id,
|
||||||
news_id = new.news_id,
|
news_id = new.news_id,
|
||||||
"date" = new.date;
|
"date" = new.date;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
create index if not exists idx_snh_operation_id_desc on squadrons_news_historical (operation_id desc);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user