From 6dbd9808814103003af0e7e7a6806cea427bbd34 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 22 Nov 2025 14:30:25 +0000 Subject: [PATCH] Add QLAPI auto-initialization for standalone node execution Co-authored-by: whyour <22700758+whyour@users.noreply.github.com> --- sample/ql_sample.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/sample/ql_sample.js b/sample/ql_sample.js index 7f5b6863..34870e6b 100644 --- a/sample/ql_sample.js +++ b/sample/ql_sample.js @@ -4,6 +4,35 @@ * 定时规则 * cron: 1 9 * * * */ + +// Initialize QLAPI if not already loaded (for direct node execution) +if (typeof QLAPI === 'undefined') { + const path = require('path'); + const qlDir = process.env.QL_DIR || '/ql'; + const preloadDir = path.join(qlDir, 'shell/preload'); + + try { + // Load the notify function + const notifyPath = path.join(preloadDir, '__ql_notify__.js'); + const { sendNotify } = require(notifyPath); + + // Load the gRPC client + const clientPath = path.join(preloadDir, 'client.js'); + const client = require(clientPath); + + // Create global QLAPI object + global.QLAPI = { + notify: sendNotify, + ...client, + }; + } catch (error) { + console.error('Failed to initialize QLAPI. Please run this script using the "task" command or add it as a scheduled task.'); + console.error('Example: task ql_sample.js'); + console.error('Error details:', error.message); + process.exit(1); + } +} + console.log('test scripts'); QLAPI.notify('test scripts', 'test desc'); QLAPI.getEnvs({ searchValue: 'dddd' }).then((x) => {