polycopy 0.1.3 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -155,7 +155,7 @@ function findPolycopyPids() {
155
155
  return pid;
156
156
  }).filter((pid) => pid !== null);
157
157
  }
158
- function stopDaemon() {
158
+ async function stopDaemon() {
159
159
  const pid = getRunningPid();
160
160
  if (!pid) {
161
161
  const fallbackPids = findPolycopyPids();
@@ -166,39 +166,46 @@ function stopDaemon() {
166
166
  console.log(
167
167
  `⚠️ 未找到 PID 文件,尝试停止前台/后台进程 (${fallbackPids.length} 个)`
168
168
  );
169
- fallbackPids.forEach((fallbackPid) => {
170
- try {
171
- process.kill(fallbackPid, "SIGTERM");
172
- console.log(`✅ 已发送停止信号 (PID: ${fallbackPid})`);
173
- } catch (error) {
174
- console.error(`❌ 停止失败 (PID: ${fallbackPid}):`, error);
175
- }
176
- });
169
+ await Promise.all(
170
+ fallbackPids.map((fallbackPid) => stopPid(fallbackPid))
171
+ );
177
172
  return;
178
173
  }
174
+ await stopPid(pid, true);
175
+ }
176
+ async function stopPid(pid, isPrimary = false) {
179
177
  try {
180
178
  process.kill(pid, "SIGTERM");
181
179
  console.log(`✅ 已发送停止信号 (PID: ${pid})`);
182
- let attempts = 0;
183
- const checkInterval = setInterval(() => {
184
- attempts++;
185
- try {
186
- process.kill(pid, 0);
187
- if (attempts >= 20) {
188
- process.kill(pid, "SIGKILL");
189
- console.log("⚠️ 进程未响应,已强制终止");
190
- clearInterval(checkInterval);
191
- removePid();
192
- }
193
- } catch {
194
- console.log("✅ 进程已停止");
195
- clearInterval(checkInterval);
180
+ } catch (error) {
181
+ console.error(`❌ 停止失败 (PID: ${pid}):`, error);
182
+ if (isPrimary) {
183
+ removePid();
184
+ }
185
+ return;
186
+ }
187
+ const maxAttempts = 20;
188
+ for (let attempts = 0; attempts < maxAttempts; attempts++) {
189
+ await new Promise((resolve) => setTimeout(resolve, 500));
190
+ try {
191
+ process.kill(pid, 0);
192
+ } catch {
193
+ console.log("✅ 进程已停止");
194
+ if (isPrimary) {
196
195
  removePid();
197
196
  }
198
- }, 500);
197
+ return;
198
+ }
199
+ }
200
+ try {
201
+ process.kill(pid, "SIGKILL");
202
+ console.log("⚠️ 进程未响应,已强制终止");
199
203
  } catch (error) {
200
- console.error("❌ 停止失败:", error);
201
- removePid();
204
+ console.error(`❌ 强制终止失败 (PID: ${pid}):`, error);
205
+ } finally {
206
+ if (isPrimary) {
207
+ removePid();
208
+ }
202
209
  }
203
210
  }
204
211
  async function runConfig() {
@@ -272,7 +279,7 @@ async function main() {
272
279
  const command = args[0];
273
280
  switch (command) {
274
281
  case "stop":
275
- stopDaemon();
282
+ await stopDaemon();
276
283
  break;
277
284
  case "log":
278
285
  case "logs":
package/dist/config.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- const init = require("./init-C9dmq3BS.js");
2
+ const init = require("./init-Bs-N_AZi.js");
3
3
  async function main() {
4
4
  try {
5
5
  await init.runConfigWizard();
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- const init = require("./init-C9dmq3BS.js");
2
+ const init = require("./init-Bs-N_AZi.js");
3
3
  const grammy = require("grammy");
4
4
  const wallet = require("@ethersproject/wallet");
5
5
  const clobClient = require("@polymarket/clob-client");
@@ -1601,6 +1601,7 @@ async function main() {
1601
1601
  init.logger.blank();
1602
1602
  init.logger.info("正在退出...");
1603
1603
  await Promise.all([trader.shutdown(), telegramService.stop()]);
1604
+ await init.logger.flush();
1604
1605
  process.exit(0);
1605
1606
  };
1606
1607
  process.prependListener("SIGINT", () => {
@@ -98,6 +98,7 @@ const winstonLogger = winston__default.default.createLogger({
98
98
  });
99
99
  class Logger {
100
100
  initialized = false;
101
+ flushing = false;
101
102
  /**
102
103
  * 初始化日志模块(输出日志路径信息)
103
104
  */
@@ -190,6 +191,25 @@ ${this.withTimestamp(`❌ ${formatted}`)}`);
190
191
  console.log(this.withTimestamp(formatted));
191
192
  winstonLogger.info(formatted);
192
193
  }
194
+ /**
195
+ * 刷新日志输出(用于进程退出前)
196
+ */
197
+ async flush(timeoutMs = 1e3) {
198
+ if (this.flushing) {
199
+ return;
200
+ }
201
+ this.flushing = true;
202
+ await new Promise((resolve) => {
203
+ const timeout = setTimeout(() => {
204
+ resolve();
205
+ }, timeoutMs);
206
+ winstonLogger.once("finish", () => {
207
+ clearTimeout(timeout);
208
+ resolve();
209
+ });
210
+ winstonLogger.end();
211
+ });
212
+ }
193
213
  }
194
214
  const logger = new Logger();
195
215
  let globalRl = null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "polycopy",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "polycopy test",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -13,7 +13,6 @@
13
13
  "config": "node dist/config.js",
14
14
  "dev": "tsc --noEmit && vite build && node dist/index.js",
15
15
  "cli": "node dist/cli.js",
16
- "preuninstall": "node dist/cli.js stop 2>/dev/null || true",
17
16
  "prepublishOnly": "npm run build",
18
17
  "test": "HOME=$PWD node --import tsx tests/redeemer.test.ts",
19
18
  "test:redeemer": "HOME=$PWD node --import tsx tests/redeemer.test.ts"