mirror of
https://github.com/whyour/qinglong.git
synced 2026-10-01 05:13:50 +08:00
fix: reduce task startup overhead and lazy-load notifications (#3080)
This commit is contained in:
@@ -65,7 +65,9 @@ ql_read_node_path_cache() {
|
||||
# the caller's descriptors. A crashed refresher releases the kernel lock.
|
||||
ql_refresh_node_global_path() (
|
||||
local cache="$1" key="$2" now result previous_umask
|
||||
local lock="${cache}.lock"
|
||||
# Keep one persistent lock per owner. Removing per-key lock files could
|
||||
# split concurrent waiters across different inodes during cache cleanup.
|
||||
local lock="${dir_tmp}/pnpm-root-${EUID}.lock"
|
||||
previous_umask=$(umask)
|
||||
umask 077
|
||||
if type -P flock &>/dev/null && mkdir -p -- "$dir_tmp" 2>/dev/null; then
|
||||
@@ -93,6 +95,10 @@ ql_refresh_node_global_path() (
|
||||
|
||||
# Private lock creation must not change pnpm's inherited creation mask.
|
||||
umask "$previous_umask"
|
||||
# Warm lookups never scan the directory. Retire old environment records on
|
||||
# refresh, while preserving the shared lock and unrelated cache files.
|
||||
find "$dir_tmp" -maxdepth 1 -type f -user "$EUID" \
|
||||
-name "pnpm-root-${EUID}-*.cache" -mmin +60 -delete 2>/dev/null || true
|
||||
now=${EPOCHSECONDS:-$(date +%s)}
|
||||
result=$(pnpm root -g 9>&- 2>/dev/null) || return $?
|
||||
# Never cache failed, empty, multiline or non-absolute answers.
|
||||
@@ -119,8 +125,10 @@ ql_get_node_global_path() {
|
||||
fi
|
||||
|
||||
local key cache
|
||||
cache="${dir_tmp}/pnpm-root-${EUID}.cache"
|
||||
key=$(ql_node_path_cache_key) || { pnpm root -g 2>/dev/null; return $?; }
|
||||
# Node and crond may have different working directories/configuration.
|
||||
# Preserve both discoveries instead of evicting each other on every run.
|
||||
cache="${dir_tmp}/pnpm-root-${EUID}-${key// /-}.cache"
|
||||
if ql_read_node_path_cache "$cache" "$key"; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
@@ -159,9 +159,13 @@ try {
|
||||
|
||||
run();
|
||||
|
||||
const { sendNotify } = require('./__ql_notify__.js');
|
||||
global.QLAPI = {
|
||||
notify: sendNotify,
|
||||
notify(...args) {
|
||||
// Keep notification dependencies out of ordinary script startup.
|
||||
// require caches the module after the first notification.
|
||||
const { sendNotify } = require('./__ql_notify__.js');
|
||||
return sendNotify.apply(this, args);
|
||||
},
|
||||
...client,
|
||||
};
|
||||
} catch (error) {
|
||||
|
||||
@@ -129,10 +129,12 @@ try:
|
||||
|
||||
run()
|
||||
|
||||
from __ql_notify__ import send
|
||||
|
||||
class BaseApi(Client):
|
||||
def notify(self, *args, **kwargs):
|
||||
# Most scripts never send a notification. Python caches this
|
||||
# module after the first call, including its channel dependencies.
|
||||
from __ql_notify__ import send
|
||||
|
||||
return send(*args, **kwargs)
|
||||
|
||||
QLAPI = BaseApi()
|
||||
|
||||
Reference in New Issue
Block a user