1
1
import * as RestAPI from "admin/rest_api" ;
2
- import Request from "libs/request" ;
3
2
import Toast from "libs/toast" ;
4
3
import _ from "lodash" ;
5
4
import messages from "messages" ;
5
+ import type { APIBuildInfoDatastore , APIBuildInfoWk } from "types/api_types" ;
6
6
7
7
// Create a throttled function which depends on its arguments.
8
8
// That way, each datastore is checked for health in a throttled and isolated manner
9
- // @ts -expect-error ts-migrate(7006) FIXME: Parameter 'func' implicitly has an 'any' type.
10
- const memoizedThrottle = ( func , wait = 0 , options = { } ) : ( ( ...args : Array < any > ) => any ) => {
9
+ const memoizedThrottle = < F extends ( ...args : Array < any > ) => any > ( func : F , wait = 0 ) : F => {
11
10
// Memoize the creation of a throttling function
12
- // @ts -expect-error ts-migrate(2339) FIXME: Property 'resolver' does not exist on type '{}'.
13
- const mem = _ . memoize ( ( ) => _ . throttle ( func , wait , options ) , options . resolver ) ;
11
+ const mem = _ . memoize ( ( ..._args : any [ ] ) => _ . throttle ( func , wait ) ) ;
14
12
15
- return ( ...args : Array < any > ) => {
13
+ return ( ( ...args : Parameters < F > ) => {
16
14
// look up (or create) the throttling function and invoke it
17
- // @ts -expect-error ts-migrate(2556) FIXME: Expected 0 arguments, but got 1 or more.
18
- mem ( ...args ) ( ...args ) ;
19
- } ;
15
+ return mem ( ...args ) ( ...args ) ;
16
+ } ) as F ;
20
17
} ;
21
18
22
19
// Do not call this function directly, but call pingMentionedDataStores instead
@@ -34,10 +31,10 @@ const pingDataStoreIfAppropriate = memoizedThrottle(async (requestedUrl: string)
34
31
return ;
35
32
}
36
33
37
- const stores = [
34
+ const stores : Array < { url : string ; path : "tracings" | "data" } > = [
38
35
{ ...tracingstore , path : "tracings" } ,
39
- ...datastores . map ( ( datastore ) => ( { ...datastore , path : "data" } ) ) ,
40
- ] ;
36
+ ...datastores . map ( ( datastore ) => ( { ...datastore , path : "data" as const } ) ) ,
37
+ ] as const ;
41
38
42
39
if ( isInMaintenance ) {
43
40
Toast . warning ( messages . planned_maintenance ) ;
@@ -46,13 +43,14 @@ const pingDataStoreIfAppropriate = memoizedThrottle(async (requestedUrl: string)
46
43
47
44
if ( usedStore != null ) {
48
45
const { url, path } = usedStore ;
49
- const healthEndpoint = `${ url } /${ path } /health` ;
50
- Request . triggerRequest ( healthEndpoint , {
51
- doNotInvestigate : true ,
52
- mode : "cors" ,
53
- timeout : 5000 ,
54
- } ) . then (
55
- ( ) => checkVersionMismatch ( url ) ,
46
+ RestAPI . pingHealthEndpoint ( url , path ) . then (
47
+ ( ) => {
48
+ if ( usedStore . path === "data" ) {
49
+ // Only check a version mismatch for the data store, because
50
+ // the tracingstore doesn't serve a tracingstoreApiVersion field.
51
+ checkVersionMismatchInDataStore ( url ) ;
52
+ }
53
+ } ,
56
54
( ) =>
57
55
Toast . warning (
58
56
messages [ "datastore.health" ] ( {
@@ -64,15 +62,13 @@ const pingDataStoreIfAppropriate = memoizedThrottle(async (requestedUrl: string)
64
62
}
65
63
} , 5000 ) ;
66
64
67
- async function checkVersionMismatch ( url : string ) {
68
- const [ buildinfoWebknossos , buildinfoDatastore ] = await Promise . all ( [
65
+ async function checkVersionMismatchInDataStore ( datastoreUrl : string ) {
66
+ const [ buildinfoWebknossos , buildinfoDatastore ] = ( await Promise . all ( [
69
67
RestAPI . getBuildInfo ( ) ,
70
- RestAPI . getDataStoreBuildInfo ( url ) ,
71
- ] ) ;
68
+ RestAPI . getDataOrTracingStoreBuildInfo ( datastoreUrl ) ,
69
+ ] ) ) as [ APIBuildInfoWk , APIBuildInfoDatastore ] ;
72
70
const expectedDatastoreApiVersion = buildinfoWebknossos . webknossos . datastoreApiVersion ;
73
- const buildInfoWebknossosDatastore = buildinfoDatastore . webknossosDatastore
74
- ? buildinfoDatastore . webknossosDatastore
75
- : buildinfoDatastore . webknossos ;
71
+ const buildInfoWebknossosDatastore = buildinfoDatastore . webknossosDatastore ;
76
72
const suppliedDatastoreApiVersion = buildInfoWebknossosDatastore . datastoreApiVersion ;
77
73
78
74
if (
@@ -83,7 +79,7 @@ async function checkVersionMismatch(url: string) {
83
79
messages [ "datastore.version.too_new" ] ( {
84
80
expectedDatastoreApiVersion,
85
81
suppliedDatastoreApiVersion,
86
- url ,
82
+ datastoreUrl ,
87
83
} ) ,
88
84
) ;
89
85
} else if (
@@ -94,7 +90,7 @@ async function checkVersionMismatch(url: string) {
94
90
messages [ "datastore.version.too_old" ] ( {
95
91
expectedDatastoreApiVersion,
96
92
suppliedDatastoreApiVersion,
97
- url ,
93
+ datastoreUrl ,
98
94
} ) ,
99
95
) ;
100
96
}
0 commit comments