Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat(site): add download logs option#13466

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
BrunoQuaresma merged 27 commits intomainfrombq/download-logs
Jun 7, 2024
Merged

Conversation

BrunoQuaresma
Copy link
Collaborator

Close#12485

Screen.Recording.2024-06-03.at.15.31.41.mov

@BrunoQuaresmaBrunoQuaresma requested a review froma teamJune 4, 2024 14:36
@BrunoQuaresmaBrunoQuaresma self-assigned thisJun 4, 2024
@BrunoQuaresmaBrunoQuaresma requested review fromcode-asher and removed request fora teamJune 4, 2024 14:36
Copy link
Member

@code-ashercode-asher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Very handy!

BrunoQuaresma reacted with heart emoji
Copy link
Member

@ParkreinerParkreiner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Looks good so far! I feel like there might be some ways to tighten upuseAgentLogs, but I'll come back to this tomorrow morning, when I'm not so tired

@Parkreiner
Copy link
Member

Parkreiner commentedJun 6, 2024
edited
Loading

@BrunoQuaresma What do you think of this?

typeUseAgentLogsOptions=Readonly<{workspaceId:string;agentId:string;agentLifeCycleState:WorkspaceAgentLifecycle;enabled?:boolean;}>;exportfunctionuseAgentLogs(options:UseAgentLogsOptions,):readonlyWorkspaceAgentLog[]|undefined{const{ workspaceId, agentId, agentLifeCycleState, enabled=true}=options;constqueryClient=useQueryClient();constqueryOptions=agentLogs(workspaceId,agentId);const{ data}=useQuery({    ...queryOptions,    enabled,select:(logs)=>{return{        logs,lastLogId:logs.at(-1)?.id??0,};},});constsocketRef=useRef<WebSocket|null>(null);constlastInitializedAgentIdRef=useRef<string|null>(null);constaddLogs=useEffectEvent((newLogs:WorkspaceAgentLog[])=>{queryClient.setQueryData(queryOptions.queryKey,(oldLogs:WorkspaceAgentLog[]=[])=>[...oldLogs, ...newLogs],);});useEffect(()=>{constisSameAgentId=agentId===lastInitializedAgentIdRef.current;if(!isSameAgentId){socketRef.current?.close();}constcannotCreateSocket=agentLifeCycleState!=="starting"||data===undefined;if(cannotCreateSocket){return;}constsocket=watchWorkspaceAgentLogs(agentId,{after:data.lastLogId,onMessage:(newLogs)=>{// Prevent new logs getting added when a connection is not openif(socket.readyState===WebSocket.OPEN){addLogs(newLogs);;}},onError:(error)=>{// Might be able to put more precise error handling here?console.error(error);},});socketRef.current=socket;lastInitializedAgentIdRef.current=agentId;},[addLogs,agentId,agentLifeCycleState,data]);// The above effect is likely going to run a lot because we don't know when or// how agentLifeCycleState will change over time (it's a union of nine// values). The only way to ensure that we only close when we unmount is by// putting the logic into a separate effect with an empty dependency arrayuseEffect(()=>{constcloseSocketOnUnmount=()=>socketRef.current?.close();returncloseSocketOnUnmount;},[]);returndata?.logs;}
BrunoQuaresma reacted with thumbs up emoji

@Parkreiner
Copy link
Member

Parkreiner commentedJun 6, 2024
edited
Loading

@BrunoQuaresma Realized one other thing: if the query for the agent logs hook is only able to run once, is it a problem if the query doesn't come back in the starting state at first?

I don't know enough about lifecycle states, and I don't know if there's a flow chart for how the states can transition into each other anywhere

@BrunoQuaresma
Copy link
CollaboratorAuthor

@BrunoQuaresma Realized one other thing: if the query for the agent logs hook is only able to run once, is it a problem if the query doesn't come back in the starting state at first?

Do you have a use case that could contextualize this better?

@Parkreiner
Copy link
Member

Parkreiner commentedJun 6, 2024
edited
Loading

Do you have a use case that could contextualize this better?
@BrunoQuaresma To be honest, I'm not sure – I was kind of hoping you would know

Looking at the type definition forWorkspaceAgentLifecycle, I see that there's aready state that sees like it could be a good candidate for the log functionality. But I don't know if that's actually true, or if there's some nuance that I'm missing. I would assume that from the names, a workspace transitions fromstarting toready

My main worry was, if a workspace is already in theready state, is it okay to skip generating logs for it? Or is it impossible for that to happen? The current logic only makes logs if we're specifically starting up

@BrunoQuaresma
Copy link
CollaboratorAuthor

@Parkreiner I think I maybe answered this question here#13466 (comment)

@BrunoQuaresma
Copy link
CollaboratorAuthor

@Parkreiner I had to roll back to the previoususeAgentLogs implementation because it was causing a loop since the data was in the dependencies list. I also removed the select option to get the last agent log ID because it updates on every data change keeping it unstable.

@Parkreiner
Copy link
Member

@Parkreiner I had to roll back to the previoususeAgentLogs implementation because it was causing a loop since the data was in the dependencies list. I also removed the select option to get the last agent log ID because it updates on every data change keeping it unstable.

@BrunoQuaresma Ah, right – forgot that we are mutating the cache, so the data is potentially going to be changing a lot

Copy link
Member

@ParkreinerParkreiner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Looks good! And glad you caught that infinite loop issue

Copy link
Member

@code-ashercode-asher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Looks good to me!

@BrunoQuaresmaBrunoQuaresma merged commit056a697 intomainJun 7, 2024
@BrunoQuaresmaBrunoQuaresma deleted the bq/download-logs branchJune 7, 2024 13:03
@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsJun 7, 2024
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@code-ashercode-ashercode-asher approved these changes

@ParkreinerParkreinerParkreiner approved these changes

Assignees

@BrunoQuaresmaBrunoQuaresma

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Feat: Add a log download feature to workspace detail page
4 participants
@BrunoQuaresma@Parkreiner@code-asher@sreya

[8]ページ先頭

©2009-2025 Movatter.jp