Skip to content

feat: add periodic NPC quote sync to daemon#2

Closed
sh1ftred wants to merge 0 commit into
Egge21M:masterfrom
sh1ftred:master
Closed

feat: add periodic NPC quote sync to daemon#2
sh1ftred wants to merge 0 commit into
Egge21M:masterfrom
sh1ftred:master

Conversation

@sh1ftred
Copy link
Copy Markdown

  • Add /npc/sync endpoint to manually sync+redeem paid NPC quotes
  • Add /npc/quotes endpoint to view quote history
  • Add CLI commands: 'cocod npc quotes' and 'cocod npc sync'
  • Add periodic sync to daemon (every 5 min by default)
  • Configurable via COCOD_NPC_SYNC_INTERVAL_SECONDS env var
  • Extract syncNpcQuotes as reusable function in routes.ts

Copy link
Copy Markdown
Owner

@Egge21M Egge21M left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for tackling this! I think this is a great solution for the problem, but on the wrong layer. This repeats lots of logic that is already part of https://github.com/Egge21M/coco-cashu-plugin-npc and should be solved there.

So I propose that we add a sync method on the plugin API, that can be called by cocod through the CLI. Additionally we use the plugins internal timer logic and wire up the sinceStore to properly persist sync timestamps

Comment thread src/daemon.ts Outdated
import { createRouteHandlers, buildRoutes, syncNpcQuotes } from "./routes.js";
import type { WalletConfig } from "./utils/config.js";

const DEFAULT_NPC_SYNC_INTERVAL_SECONDS = 300;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The NPC Plugin for Coco has a syncIntervalMs option, that arms an additional interval based sync, additional to the websocket based sync.

Comment thread src/routes.ts Outdated
}

export async function syncNpcQuotes(manager: Manager, since = 0): Promise<NpcSyncResult> {
const quotes = await manager.ext.npc.getQuotesSince(since);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything after this point should not be necessary. The NPC Plugin is built to interact with the underlying coco services so that the synced mint quotes get added to the coco lifecycle automatically. I think we should add a sync method to the plugin API and call it from here

Comment thread src/routes.ts Outdated
);
}

const result = await syncNpcQuotes(state.manager, since);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be replaced by a sync function that needs to be added to the plugin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants