-
Notifications
You must be signed in to change notification settings - Fork 12
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
Runtime and Compiler v2 #11
Conversation
Not really happy about this but at the moment it's needed for unit tests. vm.SourceTextModule doesn't seem to be available from inside the ava worker
We can use this in unit tests. Instead of calling out to the actual runtime (which throws errors reading vm.SourceTextModule, something complicated with the --experimental-vm-modules flag not getting passed to the ava thread), we create a worker which calls our simple mock function. All the worker lifecycle stuff is abstracted into a helper function which is used equally by the actual and mock workers - which gives us a really realistic mokc simulation.
…te typings (but badly)
This comment was marked as resolved.
This comment was marked as resolved.
@josephjclark I just went through this PR, this is really great - it's feeling like a very solid foundation. The CLI appears to expect a folder? Or a file called
I think in this case, then Perhaps we make the option mutually exclusive for now, you pick just one.
I'm wasn't immediately concerned about this, like I couldn't think of what might be passed in. I think what is super important is code accessing We will need to test how the sandboxing can deal with this. I think that's the only handle we really have, I don't know how we could 'knee-cap' the worker without making life very hard for everyone - we should focus on the sandboxing and test that. As an aside, it wouldn't be unreasonable to pass the process a 'cookie' (Erlang terminology) or key/secret used to trust other nodes in the cluster. Basically I do think there could/would be a requirement to have workers carry some kind of temporary and constant trust mechanism for communicating with the backend cluster. You'll have to walk me through that module resolution issue you outlined above, I'd like to understand it better. |
I know it's failing, I'm not sure why it's not skipped here...
I thoughht I'd fixed this one too...
Tidy project
So I've been through and updated everything that I think needs doing. The examples now work, the readme is updated. We do need to update Lightning to use the new @stuartc I think you need to give this a quick once-over - check the top level readme and package json, plus check my previous comment re describe-package tests. It's probably fine and we could merge and fix later. Subject to that, I think we can merge... |
The next generation runtime engine.
To make it so:
Merge Checklist
What do we need to do before merging this to main?
compiler
)Port describe-package tests over to ava ?NahLikely blockers with real-world jobs
Runtime
Create a new runtime which accepts a job as a pipeline of functions (as a string representation of an esm module which exports an array of functions), and runs them through the execute reducer.
The job is loaded into a sandbox environment using experimental node:vm module loaders. This is more to load the source properly and control the execution environment, it's not a security thing. Seems to work great.
The runtime manager may want to run the whole runtime in a vm2 context for added security.
console
to be overridden inside the jobrun should return a promise which is also an event emitterEmit events as operations start and return (current status: running operation 4: fetch from salesforce)Compiler
The new compiler will be quite different from the old because it won't need to do stuff like inject the execute reducer or ensure there's an environment for language adaptors. The runtime handles all that stuff now.
I am still using recast, acorn and ast-types to do the heavy lifting (although tbh I'm not sure why we're favouring acorn over esprima!)
export default []
Create a validator to catch naughties in code (like errant import/export statements)Provide a validation API with error reporting (closely related to the validator I hope!)Compile from typescript (!)Add wrappers for global state - State globals in the new runtime #17Devtools / CLI
Probably installed as a global to work on adaptors, or run straight out of kit when working on the runtime and compiler
Runtime Manager
The runtime manager /service provides an API to run jobs in worker threads.
There's an API to support and report on thread management, and there's a little web server which stays alive and receives post requests to run jobs. The server#'s just a demo client of the manager API really (but it'll be a fun toy to build out!).
(remaining steps moved to New runtime manager service #52)
Ava Notes
I've disabled type checking in ava's unit tests because:
Type errors will still get caught by the build process in CI. We could consider adding a
test:tsc
script as well if we want seperate CLI/local test runner for typings. At the moment I have no appetite for this.Also worth nothing that ava works nicely in monorepos - just drop a config in the top level and ava will find it from down in the packages. Now it's easy for all packages to share a standard test definition. Neat!
Naming Jobs
When running a job, we ideally want to give it a useful name. Probably found in the preceeding comments. But how will the runtime know the name?
I think we need like an Operation function, which explicitly declares an operation with a name and a handler.
Alternatively we could ad arguments to every adaptor function to do this stuff.
Breaking changes
the state global
I want to remove the state global. The currnet
core.execute
function loads state into the 'global' context. This doesn't work very well with my new vision of "immutable" state, where we clone the state object and pass it into each operation.I would like to:
(state) => x
wrapper. Maybe only if a flag is provided, maybe only if we detect a global state reference inside that operation.This means old code can be made to work if it's compiled properly, while new code can be encouraged to adopt better practice.
General TODOs