friendlier exit messages for tgapp; scheduler sleep-first and dir check

This commit is contained in:
Jiaqing Liang
2026-02-24 11:13:05 +08:00
parent e808ce6878
commit 860d305c44
3 changed files with 15 additions and 6 deletions

BIN
.gitignore vendored

Binary file not shown.

View File

@@ -145,7 +145,9 @@ if __name__ == '__main__':
while 'done' not in (item := dq.get()): pass while 'done' not in (item := dq.get()): pass
open('./temp/scheduler.log', 'a', encoding='utf-8').write(f'[{datetime.now():%m-%d %H:%M}] {tag}\n{item["done"]}\n\n') open('./temp/scheduler.log', 'a', encoding='utf-8').write(f'[{datetime.now():%m-%d %H:%M}] {tag}\n{item["done"]}\n\n')
while True: while True:
time.sleep(55 + random.random() * 10)
now = datetime.now() now = datetime.now()
if not os.path.isdir('./sche_tasks/pending'): continue
for f in os.listdir('./sche_tasks/pending'): for f in os.listdir('./sche_tasks/pending'):
m = re.match(r'(\d{4}-\d{2}-\d{2})_(\d{4})_', f) m = re.match(r'(\d{4}-\d{2}-\d{2})_(\d{4})_', f)
if m and now >= datetime.strptime(f'{m[1]} {m[2]}', '%Y-%m-%d %H%M'): if m and now >= datetime.strptime(f'{m[1]} {m[2]}', '%Y-%m-%d %H%M'):
@@ -153,7 +155,6 @@ if __name__ == '__main__':
dq = agent.put_task(f'按scheduled_task_sop执行任务文件 ../sche_tasks/pending/{f}立刻移到running\n内容:\n{raw}', source='scheduler') dq = agent.put_task(f'按scheduled_task_sop执行任务文件 ../sche_tasks/pending/{f}立刻移到running\n内容:\n{raw}', source='scheduler')
threading.Thread(target=drain, args=(dq, f), daemon=True).start() threading.Thread(target=drain, args=(dq, f), daemon=True).start()
break break
time.sleep(55 + random.random() * 10)
else: else:
agent.inc_out = True agent.inc_out = True
while True: while True:

View File

@@ -1,9 +1,13 @@
import os, sys, re, threading, asyncio, queue as Q, socket, time import os, sys, re, threading, asyncio, queue as Q, socket, time
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from agentmain import GeneraticAgent from agentmain import GeneraticAgent
try:
from telegram import Update from telegram import Update
from telegram.ext import ApplicationBuilder, MessageHandler, CommandHandler, filters, ContextTypes from telegram.ext import ApplicationBuilder, MessageHandler, CommandHandler, filters, ContextTypes
from telegram.request import HTTPXRequest from telegram.request import HTTPXRequest
except:
print("Please ask the agent install python-telegram-bot to use telegram module.")
sys.exit(1)
import mykey import mykey
agent = GeneraticAgent() agent = GeneraticAgent()
@@ -89,8 +93,12 @@ if __name__ == '__main__':
# Single instance lock using socket # Single instance lock using socket
try: try:
_lock_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM); _lock_sock.bind(('127.0.0.1', 19527)) _lock_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM); _lock_sock.bind(('127.0.0.1', 19527))
except OSError: sys.exit('Another instance is already running.') except OSError:
if not ALLOWED: sys.exit('ERROR: tg_allowed_users in mykey.py is empty or missing. Set it to avoid unauthorized access.') print('[Telegram] Another instance is already running, skiping...')
sys.exit(1)
if not ALLOWED:
print('[Telegram] ERROR: tg_allowed_users in mykey.py is empty or missing. Set it to avoid unauthorized access.')
sys.exit(1)
_logf = open(os.path.join(os.path.dirname(__file__), 'temp', 'tgapp.log'), 'a', encoding='utf-8', buffering=1) _logf = open(os.path.join(os.path.dirname(__file__), 'temp', 'tgapp.log'), 'a', encoding='utf-8', buffering=1)
sys.stdout = sys.stderr = _logf sys.stdout = sys.stderr = _logf
print('[NEW] New process starting, the above are history infos ...') print('[NEW] New process starting, the above are history infos ...')