From 929d2eb5745f8b9f9598e2279918c472736a6089 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 22 Nov 2025 14:50:55 +0000 Subject: [PATCH] Revert sample file changes - fix belongs in preload Reverted all changes to sample files as the correct fix is to export NODE_OPTIONS/PYTHONPATH in the preload scripts (sitecustomize.js/py), not to modify sample files. This was the maintainer's feedback. Co-authored-by: whyour <22700758+whyour@users.noreply.github.com> --- sample/ql_sample.js | 49 +++++---------------------------------------- sample/ql_sample.py | 33 ------------------------------ 2 files changed, 5 insertions(+), 77 deletions(-) diff --git a/sample/ql_sample.js b/sample/ql_sample.js index 9a2bf317..7f5b6863 100644 --- a/sample/ql_sample.js +++ b/sample/ql_sample.js @@ -4,43 +4,6 @@ * 定时规则 * 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( - '\n❌ Failed to initialize QLAPI. This usually happens because:', - ); - console.error(' 1. The Qinglong backend is not running'); - console.error(' 2. Required files are not yet generated\n'); - console.error( - 'Solution: Use the "task" command instead of running directly:', - ); - console.error(' Example: task ql_sample.js'); - console.error(' Or add this script as a scheduled task in the panel\n'); - 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) => { @@ -56,13 +19,11 @@ QLAPI.getCrons({ searchValue: 'test' }).then((x) => { }); // 通过ID查询定时任务 (Get cron by ID) -QLAPI.getCronById({ id: 1 }) - .then((x) => { - console.log('getCronById', x); - }) - .catch((err) => { - console.log('getCronById error', err); - }); +QLAPI.getCronById({ id: 1 }).then((x) => { + console.log('getCronById', x); +}).catch((err) => { + console.log('getCronById error', err); +}); // 启用定时任务 (Enable cron tasks) QLAPI.enableCrons({ ids: [1, 2] }).then((x) => { diff --git a/sample/ql_sample.py b/sample/ql_sample.py index d183523d..8135e4c7 100644 --- a/sample/ql_sample.py +++ b/sample/ql_sample.py @@ -5,39 +5,6 @@ name: script name cron: 1 9 * * * """ -# Initialize QLAPI if not already loaded (for direct python execution) -try: - QLAPI -except NameError: - import os - import sys - from pathlib import Path - - ql_dir = os.getenv('QL_DIR', '/ql') - preload_dir = Path(ql_dir) / 'shell' / 'preload' - - # Add preload directory to Python path - sys.path.insert(0, str(preload_dir)) - - try: - from __ql_notify__ import send - from client import Client - - class BaseApi(Client): - def notify(self, *args, **kwargs): - return send(*args, **kwargs) - - QLAPI = BaseApi() - except Exception as error: - print('\n❌ Failed to initialize QLAPI. This usually happens because:') - print(' 1. The Qinglong backend is not running') - print(' 2. Required files are not yet generated\n') - print('Solution: Use the "task" command instead of running directly:') - print(' Example: task ql_sample.py') - print(' Or add this script as a scheduled task in the panel\n') - print(f'Error details: {error}') - sys.exit(1) - print("test script") print(QLAPI.notify("test script", "test desc")) print("test systemNotify")