Enhance agent.user.js by adding a task handling mechanism and updating logging functions to include timestamps. Refactor existing log calls to use debug level for better traceability and introduce a new task interval for improved task management.
This commit is contained in:
@@ -42,8 +42,9 @@ GM_log('[TL] 🏁 Welcome to Binance Alpha Farm Agent.');
|
||||
|
||||
// ====== CONFIGURATION ======
|
||||
const CONFIG = {
|
||||
HEARTBEAT_INTERVAL: 10000,
|
||||
HEARTBEAT_INTERVAL: 10000, // Send heartbeat every 10 seconds
|
||||
DASHBOARD_UPDATE_INTERVAL: 500, // Update dashboard overlay every 0.5 seconds
|
||||
TASK_INTERVAL: 1000, // Check for new task every 1 second
|
||||
SERVERS: {
|
||||
local: { label: '🏠 Local', url: 'http://localhost:3000' },
|
||||
prod: { label: '🌐 Prod', url: 'https://baf.thuanle.me' },
|
||||
@@ -112,7 +113,7 @@ GM_log('[TL] 🏁 Welcome to Binance Alpha Farm Agent.');
|
||||
current_page: currentPage,
|
||||
});
|
||||
|
||||
TL.log('APP-STATE', 'AppState initialized');
|
||||
TL.debug('APP-STATE', 'AppState initialized');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -258,10 +259,10 @@ GM_log('[TL] 🏁 Welcome to Binance Alpha Farm Agent.');
|
||||
* TL - Common utilities cho logging, notifications, và DOM helpers
|
||||
*/
|
||||
const TL = {
|
||||
debug: (tag, msg, ...args) => AppSettings.getDebug() && GM_log(`[TL] [${tag}]\n${msg}`, ...args),
|
||||
log: (tag, msg, ...args) => GM_log(`[TL] [${tag}]\n${msg}`, ...args),
|
||||
warn: (tag, msg, ...args) => GM_log(`[TL] [WARN] [${tag}] ⚠️\n${msg}`, ...args),
|
||||
error: (tag, msg, ...args) => GM_log(`[TL] [ERROR] [${tag}] ❌\n${msg}`, ...args),
|
||||
debug: (tag, msg, ...args) => AppSettings.getDebug() && GM_log(`[TL] [DEBUG] [${new Date().toLocaleString()}] [${tag}] \n${msg}`, ...args),
|
||||
log: (tag, msg, ...args) => GM_log(`[TL] [LOG] [${new Date().toLocaleString()}] [${tag}] \n${msg}`, ...args),
|
||||
warn: (tag, msg, ...args) => GM_log(`[TL] [WARN] [${new Date().toLocaleString()}] [${tag}] ⚠️\n${msg}`, ...args),
|
||||
error: (tag, msg, ...args) => GM_log(`[TL] [ERROR] [${new Date().toLocaleString()}] [${tag}] ❌\n${msg}`, ...args),
|
||||
|
||||
noti: (title, text, timeout = 2500) => {
|
||||
if (typeof GM_notification === 'function') {
|
||||
@@ -875,7 +876,7 @@ GM_log('[TL] 🏁 Welcome to Binance Alpha Farm Agent.');
|
||||
// Setup interval services
|
||||
AppServices.initInterval();
|
||||
|
||||
TL.log('APP-SERVICES', 'AppServices initialized');
|
||||
TL.debug('APP-SERVICES', 'AppServices initialized');
|
||||
},
|
||||
|
||||
initObservers: () => {
|
||||
@@ -900,7 +901,7 @@ GM_log('[TL] 🏁 Welcome to Binance Alpha Farm Agent.');
|
||||
registerSession: async () => {
|
||||
const msg = await BAF.register({ session_id: AppSession.SESSION_ID });
|
||||
AppSession.setSessionToken(msg.data.token);
|
||||
TL.log('APP-SERVICES', `Session token: ${AppSession.getSessionToken()}`);
|
||||
TL.debug('APP-SERVICES', `Session token: ${AppSession.getSessionToken()}`);
|
||||
},
|
||||
|
||||
// Setup interval services
|
||||
@@ -945,6 +946,21 @@ GM_log('[TL] 🏁 Welcome to Binance Alpha Farm Agent.');
|
||||
TL.error('HEARTBEAT', e.message);
|
||||
return null;
|
||||
}
|
||||
},
|
||||
|
||||
handleTask: (task) => {
|
||||
TL.debug('APP-SERVICES', `Task: ${JSON.stringify(task, null, 2)}`);
|
||||
},
|
||||
|
||||
start: async () => {
|
||||
while (true) {
|
||||
const task = await BAF.getTask();
|
||||
if (task.ok) {
|
||||
AppServices.handleTask(task.data);
|
||||
}
|
||||
|
||||
await TL.sleep(CONFIG.TASK_INTERVAL);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -956,4 +972,5 @@ GM_log('[TL] 🏁 Welcome to Binance Alpha Farm Agent.');
|
||||
}
|
||||
|
||||
TL.log('MAIN', 'App started');
|
||||
await AppServices.start();
|
||||
})();
|
||||
Reference in New Issue
Block a user