Skip to content

Commit

Permalink
Allow pluginId independent of partnerId
Browse files Browse the repository at this point in the history
This allows a single code instance, denoted by a pluginId, to be used with multiple apikeys which are bound to a partnerId.
  • Loading branch information
paullinator committed Oct 10, 2023
1 parent d613a36 commit cb5179b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/queryEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,13 @@ export async function queryEngine(): Promise<void> {
// loop over every pluginId that app uses
remainingPartners = Object.keys(app.partnerIds)
for (const partnerId in app.partnerIds) {
const pluginId = app.partnerIds[partnerId].pluginId ?? partnerId

if (config.soloPartnerId != null && config.soloPartnerId !== partnerId)
continue
remainingPartners.push(partnerId)
promiseArray.push(
runPlugin(app, partnerId, dbProgress).finally(() => {
runPlugin(app, partnerId, pluginId, dbProgress).finally(() => {
remainingPartners = remainingPartners.filter(
string => string !== partnerId
)
Expand Down Expand Up @@ -281,13 +283,14 @@ async function insertTransactions(
async function runPlugin(
app: ReturnType<typeof asApp>,
partnerId: string,
pluginId: string,
dbProgress: nano.DocumentScope<unknown>
): Promise<string> {
const start = Date.now()
let errorText = ''
try {
// obtains function that corresponds to current pluginId
const plugin = plugins.find(plugin => plugin.pluginId === partnerId)
const plugin = plugins.find(plugin => plugin.pluginId === pluginId)
// if current plugin is not within the list of partners skip to next
if (plugin === undefined) {
errorText = `Missing or disabled plugin ${app.appId.toLowerCase()}_${partnerId}`
Expand All @@ -296,7 +299,9 @@ async function runPlugin(
}

// get progress cache to see where previous query ended
datelog(`Starting with partner:${partnerId}, app: ${app.appId}`)
datelog(
`Starting with partner:${partnerId} plugin:${pluginId}, app: ${app.appId}`
)
const progressCacheFileName = `${app.appId.toLowerCase()}:${partnerId}`
const out = await dbProgress.get(progressCacheFileName).catch(e => {
if (e.error != null && e.error === 'not_found') {
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export const asStandardPluginParams = asObject({
})

const asPartnerInfo = asObject({
pluginId: asOptional(asString),
apiKeys: asMap(asString)
})

Expand Down

0 comments on commit cb5179b

Please sign in to comment.