Skip to content

Use dedicated class and types for server communication#64

Merged
ageorgou merged 6 commits intomasterfrom
ag/refactor-server
Sep 22, 2021
Merged

Use dedicated class and types for server communication#64
ageorgou merged 6 commits intomasterfrom
ag/refactor-server

Conversation

@ageorgou
Copy link
Copy Markdown
Contributor

@ageorgou ageorgou commented Aug 18, 2021

Not fully convinced this is worth it but interested in feedback, especially about readability and whether the structure makes sense.

The general plan was:

  • Move server communication to the SOAP_client class.
  • Use some Typescript features to formalise the parameters.
  • (Maybe?) Move mime.ts to client/ from server/
  • (Maybe?) Use the HTTP_request class for some of the functionality that's currently in mime.ts (or some of SOAP_client too) Deleted HTTP_request
  • (Maybe?) Update the tests to use the new structure directly (the overall validation functionality is still tested)

My thinking is that:

  • Hopefully the new class structure makes the different steps clearer, as well as simplifying the error handling and reporting.
  • Having a new type for request parameters lets us eliminate the repetition when creating and handling different types of messages.
  • Typescript will also catch some errors through type inference, such as if we try to access a field from the wrong kind of request, or if we try to pass an non-existent command (e.g. "val" instead of "atf").

I'm not sure about HTTP_request, because the two types of requests we create do different things, so a shared base may be tricky. I don't know if putting that in a class (rather than functions) is going to be a better structure.

Comment thread src/server/mime.ts
<osc-data:key>${params.command}</osc-data:key>
<osc-data:key>${params.project}</osc-data:key>
<osc-data:key>00atf/${params.filename}</osc-data:key>
</osc-data:keys>`;
Copy link
Copy Markdown
Contributor

@raquelalegre raquelalegre Aug 23, 2021

Choose a reason for hiding this comment

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

One thing I had planned to do but I think I never did was to use templates for the xml used in the server communication. I imagine there's something like jinja2 for Typescript.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So you could have an XML template file for each time of message, or chunk of message, and then fill it in with the given parameters.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good idea, I'll make another issue for that! Especially because the indentation is confusing here.

Comment thread src/client/SOAP_client.ts Outdated
log('error', `Error during communication with server: ${err}`);
vscode.window.showErrorMessage(
"Problem getting response from server, see log for details.");
return; // Should return an empty result?
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No need for an empty result to be returned I think. You're catching the errors and the ServerResults are returned via a Promise (which I don't quite understand yet!). What would you use an empty result for?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The Promise represents a result that's not finished computing yet. At some point we'll need to either return a result, or say that there's an error. Maybe the right thing is to throw an error here, and let the caller show the message etc. I have trouble explaining it because I don't fully understand promises either.

Comment thread src/client/SOAP_client.ts Outdated
Please contact the Oracc server admin to look into this problem.`;
case 'run':
if (attempts < max_attempts) {
log('info', 'Server working on request.');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does this mean that the user will see "Server working on request" as many times as attempts there are? I don't know how many of those it normally takes until the server finished processing the request, but I'd log the attempt number in the debug log maybe, and just the "Server working on request" for the users to see just once. Or even not at all.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I was going by what Nammu does (it prints every time on the console), but you're right that it doesn't show it on the main window. This will only show up to ten times (we'll time out after that).

I wanted to have something that shows that it's not stuck, but your suggestion sounds better, thanks!

Copy link
Copy Markdown
Contributor

@raquelalegre raquelalegre left a comment

Choose a reason for hiding this comment

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

I think this improves the previous design quite a bit! It's easy to read and understand, although maybe it's easier for me as I know how it works! The only thing I'd consider which might make things easier to understand is to use templates for the XML text rather than chunks of formatted text inbetween lines of code. This is something I wanted to have done in Nammu but never found the time to do. Just a suggestion! It reads fine as it is.

@ageorgou ageorgou marked this pull request as ready for review September 16, 2021 13:08
ageorgou and others added 6 commits September 16, 2021 14:20
I think mime.ts makes more sense under client, where it's being
called from. So now server only has the user-facing stuff about
communicating to the server, not the behind-the-scense SOAP client.
@ageorgou ageorgou merged commit d98b085 into master Sep 22, 2021
@ageorgou ageorgou deleted the ag/refactor-server branch September 22, 2021 12:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants