Skip to content

Commit

Permalink
Merge pull request #518 from deltaDAO/fix/duplicate-ctdjobs
Browse files Browse the repository at this point in the history
fix: duplicate ctd jobs from multiple provider endpoints
  • Loading branch information
oceanByte authored Mar 6, 2024
2 parents 67be130 + c1b59c2 commit 9e782b0
Showing 1 changed file with 21 additions and 1 deletion.
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

0 comments on commit 9e782b0

Please sign in to comment.