11import { faPowerOff , faSpinnerThird , Icon } from "@rivet-gg/icons" ;
22import { useMutation , useQuery , useSuspenseQuery } from "@tanstack/react-query" ;
33import { useMatch } from "@tanstack/react-router" ;
4- import { createContext , type ReactNode , useContext , useMemo } from "react" ;
4+ import {
5+ createContext ,
6+ type ReactNode ,
7+ useContext ,
8+ useMemo ,
9+ useState ,
10+ } from "react" ;
511import { useInspectorCredentials } from "@/app/credentials-context" ;
612import { createInspectorActorContext } from "@/queries/actor-inspector" ;
713import { DiscreteCopyButton } from "../copy-area" ;
@@ -33,6 +39,12 @@ export function GuardConnectableInspector({
3339 } = useQuery ( {
3440 ...useDataProvider ( ) . actorQueryOptions ( actorId ) ,
3541 refetchInterval : 1000 ,
42+ select : ( data ) => ( {
43+ destroyedAt : data . destroyedAt ,
44+ sleepingAt : data . sleepingAt ,
45+ pendingAllocationAt : data . pendingAllocationAt ,
46+ startedAt : data . startedAt ,
47+ } ) ,
3648 } ) ;
3749
3850 if ( destroyedAt ) {
@@ -126,7 +138,7 @@ function ActorInspectorProvider({ children }: { children: ReactNode }) {
126138}
127139
128140function useActorRunner ( { actorId } : { actorId : ActorId } ) {
129- const { data : actor } = useSuspenseQuery (
141+ const { data : actor , isLoading } = useSuspenseQuery (
130142 useDataProvider ( ) . actorQueryOptions ( actorId ) ,
131143 ) ;
132144
@@ -142,19 +154,29 @@ function useActorRunner({ actorId }: { actorId: ActorId }) {
142154 throw new Error ( "Actor is missing required fields" ) ;
143155 }
144156
145- const { data : runner } = useQuery ( {
157+ const {
158+ data : runner ,
159+ isLoading : isLoadingRunner ,
160+ isSuccess,
161+ } = useQuery ( {
146162 ...useEngineCompatDataProvider ( ) . runnerByNameQueryOptions ( {
147163 runnerName : actor . runner ,
148164 namespace : match . params . namespace ,
149165 } ) ,
166+ retryDelay : 10_000 ,
150167 refetchInterval : 1000 ,
151168 } ) ;
152169
153- return { actor, runner } ;
170+ return {
171+ actor,
172+ runner,
173+ isLoading : isLoading || isLoadingRunner ,
174+ isSuccess,
175+ } ;
154176}
155177
156178function useActorEngineContext ( { actorId } : { actorId : ActorId } ) {
157- const { actor, runner } = useActorRunner ( { actorId } ) ;
179+ const { actor, runner, isLoading } = useActorRunner ( { actorId } ) ;
158180
159181 const actorContext = useMemo ( ( ) => {
160182 return createInspectorActorContext ( {
@@ -164,7 +186,7 @@ function useActorEngineContext({ actorId }: { actorId: ActorId }) {
164186 } ) ;
165187 } , [ runner ?. metadata ?. inspectorToken ] ) ;
166188
167- return { actorContext, actor, runner } ;
189+ return { actorContext, actor, runner, isLoading } ;
168190}
169191
170192function ActorEngineProvider ( {
@@ -174,7 +196,9 @@ function ActorEngineProvider({
174196 actorId : ActorId ;
175197 children : ReactNode ;
176198} ) {
177- const { actorContext, actor, runner } = useActorEngineContext ( { actorId } ) ;
199+ const { actorContext, actor, runner } = useActorEngineContext ( {
200+ actorId,
201+ } ) ;
178202
179203 if ( ! runner || ! actor . runner ) {
180204 return (
@@ -207,6 +231,7 @@ function NoRunnerInfo({ runner }: { runner: string }) {
207231 < span className = "font-mono-console" > { runner } </ span >
208232 </ DiscreteCopyButton >
209233 </ p >
234+ < p > Will retry automatically in the background.</ p >
210235 </ Info >
211236 ) ;
212237}
@@ -232,22 +257,24 @@ function WakeUpActorButton({ actorId }: { actorId: ActorId }) {
232257}
233258
234259function AutoWakeUpActor ( { actorId } : { actorId : ActorId } ) {
235- const { runner, actor, actorContext } = useActorEngineContext ( { actorId } ) ;
260+ const { runner, actor, actorContext } = useActorEngineContext ( {
261+ actorId,
262+ } ) ;
236263
237- const { isPending } = useQuery (
264+ useQuery (
238265 actorContext . actorAutoWakeUpQueryOptions ( actorId , {
239266 enabled : ! ! runner ,
240267 } ) ,
241268 ) ;
242269
243270 if ( ! runner ) return < NoRunnerInfo runner = { actor . runner || "unknown" } /> ;
244271
245- return isPending ? (
272+ return (
246273 < Info >
247274 < div className = "flex items-center" >
248275 < Icon icon = { faSpinnerThird } className = "animate-spin mr-2" />
249276 Waiting for Actor to wake...
250277 </ div >
251278 </ Info >
252- ) : null ;
279+ ) ;
253280}
0 commit comments