From e73d14001294661341a195608bada441321a7130 Mon Sep 17 00:00:00 2001 From: Bogdan Fazakas Date: Fri, 7 May 2021 16:00:40 +0300 Subject: [PATCH 1/2] trigger check previous order after starting a compute job --- .../organisms/AssetActions/Compute/index.tsx | 6 +++++- src/utils/subgraph.ts | 12 ++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/components/organisms/AssetActions/Compute/index.tsx b/src/components/organisms/AssetActions/Compute/index.tsx index 06089e9de..9ced34559 100644 --- a/src/components/organisms/AssetActions/Compute/index.tsx +++ b/src/components/organisms/AssetActions/Compute/index.tsx @@ -136,6 +136,7 @@ export default function Compute({ timeout.toString() ) const assetType = ddo.findServiceByType('metadata').attributes.main.type + console.log('checkPreviousOrders asset ' + assetType + ' id= ', orderId) if (assetType === 'algorithm') { setPreviousAlgorithmOrderId(orderId) setHasPreviousAlgorithmOrder(!!orderId) @@ -430,7 +431,10 @@ export default function Compute({ Logger.log('[compute] Starting compute job response: ', response) - setHasPreviousDatasetOrder(true) + // setHasPreviousDatasetOrder(true) + // setHasPreviousAlgorithmOrder(true) + checkPreviousOrders(selectedAlgorithmAsset) + checkPreviousOrders(ddo) setIsPublished(true) } catch (error) { setError('Failed to start job!') diff --git a/src/utils/subgraph.ts b/src/utils/subgraph.ts index c424251ef..3edd20c82 100644 --- a/src/utils/subgraph.ts +++ b/src/utils/subgraph.ts @@ -75,14 +75,18 @@ export async function getPreviousOrders( variables ) if (fetchedPreviousOrders.data?.tokenOrders?.length === 0) return null + console.log('order fetchedPreviousOrders', fetchedPreviousOrders?.data) if (assetTimeout === '0') { return fetchedPreviousOrders?.data?.tokenOrders[0]?.tx } else { - const expiry = new BigNumber( + console.log( + 'order timestamp', fetchedPreviousOrders?.data?.tokenOrders[0]?.timestamp - ).plus(assetTimeout) - const unixTime = new BigNumber(Math.floor(Date.now() / 1000)) - if (unixTime.isLessThan(expiry)) { + ) + const expiry = + fetchedPreviousOrders?.data?.tokenOrders[0]?.timestamp * 1000 + + Number(assetTimeout) * 1000 + if (Date.now() <= expiry) { return fetchedPreviousOrders?.data?.tokenOrders[0]?.tx } else { return null From fadffb5d870ec6b258dcb3d4cd3594f222372b22 Mon Sep 17 00:00:00 2001 From: Bogdan Fazakas Date: Mon, 10 May 2021 15:35:49 +0300 Subject: [PATCH 2/2] added no cache fetch policy on appolo request and removed debug logs --- src/components/organisms/AssetActions/Compute/index.tsx | 7 ++----- src/utils/subgraph.ts | 8 ++------ 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/src/components/organisms/AssetActions/Compute/index.tsx b/src/components/organisms/AssetActions/Compute/index.tsx index 9ced34559..62c12d62b 100644 --- a/src/components/organisms/AssetActions/Compute/index.tsx +++ b/src/components/organisms/AssetActions/Compute/index.tsx @@ -136,7 +136,6 @@ export default function Compute({ timeout.toString() ) const assetType = ddo.findServiceByType('metadata').attributes.main.type - console.log('checkPreviousOrders asset ' + assetType + ' id= ', orderId) if (assetType === 'algorithm') { setPreviousAlgorithmOrderId(orderId) setHasPreviousAlgorithmOrder(!!orderId) @@ -431,10 +430,8 @@ export default function Compute({ Logger.log('[compute] Starting compute job response: ', response) - // setHasPreviousDatasetOrder(true) - // setHasPreviousAlgorithmOrder(true) - checkPreviousOrders(selectedAlgorithmAsset) - checkPreviousOrders(ddo) + await checkPreviousOrders(selectedAlgorithmAsset) + await checkPreviousOrders(ddo) setIsPublished(true) } catch (error) { setError('Failed to start job!') diff --git a/src/utils/subgraph.ts b/src/utils/subgraph.ts index 3edd20c82..05e16ef8b 100644 --- a/src/utils/subgraph.ts +++ b/src/utils/subgraph.ts @@ -53,7 +53,8 @@ async function fetchData( const client = getApolloClientInstance() const response = await client.query({ query: query, - variables: variables + variables: variables, + fetchPolicy: 'no-cache' }) return response } catch (error) { @@ -75,14 +76,9 @@ export async function getPreviousOrders( variables ) if (fetchedPreviousOrders.data?.tokenOrders?.length === 0) return null - console.log('order fetchedPreviousOrders', fetchedPreviousOrders?.data) if (assetTimeout === '0') { return fetchedPreviousOrders?.data?.tokenOrders[0]?.tx } else { - console.log( - 'order timestamp', - fetchedPreviousOrders?.data?.tokenOrders[0]?.timestamp - ) const expiry = fetchedPreviousOrders?.data?.tokenOrders[0]?.timestamp * 1000 + Number(assetTimeout) * 1000