.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.search.checker.scheduler Namespace Reference

Functions

 scheduler_function (int start_after_from, int start_after_to, int every_from, int every_to, Callable callback)
 

Variables

 logger = logging.getLogger('searx.search.checker')
 
str SCHEDULER_LUA = Path(__file__).parent / "scheduler.lua"
 

Detailed Description

Lame scheduler which use Redis as a source of truth:
* the Redis key SearXNG_checker_next_call_ts contains the next time the embedded checker should run.
* to avoid lock, a unique Redis script reads and updates the Redis key SearXNG_checker_next_call_ts.
* this Redis script returns a list of two elements:
   * the first one is a boolean. If True, the embedded checker must run now in this worker.
   * the second element is the delay in second to wait before the next call to the Redis script.

This scheduler is not generic on purpose: if more feature are required, a dedicate scheduler must be used
(= a better scheduler should not use the web workers)

Function Documentation

◆ scheduler_function()

searx.search.checker.scheduler.scheduler_function ( int start_after_from,
int start_after_to,
int every_from,
int every_to,
Callable callback )
Run the checker periodically. The function never returns.

Parameters:
* start_after_from and start_after_to: when to call "callback" for the first on the Redis instance
* every_from and every_to: after the first call, how often to call "callback"

There is no issue:
* to call this function is multiple workers
* to kill workers at any time as long there is one at least one worker

Definition at line 28 of file scheduler.py.

28def scheduler_function(start_after_from: int, start_after_to: int, every_from: int, every_to: int, callback: Callable):
29 """Run the checker periodically. The function never returns.
30
31 Parameters:
32 * start_after_from and start_after_to: when to call "callback" for the first on the Redis instance
33 * every_from and every_to: after the first call, how often to call "callback"
34
35 There is no issue:
36 * to call this function is multiple workers
37 * to kill workers at any time as long there is one at least one worker
38 """
39 scheduler_now_script = SCHEDULER_LUA.open().read()
40 while True:
41 # ask the Redis script what to do
42 # the script says
43 # * if the checker must run now.
44 # * how to long to way before calling the script again (it can be call earlier, but not later).
45 script = lua_script_storage(get_redis_client(), scheduler_now_script)
46 call_now, wait_time = script(args=[start_after_from, start_after_to, every_from, every_to])
47
48 # does the worker run the checker now?
49 if call_now:
50 # run the checker
51 try:
52 callback()
53 except Exception: # pylint: disable=broad-except
54 logger.exception("Error calling the embedded checker")
55 # only worker display the wait_time
56 logger.info("Next call to the checker in %s seconds", wait_time)
57 # wait until the next call
58 time.sleep(wait_time)

Variable Documentation

◆ logger

searx.search.checker.scheduler.logger = logging.getLogger('searx.search.checker')

Definition at line 23 of file scheduler.py.

◆ SCHEDULER_LUA

str searx.search.checker.scheduler.SCHEDULER_LUA = Path(__file__).parent / "scheduler.lua"

Definition at line 25 of file scheduler.py.