All updates is working but require extend presignUrl responce.

pull/516/head
Andrey Dolgolev 2021-12-22 18:55:42 +02:00
rodzic 968a1ddf45
commit 95b6ccdb4e
7 zmienionych plików z 82 dodań i 71 usunięć

Wyświetl plik

@ -1,6 +1,7 @@
"""
The Mooncrawl HTTP API
"""
from datetime import datetime, timedelta
import logging
from os import times
import time
@ -141,12 +142,16 @@ async def status_handler(
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

Wyświetl plik

@ -865,6 +865,14 @@ def stats_generate_api_task(
address = subscription_by_id[subscription_id].resource_data["address"]
crawler_label = CRAWLER_LABEL
if address in (
"0xdC0479CC5BbA033B3e7De9F178607150B3AbCe1f",
"0xA2a13cE1824F3916fC84C65e559391fc6674e6e8",
):
crawler_label = "moonworm"
generic = dashboard_subscription_filters["generic"]
if not subscription_by_id[subscription_id].resource_data["abi"]:
@ -913,6 +921,7 @@ def stats_generate_api_task(
db_session=db_session,
blockchain_type=blockchain_type,
address=address,
crawler_label=crawler_label,
),
}
)
@ -929,6 +938,7 @@ def stats_generate_api_task(
select_expression=get_label_model(blockchain_type),
blockchain_type=blockchain_type,
address=address,
crawler_label=crawler_label,
),
}
)
@ -949,6 +959,7 @@ def stats_generate_api_task(
),
blockchain_type=blockchain_type,
address=address,
crawler_label=crawler_label,
),
}
)
@ -977,6 +988,7 @@ def stats_generate_api_task(
functions=methods,
start=start_date,
metric_type="tx_call",
crawler_label=crawler_label,
)
s3_data_object["functions"] = functions_calls_data
@ -989,6 +1001,7 @@ def stats_generate_api_task(
functions=events,
start=start_date,
metric_type="event",
crawler_label=crawler_label,
)
s3_data_object["events"] = events_data

Wyświetl plik

@ -13,6 +13,7 @@ import {
EditablePreview,
Button,
} from "@chakra-ui/react";
import { RepeatIcon } from "@chakra-ui/icons";
import Scrollable from "../../src/components/Scrollable";
import RangeSelector from "../../src/components/RangeSelector";
import useDashboard from "../../src/core/hooks/useDashboard";
@ -46,7 +47,7 @@ const Analytics = () => {
deleteDashboard,
updateDashboard,
refreshDashboard,
} = useDashboard(dashboardId, timeRange);
} = useDashboard(dashboardId);
const { subscriptionsCache } = useSubscriptions();
@ -88,6 +89,13 @@ const Analytics = () => {
const plotMinW = "250px";
const referesh_graf = function () {
refreshDashboard.mutate({
timeRange: timeRange,
dashboardId: dashboardCache.data.id,
});
};
return (
<Scrollable>
<Flex
@ -148,6 +156,15 @@ const Analytics = () => {
variant="outline"
icon={<BsGear />}
/>
<IconButton
icon={<RepeatIcon />}
variant="ghost"
colorScheme="green"
size="sm"
onClick={() => {
referesh_graf();
}}
/>
</Stack>
<Flex w="100%" direction="row" flexWrap="wrap-reverse" id="container">
@ -177,12 +194,12 @@ const Analytics = () => {
>
{name ?? ""}
</Text>
<SubscriptionReport
timeRange={timeRange}
url={s3PresignedURLs[timeRange]}
id={dashboardId}
refetchLinks={dashboardLinksCache.refetch}
refreshDashboard={refreshDashboard}
/>
</Flex>
);

Wyświetl plik

@ -10,7 +10,6 @@ import {
Container,
chakra,
Link,
IconButton,
} from "@chakra-ui/react";
import { v4 } from "uuid";
@ -22,16 +21,8 @@ timeMap[HOUR_KEY] = "hour";
timeMap[DAY_KEY] = "day";
timeMap[WEEK_KEY] = "week";
const SubscriptionReport = ({
timeRange,
url,
id,
refetchLinks,
refreshDashboard,
}) => {
const { data, isLoading, failureCount, refetch, dataUpdatedAt } = usePresignedURL({
const SubscriptionReport = ({ timeRange, url, id, refetchLinks }) => {
const { data, isLoading, failureCount } = usePresignedURL({
url: url,
isEnabled: true,
id: id,
@ -40,15 +31,9 @@ const SubscriptionReport = ({
hideToastOn404: true,
});
const plotMinW = "250px";
console.log(data, isLoading);
if (failureCount < 1 && (!data || isLoading)) return <Spinner />;
if (failureCount >= 1 && (!data || isLoading))
const referesh_graf = function () {
refreshDashboard.refetch();
dataUpdatedAt = new Date().toUTCString();
refetch();
};
if (failureCount >= 1 && (!data || isLoading)) {
return (
<Container
w="100%"
@ -82,7 +67,8 @@ const SubscriptionReport = ({
<br />
</Container>
);
>>>>>>> main
}
return (
<Flex
w="100%"
@ -91,15 +77,6 @@ const SubscriptionReport = ({
flexBasis={plotMinW}
direction="column"
>
<IconButton
icon={<RepeatIcon />}
variant="ghost"
colorScheme="green"
size="sm"
onClick={() => {
referesh_graf();
}}
/>
<Flex
bgColor="blue.50"
direction={["column", "row", null]}

Wyświetl plik

@ -1,13 +1,14 @@
import { useMutation, useQuery } from "react-query";
import { useMutation, useQuery, useQueryClient } from "react-query";
import { useRouter, useToast } from ".";
import { queryCacheProps } from "./hookCommon";
import { DashboardService } from "../services";
import { useContext } from "react";
import UserContext from "../providers/UserProvider/context";
const useDashboard = (dashboardId, timeRange) => {
const useDashboard = (dashboardId) => {
const toast = useToast();
const router = useRouter();
const queryClient = useQueryClient();
const { user } = useContext(UserContext);
const dashboardsListCache = useQuery(
@ -119,18 +120,36 @@ const useDashboard = (dashboardId, timeRange) => {
}
);
const refreshDashboard = useQuery(
["dashboardRefresh", { dashboardId }],
() => DashboardService.refreshDashboard(dashboardId, timeRange),
{
...queryCacheProps,
enabled: false,
onError: (error) => {
toast(error, "error");
},
enabled: !!user && !!dashboardId,
}
);
const refreshDashboard = useMutation(DashboardService.refreshDashboard, {
onSuccess: (data) => {
let new_state = {};
let current_links_state = queryClient.getQueryData([
"dashboardLinks",
{ dashboardId: dashboardId },
]);
new_state = current_links_state;
Object.keys(data.data).map((subscription) => {
Object.keys(data.data[subscription]).map((timeScale) => {
new_state.data[subscription][timeScale] =
data.data[subscription][timeScale];
});
});
queryClient.setQueryData(
["dashboardLinks", { dashboardId: dashboardId }],
new_state
);
},
onError: (error) => {
toast(error.error, "error", "Fail");
},
onSettled: () => {
dashboardsListCache.refetch();
},
});
return {
createDashboard,

Wyświetl plik

@ -1,4 +1,4 @@
import { useQuery } from "react-query";
import { useQuery, useQueryClient } from "react-query";
import { queryCacheProps } from "./hookCommon";
import { useToast } from ".";
import axios from "axios";
@ -14,34 +14,17 @@ const usePresignedURL = ({
const toast = useToast();
const getFromPresignedURL = async () => {
const queryState = queryClient.getQueryState([
"presignedURL",
cacheType,
id,
url,
]);
const response = await axios({
url: url,
// You can uncomment this to use mockupsLibrary in development
// url: `https://example.com/s3`,
method: "GET",
headers: {
"If-Modified-Since": queryState?.dataUpdatedAt,
},
});
return response.data;
};
<<<<<<< HEAD
const { data, isLoading, failureCount, refetch, dataUpdatedAt } = useQuery(
[`${cacheType}`, id, url],
=======
const { data, isLoading, error, failureCount } = useQuery(
["presignedURL", cacheType, id, url],
>>>>>>> main
getFromPresignedURL,
{
const { data, isLoading, error, failureCount, refetch, dataUpdatedAt } =
useQuery(["presignedURL", cacheType, id, url], getFromPresignedURL, {
...queryCacheProps,
refetchOnMount: false,
refetchOnWindowFocus: false,
@ -55,23 +38,20 @@ const usePresignedURL = ({
e?.response?.status === 403
) {
requestNewURLCallback();
} else if (e?.response?.status === 304) {
} else {
!hideToastOn404 && toast(error, "error");
}
},
}
);
});
return {
data,
isLoading,
error,
failureCount,
<<<<<<< HEAD
dataUpdatedAt,
refetch,
=======
>>>>>>> main
};
};

Wyświetl plik

@ -46,7 +46,7 @@ export const getDashboardLinks = (dashboardId) => {
});
};
export const refreshDashboard = (dashboardId, timeRange) => {
export const refreshDashboard = ({ dashboardId, timeRange }) => {
return http({
method: "POST",
url: `${API_URL}/dashboards/${dashboardId}/stats_update`,