Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement more Effects #8

Merged
merged 25 commits into from
Nov 19, 2023
Merged

Implement more Effects #8

merged 25 commits into from
Nov 19, 2023

Conversation

lukewilliamboswell
Copy link
Collaborator

@lukewilliamboswell lukewilliamboswell commented Nov 19, 2023

This PR

  • Implements the remaining effects
  • Adds a number of examples and improves the existing examples
  • Improves glue generation with a platform/glue-gen.sh script to capture the key steps
  • Fixes documentation generation

@brian-carroll
Copy link

glue_manual has thousands and thousands of lines. The name makes it sounds like you wrote it manually but I guess not? Do you mean that it is still generated but just generated differently?

Choose a reason for hiding this comment

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

OK I think I finally see what's happening, the name was misleading me.
Maybe it would be good to rename this to "extra" glue rather than "manual" glue.

Choose a reason for hiding this comment

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

Actually even better would be to make it more descriptive. All the listed types seem to be "internal" to the platform. So maybe we could have "app" glue and "platform" glue?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I like extra glue, I'll update it.

Copy link

@brian-carroll brian-carroll left a comment

Choose a reason for hiding this comment

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

This is fantastic to see! Great work!
A few suggestions below but no problems.

FYI, it's possible to tell GitHub which files are generated so that they are collapsed in PRs.
https://docs.github.com/en/repositories/working-with-files/managing-files/customizing-how-changed-files-appear-on-github

platform/main.roc Show resolved Hide resolved

Choose a reason for hiding this comment

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

If you need a separate file for glue anyway (because of the Task problem) then you could just combine all the app and host types into a single glue.roc.
But I suppose there's not much real benefit. And you might want to keep them separate for when the bug is fixed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, keeping seperate so when we fix the bugs we can just delete glue_manual crate and the glue mains.

platform/Env.roc Show resolved Hide resolved
Effect.commandOutput (Box.box cmd)
|> Effect.map Ok
|> Effect.map (\out -> Ok out)

Choose a reason for hiding this comment

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

Oh wow, why was this needed? Compiler bug?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, this is a compiler bug. I am pretty sure this is known as it came up somewhere else earlier. @ayazhafiz or @bhansconnect do you know if this is new? should I make an issue for it?

## when output.status is
## Ok {} -> jsonResponse output.stdout
## Err _ -> byteResponse 500 output.stderr
## ```

Choose a reason for hiding this comment

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

Always nice to see doc comments being added!


readUrlEnv : Task Str AppError
readUrlEnv =
maybeDbPath <- Env.var "TARGET_URL" |> Task.attempt

Choose a reason for hiding this comment

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

This variable name is not an obvious choice. Does it have something to do with databases? Or is it copy-pasted from elsewhere?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not really, I was just looking for an excuse to read an Env.var so I could test that effect. I'll polish it some more in a follow up.

# Log the date, time, method, and url to stdout
{} <- logRequest req |> Task.await

# Read TARGET_URL environment variable

Choose a reason for hiding this comment

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

The fact that you had to make this comment suggests that the function call itself could be made a bit more self-explanatory.
Maybe it would be better to pass the env var name as a string so that you don't need the comment. Or rename the function.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thank you, great idea I'll add in a follow up PR

Ok str -> respond 200 str
Err _ -> respond 500 "Error 500 Internal Server Error\n"
Ok content -> Task.ok content
Err err -> Task.err (HttpError err)

Choose a reason for hiding this comment

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

I see a lot of these wrapper functions to transform things from Result to Task.
It might be worth considering absorbing those into the platform itself.
Not for this PR though, it's doing enough! Just an idea for later.

Choose a reason for hiding this comment

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

In fact they are transforming from Task to Result and back to Task.
I don't understand why that's needed.
Is it to change the error type? Would Task.mapError achieve the same thing?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't have a particular reason other than I was in a hurry and this was the first thing that came to mind when refactoring out the errors to have a common type and a single handler.

I would like to look at this closer in a following PR.

@lukewilliamboswell lukewilliamboswell merged commit a9b32ff into main Nov 19, 2023
1 check passed
@lukewilliamboswell lukewilliamboswell deleted the more-features branch November 19, 2023 19:32
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