@@ -5,11 +5,49 @@ function App() {
5
5
const [ location , setLocation ] = useState ( '' ) ;
6
6
const [ planet , setPlanet ] = useState ( null )
7
7
8
- const handleRestCall = ( ) => {
9
- fetch ( `http://sömi-weather.ch/api/get-the-star-wars-planets-mapping-for-the-current-temperature-completely-and-utterly-accurate?temp=${ location } ` )
10
- . then ( ( response ) => response . json ( ) )
11
- . then ( ( data ) => setPlanet ( data ) )
12
- . catch ( ( error ) => console . error ( error ) ) ;
8
+ const handleRestCall = async ( ) => {
9
+ const temp = await getTemp ( ) ;
10
+ const imgRes = await fetch ( `http://sömi-weather.ch/api/get-the-star-wars-planets-mapping-for-the-current-temperature-completely-and-utterly-accurate?temp=${ temp } ` )
11
+ const imgJson = await imgRes . json ( ) ;
12
+
13
+ setPlanet ( imgJson ) ;
14
+ } ;
15
+
16
+ const getTemp = async ( ) => {
17
+ const res = await fetch ( `http://localhost:8080/engine-rest/process-definition/key/Process_13h4fbi/start` , {
18
+ method : "POST" ,
19
+ headers : {
20
+ "Content-Type" : "application/json"
21
+ } ,
22
+ body : JSON . stringify (
23
+ {
24
+ "businessKey" : "yourBusinessKey" ,
25
+ "variables" : {
26
+ "location" : { "value" : location , "type" : "String" }
27
+ }
28
+ }
29
+ )
30
+ } ) ;
31
+ const json = await res . json ( ) ;
32
+ const id = await json . id ;
33
+
34
+ for ( let i = 0 ; i < 10 ; i ++ )
35
+ {
36
+ await delay ( 500 ) ;
37
+ try
38
+ {
39
+ const varRes = await fetch ( `http://localhost:8080/engine-rest/history/variable-instance?processInstanceId=${ id } &variableName=temp` )
40
+ const varJson = await varRes . json ( ) ;
41
+ const temp = varJson . value ;
42
+
43
+ return temp ;
44
+ }
45
+ catch ( err )
46
+ {
47
+ console . log ( err ) ;
48
+ console . log ( "retrying" ) ;
49
+ }
50
+ }
13
51
} ;
14
52
15
53
return (
@@ -26,6 +64,13 @@ function App() {
26
64
) ;
27
65
}
28
66
67
+ function delay ( time ) {
68
+ return new Promise ( ( resolve ) => {
69
+ setTimeout ( ( ) => resolve ( ) , time ) ;
70
+ } ) ;
71
+ }
72
+
73
+
29
74
export function Planet ( { planet } ) {
30
75
const { name, image} = planet
31
76
0 commit comments