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>
This commit is contained in:
copilot-swe-agent[bot] 2025-11-22 14:50:55 +00:00
parent ebedd994dd
commit 929d2eb574
2 changed files with 5 additions and 77 deletions

View File

@ -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) => {

View File

@ -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")