Skip to content

Commit

Permalink
chore: fix session issues
Browse files Browse the repository at this point in the history
Signed-off-by: Scott Dover <[email protected]>
  • Loading branch information
Scott Dover authored and Scott Dover committed Oct 18, 2024
1 parent f863576 commit bc7bcf1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 14 deletions.
18 changes: 13 additions & 5 deletions client/src/components/ContentNavigator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,10 @@ class ContentNavigator implements SubscriptionProvider {
);
},
),
commands.registerCommand(`${SAS}.collapseAllContent`, () => {
commands.executeCommand(
`workbench.actions.treeView.${this.treeIdentifier}.collapseAll`,
);
}),
commands.registerCommand(
`${SAS}.collapseAllContent`,
this.collapseAllContent,
),
commands.registerCommand(
`${SAS}.convertNotebookToFlow`,
async (resource: ContentItem | Uri) => {
Expand Down Expand Up @@ -386,15 +385,24 @@ class ContentNavigator implements SubscriptionProvider {
async (event: ConfigurationChangeEvent) => {
if (event.affectsConfiguration("SAS.connectionProfiles")) {
const endpoint = this.viyaEndpoint();
this.collapseAllContent();
if (endpoint) {
await this.contentDataProvider.connect(endpoint);
} else {
await this.contentDataProvider.refresh();
}
}
},
),
];
}

private collapseAllContent() {
commands.executeCommand(
`workbench.actions.treeView.${this.treeIdentifier}.collapseAll`,
);
}

private async uploadResource(
resource: ContentItem,
openDialogOptions: Partial<OpenDialogOptions> = {},
Expand Down
27 changes: 18 additions & 9 deletions client/src/connection/rest/RestSASServerAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,22 @@ class RestSASServerAdapter implements ContentAdapter {
recycleItem?: (item: ContentItem) => Promise<{ newUri?: Uri; oldUri?: Uri }>;
restoreItem?: (item: ContentItem) => Promise<boolean>;

public async connect(): Promise<void> {
private async establishConnection() {
const session = getSession();
session.onSessionLogFn = appendSessionLogFn;

await session.setup(true);

this.sessionId = session?.sessionId();

return this.sessionId;
}

public async connect(): Promise<void> {
await this.establishConnection();
// This proxies all calls to the fileSystem api to reconnect
// if we ever get a 401 (unauthorized)
const reconnect = async () => await this.connect();
const reconnect = async () => {
return await this.establishConnection();
};
this.fileSystemApi = new Proxy(FileSystemApi(getApiConfig()), {
get: function (target, property) {
if (typeof target[property] === "function") {
Expand All @@ -76,11 +82,14 @@ class RestSASServerAdapter implements ContentAdapter {
try {
return await target(...argList);
} catch (error) {
if (error.response?.status !== 401) {
throw error;
}
// If we get any error, lets reconnect and try again. If we fail a second time,
// then we can assume it's a "real" error
const sessionId = await reconnect();

await reconnect();
// If we reconnected, lets make sure we update our session id
if (argList.length && argList[0].sessionId) {
argList[0].sessionId = sessionId;
}

return await target(...argList);
}
Expand Down Expand Up @@ -461,7 +470,7 @@ class RestSASServerAdapter implements ContentAdapter {

private trimComputePrefix(uri: string): string {
return decodeURI(
uri.replace(`/compute/sessions/${this.sessionId}/files/`, ""),
uri.replace(/\/compute\/sessions\/[a-zA-Z0-9-]*\/files\//, ""),
);
}

Expand Down

0 comments on commit bc7bcf1

Please sign in to comment.