Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: duplicate ctd jobs from multiple provider endpoints #518

Merged
merged 1 commit into from
Mar 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/@utils/compute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,24 @@ async function getJobs(
return computeJobs
}

/**
* in case multiple providers return the same computeJob, filter these duplicates
* e.g. same instance listens on multiple domains
*/
export function filterForUniqueJobs(
jobs: ComputeJobMetaData[],
assets: Asset[]
): ComputeJobMetaData[] {
return jobs.filter((job) => {
const { inputDID, providerUrl } = job

// compare providerUrl where the job status was accessed from
// with the serviceEndpoint found in asset with first inputDID
const inputAsset = assets.find((asset) => asset.id === inputDID[0])
return providerUrl === inputAsset?.services[0]?.serviceEndpoint
})
}

export async function getComputeJobs(
chainIds: number[],
accountId: string,
Expand Down Expand Up @@ -353,7 +371,9 @@ export async function getComputeJobs(
providerUrls.push(asset.services[0].serviceEndpoint)
)

computeResult.computeJobs = await getJobs(providerUrls, accountId, assets)
const allProviderJobs = await getJobs(providerUrls, accountId, assets)
computeResult.computeJobs = filterForUniqueJobs(allProviderJobs, assets)

computeResult.isLoaded = true

return computeResult
Expand Down
Loading