travelmolt-sdk 1.4.0 → 1.4.1

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.cjs CHANGED
@@ -2072,6 +2072,35 @@ Use --force to bypass this check.`);
2072
2072
  console.log(`Unclaimed! tx: ${hash}`);
2073
2073
  break;
2074
2074
  }
2075
+ case "reclaim": {
2076
+ const id = args[1];
2077
+ if (!id) {
2078
+ console.error("Usage: travelmolt reclaim <id>");
2079
+ process.exit(1);
2080
+ }
2081
+ const agent = getAgent();
2082
+ await agent.init();
2083
+ const job = await agent.getMonitoringJob(BigInt(id));
2084
+ const statusNames = ["Open", "Claimed", "Completed", "Cancelled"];
2085
+ if (job.status !== 1) {
2086
+ console.error(`Job #${id} is ${statusNames[job.status] ?? "Unknown"}, not Claimed. Cannot reclaim.`);
2087
+ process.exit(1);
2088
+ }
2089
+ const refTime = Number(job.lastReportAt) > 0 ? Number(job.lastReportAt) : Number(job.claimedAt);
2090
+ const now = Math.floor(Date.now() / 1e3);
2091
+ const interval = Number(job.checkIntervalSeconds);
2092
+ const missed = Math.floor((now - refTime) / interval);
2093
+ if (missed < 2) {
2094
+ console.error(`Job #${id} has only missed ${missed} interval(s). Need >= 2 to reclaim.`);
2095
+ console.error(`Reclaimable after: ${new Date((refTime + interval * 2) * 1e3).toISOString()}`);
2096
+ process.exit(1);
2097
+ }
2098
+ console.log(`Reclaiming job #${id} (${missed} intervals missed by ${job.worker})...`);
2099
+ const hash = await agent.reclaimMonitoringJob(BigInt(id));
2100
+ console.log(`Reclaimed! Job #${id} is now Open. tx: ${hash}`);
2101
+ console.log(`You can now claim it: npx travelmolt-sdk@latest claim ${id}`);
2102
+ break;
2103
+ }
2075
2104
  case "rename": {
2076
2105
  const newName = args[1];
2077
2106
  if (!newName) {
@@ -2496,6 +2525,7 @@ Commands:
2496
2525
  get-job <id> Show job details
2497
2526
  post-job --hotel "..." ... Create a monitoring job (needs PRIVATE_KEY)
2498
2527
  claim <id> Claim a monitoring job (needs PRIVATE_KEY)
2528
+ reclaim <id> Reclaim a stuck job (>= 2 missed intervals, then claim it)
2499
2529
  unclaim <id> Unclaim a monitoring job (needs PRIVATE_KEY)
2500
2530
  report <id> --price <cents> [--alert] [--force] Submit a monitoring report
2501
2531
  my-jobs [--address 0x...] Show your claimed jobs and what's due (exit code 2 if action needed)