kopia lustrzana https://github.com/bugout-dev/moonstream
Add correct refreshing status.
rodzic
95b6ccdb4e
commit
ef064827fd
|
@ -428,7 +428,7 @@ async def get_dashboard_data_links_handler(
|
||||||
ExpiresIn=300,
|
ExpiresIn=300,
|
||||||
HttpMethod="GET",
|
HttpMethod="GET",
|
||||||
)
|
)
|
||||||
stats[subscription.id][timescale] = stats_presigned_url
|
stats[subscription.id][timescale] = {"url": stats_presigned_url}
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
logger.warning(
|
logger.warning(
|
||||||
f"Can't generate S3 presigned url in stats endpoint for Bucket:{MOONSTREAM_S3_SMARTCONTRACTS_ABI_BUCKET}, Key:{result_key} get error:{err}"
|
f"Can't generate S3 presigned url in stats endpoint for Bucket:{MOONSTREAM_S3_SMARTCONTRACTS_ABI_BUCKET}, Key:{result_key} get error:{err}"
|
||||||
|
|
|
@ -139,22 +139,25 @@ async def status_handler(
|
||||||
|
|
||||||
try:
|
try:
|
||||||
result_key = f'{MOONSTREAM_S3_SMARTCONTRACTS_ABI_PREFIX}/{dashboard.blockchain_by_subscription_id[subscription.resource_data["subscription_type_id"]]}/contracts_data/{subscription.resource_data["address"]}/{stats_update.dashboard_id}/v1/{timescale}.json'
|
result_key = f'{MOONSTREAM_S3_SMARTCONTRACTS_ABI_PREFIX}/{dashboard.blockchain_by_subscription_id[subscription.resource_data["subscription_type_id"]]}/contracts_data/{subscription.resource_data["address"]}/{stats_update.dashboard_id}/v1/{timescale}.json'
|
||||||
|
|
||||||
|
object = s3_client.head_object(
|
||||||
|
Bucket=subscription.resource_data["bucket"], Key=result_key
|
||||||
|
)
|
||||||
|
|
||||||
stats_presigned_url = s3_client.generate_presigned_url(
|
stats_presigned_url = s3_client.generate_presigned_url(
|
||||||
"get_object",
|
"get_object",
|
||||||
Params={
|
Params={
|
||||||
# "IfModifiedSince": datetime(2015, 1, 1),
|
|
||||||
# "IfUnmodifiedSince": datetime(2015, 1, 1),
|
|
||||||
"IfMatch": "757ab3614c58b5a184457d34dd104238",
|
|
||||||
"Bucket": subscription.resource_data["bucket"],
|
"Bucket": subscription.resource_data["bucket"],
|
||||||
"Key": result_key,
|
"Key": result_key,
|
||||||
},
|
},
|
||||||
ExpiresIn=300,
|
ExpiresIn=300,
|
||||||
HttpMethod="GET",
|
HttpMethod="GET",
|
||||||
)
|
)
|
||||||
print("stats_presigned_url", stats_presigned_url)
|
|
||||||
presigned_urls_response[subscription.id][
|
presigned_urls_response[subscription.id][timescale] = {
|
||||||
timescale
|
"url": stats_presigned_url,
|
||||||
] = stats_presigned_url
|
"headers": {"If-Modified-Since": object["LastModified"]},
|
||||||
|
}
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
logger.warning(
|
logger.warning(
|
||||||
f"Can't generate S3 presigned url in stats endpoint for Bucket:{subscription.resource_data['bucket']}, Key:{result_key} get error:{err}"
|
f"Can't generate S3 presigned url in stats endpoint for Bucket:{subscription.resource_data['bucket']}, Key:{result_key} get error:{err}"
|
||||||
|
|
|
@ -41,6 +41,7 @@ const Analytics = () => {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const overlay = useContext(OverlayContext);
|
const overlay = useContext(OverlayContext);
|
||||||
const { dashboardId } = router.params;
|
const { dashboardId } = router.params;
|
||||||
|
const [refreshingStatus, setRefreshingStatus] = useState(false);
|
||||||
const {
|
const {
|
||||||
dashboardCache,
|
dashboardCache,
|
||||||
dashboardLinksCache,
|
dashboardLinksCache,
|
||||||
|
@ -94,6 +95,7 @@ const Analytics = () => {
|
||||||
timeRange: timeRange,
|
timeRange: timeRange,
|
||||||
dashboardId: dashboardCache.data.id,
|
dashboardId: dashboardCache.data.id,
|
||||||
});
|
});
|
||||||
|
setRefreshingStatus(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -157,6 +159,7 @@ const Analytics = () => {
|
||||||
icon={<BsGear />}
|
icon={<BsGear />}
|
||||||
/>
|
/>
|
||||||
<IconButton
|
<IconButton
|
||||||
|
isLoading={refreshingStatus}
|
||||||
icon={<RepeatIcon />}
|
icon={<RepeatIcon />}
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
colorScheme="green"
|
colorScheme="green"
|
||||||
|
@ -197,9 +200,11 @@ const Analytics = () => {
|
||||||
|
|
||||||
<SubscriptionReport
|
<SubscriptionReport
|
||||||
timeRange={timeRange}
|
timeRange={timeRange}
|
||||||
url={s3PresignedURLs[timeRange]}
|
presignedRequest={s3PresignedURLs[timeRange]}
|
||||||
id={dashboardId}
|
id={dashboardId}
|
||||||
refetchLinks={dashboardLinksCache.refetch}
|
refetchLinks={dashboardLinksCache.refetch}
|
||||||
|
refreshingStatus={refreshingStatus}
|
||||||
|
setRefreshingStatus={setRefreshingStatus}
|
||||||
/>
|
/>
|
||||||
</Flex>
|
</Flex>
|
||||||
);
|
);
|
||||||
|
|
|
@ -21,17 +21,26 @@ timeMap[HOUR_KEY] = "hour";
|
||||||
timeMap[DAY_KEY] = "day";
|
timeMap[DAY_KEY] = "day";
|
||||||
timeMap[WEEK_KEY] = "week";
|
timeMap[WEEK_KEY] = "week";
|
||||||
|
|
||||||
const SubscriptionReport = ({ timeRange, url, id, refetchLinks }) => {
|
const SubscriptionReport = ({
|
||||||
|
timeRange,
|
||||||
|
presignedRequest,
|
||||||
|
id,
|
||||||
|
refetchLinks,
|
||||||
|
refreshingStatus: refreshingStatus,
|
||||||
|
setRefreshingStatus: setRefreshingStatus,
|
||||||
|
}) => {
|
||||||
const { data, isLoading, failureCount } = usePresignedURL({
|
const { data, isLoading, failureCount } = usePresignedURL({
|
||||||
url: url,
|
presignedRequest: presignedRequest,
|
||||||
isEnabled: true,
|
isEnabled: true,
|
||||||
id: id,
|
id: id,
|
||||||
cacheType: `${timeRange} subscription_report`,
|
cacheType: `${timeRange} subscription_report`,
|
||||||
requestNewURLCallback: refetchLinks,
|
requestNewURLCallback: refetchLinks,
|
||||||
hideToastOn404: true,
|
hideToastOn404: true,
|
||||||
|
refreshingStatus: refreshingStatus,
|
||||||
|
setRefreshingStatus: setRefreshingStatus,
|
||||||
});
|
});
|
||||||
const plotMinW = "250px";
|
const plotMinW = "250px";
|
||||||
console.log(data, isLoading);
|
console.log(refreshingStatus);
|
||||||
if (failureCount < 1 && (!data || isLoading)) return <Spinner />;
|
if (failureCount < 1 && (!data || isLoading)) return <Spinner />;
|
||||||
if (failureCount >= 1 && (!data || isLoading)) {
|
if (failureCount >= 1 && (!data || isLoading)) {
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -4,34 +4,50 @@ import { useToast } from ".";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
|
||||||
const usePresignedURL = ({
|
const usePresignedURL = ({
|
||||||
url,
|
presignedRequest,
|
||||||
cacheType,
|
cacheType,
|
||||||
id,
|
id,
|
||||||
requestNewURLCallback,
|
requestNewURLCallback,
|
||||||
isEnabled,
|
isEnabled,
|
||||||
hideToastOn404,
|
hideToastOn404,
|
||||||
|
refreshingStatus,
|
||||||
|
setRefreshingStatus,
|
||||||
}) => {
|
}) => {
|
||||||
const toast = useToast();
|
const toast = useToast();
|
||||||
|
|
||||||
const getFromPresignedURL = async () => {
|
const getFromPresignedURL = async () => {
|
||||||
const response = await axios({
|
let request_parameters = {
|
||||||
url: url,
|
url: presignedRequest.url,
|
||||||
// You can uncomment this to use mockupsLibrary in development
|
// You can uncomment this to use mockupsLibrary in development
|
||||||
// url: `https://example.com/s3`,
|
// url: `https://example.com/s3`,
|
||||||
|
headers: {},
|
||||||
method: "GET",
|
method: "GET",
|
||||||
|
};
|
||||||
|
console.log(presignedRequest);
|
||||||
|
if ("headers" in presignedRequest) {
|
||||||
|
Object.keys(presignedRequest.headers).map((key) => {
|
||||||
|
request_parameters["headers"][key] = presignedRequest.headers[key];
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await axios(request_parameters);
|
||||||
return response.data;
|
return response.data;
|
||||||
};
|
};
|
||||||
|
|
||||||
const { data, isLoading, error, failureCount, refetch, dataUpdatedAt } =
|
const { data, isLoading, error, failureCount, refetch } = useQuery(
|
||||||
useQuery(["presignedURL", cacheType, id, url], getFromPresignedURL, {
|
["presignedURL", cacheType, id, presignedRequest.url],
|
||||||
|
getFromPresignedURL,
|
||||||
|
{
|
||||||
...queryCacheProps,
|
...queryCacheProps,
|
||||||
refetchOnMount: false,
|
refetchOnMount: false,
|
||||||
refetchOnWindowFocus: false,
|
refetchOnWindowFocus: false,
|
||||||
refetchOnReconnect: false,
|
refetchOnReconnect: false,
|
||||||
staleTime: Infinity,
|
staleTime: Infinity,
|
||||||
enabled: isEnabled && url ? true : false,
|
enabled: isEnabled && presignedRequest.url ? true : false,
|
||||||
keepPreviousData: true,
|
keepPreviousData: true,
|
||||||
|
onSuccess: (e) => {
|
||||||
|
setRefreshingStatus(false);
|
||||||
|
},
|
||||||
onError: (e) => {
|
onError: (e) => {
|
||||||
if (
|
if (
|
||||||
e?.response?.data?.includes("Request has expired") ||
|
e?.response?.data?.includes("Request has expired") ||
|
||||||
|
@ -43,14 +59,14 @@ const usePresignedURL = ({
|
||||||
!hideToastOn404 && toast(error, "error");
|
!hideToastOn404 && toast(error, "error");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
data,
|
data,
|
||||||
isLoading,
|
isLoading,
|
||||||
error,
|
error,
|
||||||
failureCount,
|
failureCount,
|
||||||
dataUpdatedAt,
|
|
||||||
refetch,
|
refetch,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
Ładowanie…
Reference in New Issue