fastn tutor
#1414
Replies: 7 comments 6 replies
-
Status updateI have merged two PRs so far (#1415, #1420) and a third PR is ongoing (#1434). Tutor PageWe have created a new command This is how it looks like right now: The iframe on left is not meant to be there. The data for tutorial is in the We also have a file #[derive(Debug, Default, serde::Serialize, serde::Deserialize)]
struct TutorState {
done: Vec<String>,
current: String,
} If the file is not present use Tutorial PageThere is a concept of a current tutorial. When a tutorial is made current on Tutor Page, we start a new fastn server, in the folder corresponding to the selected tutorial, and show this page. We inject a |
Beta Was this translation helpful? Give feedback.
-
The Two
|
Beta Was this translation helpful? Give feedback.
-
How does fastn controller know if slave is running?Since slave can be either running or not running, how does the controller know? How does controller start the slave? And how does it proxy requests? Do we really need two servers? It's a bit heavy handed approach. Can we not simply re-use the same server and call the serve or handle method? Currently we have a global config, so if we have to servers running, we will need two config objects. Also the code is written with the assumption that all files are in current directory, and our two servers are supposed to serve from two different folders. What if we add the working directory in config and make multiple instances of config? Currently each route handler is responsible for creating config. This is not great in general, we are creating config all the time, which is rather expensive. Re-using means config could be stale. The right way would be to watch folder for changes, and update config only on file change. Or do it prod/debug mode, in prod mode we do not expect the file system content to change, and we can re-use the config object. Actually there is another reason to re-create config, as we keep some mutable fields on the config object, which contains data specific to current request. This has to be re-created. Right thing would be refactor config into more than one such, the dependency stuff, which is "heavy" can be re-used, and per-request stuff, which is cheaper, can be created on each request. What to do? |
Beta Was this translation helpful? Give feedback.
-
Config RefactorSo I am finally biting the bullet and refactoring config into two structs: #[derive(Debug, Clone)]
pub struct RequestConfig<'a> {
pub named_parameters: Vec<(String, ftd::Value)>,
pub extra_data: std::collections::BTreeMap<String, String>,
pub current_document: Option<String>,
pub dependencies_during_render: Vec<String>,
pub request: &'a fastn_core::http::Request,
pub config: &'a Config,
} Every method that used to get cc: @Arpita-Jaiswal |
Beta Was this translation helpful? Give feedback.
-
So now that config refactor is almost done, still in PR, but we can continue back on tutor stuff. When we are serving, we need the the package current folder, earlier it used to be always pwd, but now we can make it anything. Also since tutor is there to teach you all features of fastn, and some of those features include CLI arguments, like This is actually quite easy because we create a new config object on each request, and all the Modes
Normal ModeIn this the default, the external-js stuff comes from CLI, and folder is current folder (we can make this configurable by CLI / env var also). Tutor ModeThis is when we run We are in tutorial mode when Tutorial ModeThis is the when the learner has selected a tutorial. We store the current tutorial folder in a variable We have API like start tutorial and end tutorial, which basically mutate this variable. We are in tutorial mode when Tutorial Mode CLI flagsIn tutorial mode we need possibly different set of CLI flags for each tutorial. To get this flag we are going to store them in struct Tutorial {
path: String,
app_data: fastn_core::commands::serve::AppData,
}
|
Beta Was this translation helpful? Give feedback.
-
Wrote some thoughts on configuration: https://github.com/orgs/fastn-stack/discussions/1451 |
Beta Was this translation helpful? Give feedback.
-
So let's recap where I am: I have API's to set current tutorial (untested), our server can now serve the content of the current tutorial (untested), and a processor to show tutorial data, including current tutorial (also untested). I have not called those APIs yet or tested any of these features. And for that matter tests are not passing right now in the PR and fonts are not working. So what do I do next? Start TutorialWe have to show the processor data in tutor.ftd file, and then call the start tutorial API. Once done all subsequent requests should be served by that tutorial. |
Beta Was this translation helpful? Give feedback.
-
Status: WIP, Owner: @amitu
fastn_core::utils::is_tutor()
function)keywords: fastling, rustling
fastn tutor
to help learn fastn.fastn tutor
This will expect current folder to be checkout of the workshop. It will launch a UI, which will show status of what all steps are marked as done.
Tutor UI
It will get the list of steps by scanning the workshop, and finding the first two levels (first level is workshop name, eg a-workshop, and second is a step in the workshop, eg
a-workshop/01-hello-world
.The tutor ui will also have button to mark a step as done, which automatically moves to next step. Next to any other step there is a run button as well, which makes that step the current step.
Based on current step the tutor ui also shows some instructions on how to finish the step. This is read from the workshop folder itself.
Current Folder
Till fastn can download the workshop, it will be assumed the current folder is workshop folder, and workshop folder contains the fastn tutor related package as well.
State
fastn tutor will store the state in
~/.fastn/tutor.json
file.When the file is created,
done
will be empty andcurrent
would be the first step.Both will contain names like
a-website/01-hello-world
.Tutor Mode
fastn tutor will run fastn server in the folder corresponding to current. When fastn starts like that it will run with
fastn serve --tutor
as the CLI argument.Fixed Port
In the tutor mode, the port cli argument will be ignored, and it will always run on port
10345
./-/shutdown/
In tutor mode request to this URL will stop the server. This will be used by tutor to stop the server and start a new server when learner moves from one step to next.
/-/pwd/
This URL will return the pwd, which will be used by tutor to check to ensure the right server is running. If not, it will shut it down and start another fastn on right port.
tutor.js
When running in tutor mode
fastn serve
will auto inject atutor.js
(this can be done using--js
cli argument.tutor.js
will mapt
shortcut, which will open a popup, which will show tutor UI in an iframe.Downloads Github Workshop - LATER
fastn tutor
will checkout workshop if it is not yet there.Beta Was this translation helpful? Give feedback.
All reactions