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,
|
||||
HttpMethod="GET",
|
||||
)
|
||||
stats[subscription.id][timescale] = stats_presigned_url
|
||||
stats[subscription.id][timescale] = {"url": stats_presigned_url}
|
||||
except Exception as err:
|
||||
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}"
|
||||
|
|
|
@ -139,22 +139,25 @@ async def status_handler(
|
|||
|
||||
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'
|
||||
|
||||
object = s3_client.head_object(
|
||||
Bucket=subscription.resource_data["bucket"], Key=result_key
|
||||
)
|
||||
|
||||
stats_presigned_url = s3_client.generate_presigned_url(
|
||||
"get_object",
|
||||
Params={
|
||||
# "IfModifiedSince": datetime(2015, 1, 1),
|
||||
# "IfUnmodifiedSince": datetime(2015, 1, 1),
|
||||
"IfMatch": "757ab3614c58b5a184457d34dd104238",
|
||||
"Bucket": subscription.resource_data["bucket"],
|
||||
"Key": result_key,
|
||||
},
|
||||
ExpiresIn=300,
|
||||
HttpMethod="GET",
|
||||
)
|
||||
print("stats_presigned_url", stats_presigned_url)
|
||||
presigned_urls_response[subscription.id][
|
||||
timescale
|
||||
] = stats_presigned_url
|
||||
|
||||
presigned_urls_response[subscription.id][timescale] = {
|
||||
"url": stats_presigned_url,
|
||||
"headers": {"If-Modified-Since": object["LastModified"]},
|
||||
}
|
||||
except Exception as err:
|
||||
logger.warning(
|
||||
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 overlay = useContext(OverlayContext);
|
||||
const { dashboardId } = router.params;
|
||||
const [refreshingStatus, setRefreshingStatus] = useState(false);
|
||||
const {
|
||||
dashboardCache,
|
||||
dashboardLinksCache,
|
||||
|
@ -94,6 +95,7 @@ const Analytics = () => {
|
|||
timeRange: timeRange,
|
||||
dashboardId: dashboardCache.data.id,
|
||||
});
|
||||
setRefreshingStatus(true);
|
||||
};
|
||||
|
||||
return (
|
||||
|
@ -157,6 +159,7 @@ const Analytics = () => {
|
|||
icon={<BsGear />}
|
||||
/>
|
||||
<IconButton
|
||||
isLoading={refreshingStatus}
|
||||
icon={<RepeatIcon />}
|
||||
variant="ghost"
|
||||
colorScheme="green"
|
||||
|
@ -197,9 +200,11 @@ const Analytics = () => {
|
|||
|
||||
<SubscriptionReport
|
||||
timeRange={timeRange}
|
||||
url={s3PresignedURLs[timeRange]}
|
||||
presignedRequest={s3PresignedURLs[timeRange]}
|
||||
id={dashboardId}
|
||||
refetchLinks={dashboardLinksCache.refetch}
|
||||
refreshingStatus={refreshingStatus}
|
||||
setRefreshingStatus={setRefreshingStatus}
|
||||
/>
|
||||
</Flex>
|
||||
);
|
||||
|
|
|
@ -21,17 +21,26 @@ timeMap[HOUR_KEY] = "hour";
|
|||
timeMap[DAY_KEY] = "day";
|
||||
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({
|
||||
url: url,
|
||||
presignedRequest: presignedRequest,
|
||||
isEnabled: true,
|
||||
id: id,
|
||||
cacheType: `${timeRange} subscription_report`,
|
||||
requestNewURLCallback: refetchLinks,
|
||||
hideToastOn404: true,
|
||||
refreshingStatus: refreshingStatus,
|
||||
setRefreshingStatus: setRefreshingStatus,
|
||||
});
|
||||
const plotMinW = "250px";
|
||||
console.log(data, isLoading);
|
||||
console.log(refreshingStatus);
|
||||
if (failureCount < 1 && (!data || isLoading)) return <Spinner />;
|
||||
if (failureCount >= 1 && (!data || isLoading)) {
|
||||
return (
|
||||
|
|
|
@ -4,34 +4,50 @@ import { useToast } from ".";
|
|||
import axios from "axios";
|
||||
|
||||
const usePresignedURL = ({
|
||||
url,
|
||||
presignedRequest,
|
||||
cacheType,
|
||||
id,
|
||||
requestNewURLCallback,
|
||||
isEnabled,
|
||||
hideToastOn404,
|
||||
refreshingStatus,
|
||||
setRefreshingStatus,
|
||||
}) => {
|
||||
const toast = useToast();
|
||||
|
||||
const getFromPresignedURL = async () => {
|
||||
const response = await axios({
|
||||
url: url,
|
||||
let request_parameters = {
|
||||
url: presignedRequest.url,
|
||||
// You can uncomment this to use mockupsLibrary in development
|
||||
// url: `https://example.com/s3`,
|
||||
headers: {},
|
||||
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;
|
||||
};
|
||||
|
||||
const { data, isLoading, error, failureCount, refetch, dataUpdatedAt } =
|
||||
useQuery(["presignedURL", cacheType, id, url], getFromPresignedURL, {
|
||||
const { data, isLoading, error, failureCount, refetch } = useQuery(
|
||||
["presignedURL", cacheType, id, presignedRequest.url],
|
||||
getFromPresignedURL,
|
||||
{
|
||||
...queryCacheProps,
|
||||
refetchOnMount: false,
|
||||
refetchOnWindowFocus: false,
|
||||
refetchOnReconnect: false,
|
||||
staleTime: Infinity,
|
||||
enabled: isEnabled && url ? true : false,
|
||||
enabled: isEnabled && presignedRequest.url ? true : false,
|
||||
keepPreviousData: true,
|
||||
onSuccess: (e) => {
|
||||
setRefreshingStatus(false);
|
||||
},
|
||||
onError: (e) => {
|
||||
if (
|
||||
e?.response?.data?.includes("Request has expired") ||
|
||||
|
@ -43,14 +59,14 @@ const usePresignedURL = ({
|
|||
!hideToastOn404 && toast(error, "error");
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
return {
|
||||
data,
|
||||
isLoading,
|
||||
error,
|
||||
failureCount,
|
||||
dataUpdatedAt,
|
||||
refetch,
|
||||
};
|
||||
};
|
||||
|
|
Ładowanie…
Reference in New Issue