-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4259 from systeminit/nick/eng-2618
Add configurable timeout to function execution in `lang-js`
- Loading branch information
Showing
28 changed files
with
250 additions
and
208 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,59 @@ | ||
# Lang JS | ||
# `lang-js` | ||
|
||
This directory contains `lang-js`. | ||
This directory contains `lang-js`, the primary executor for functions in SI. | ||
|
||
## Testing Locally | ||
## Local Testing Guide | ||
|
||
Here is an example of testing `lang-js` locally: | ||
This is a guide for testing `lang-js` locally by using functions in the [examples](exmaples) directory. | ||
|
||
```bash | ||
SI_LANG_JS_LOG=* buck2 run :lang-js -- ${CHECK_NAME} < examples/${FILE_NAME} | ||
``` | ||
> [!NOTE] | ||
> While [dal integration tests](../../lib/dal/tests/integration.rs) are useful for testing new functions and workflows that leverage `lang-js`, it can be helpful to run `lang-js` directly for an efficient developer feedback loop. | ||
## Encoding the Code | ||
### 1) Writing the Function | ||
|
||
Here is an example of "encoding the code" locally: | ||
Before writing a payload file, we will want to write a function to be executed. | ||
We can do this anywhere, but for this guide, we will write the file to the [examples](examples) directory. | ||
|
||
```bash | ||
cat examples/commandRunFailCode.js | base64 | tr -d '\n' | ||
``` | ||
> [!TIP] | ||
> You can write the function in JavaScript (`.js`) or TypeScript (`.ts`). | ||
> You can also write an `async` function or a regular, synchronous one. | ||
## Example Test Workflow | ||
|
||
While [dal integration tests](../../lib/dal/tests/integration.rs) are useful for testing new functions and workflows | ||
that leverage `lang-js`, it can be helpful to run `lang-js` directly for an efficient | ||
developer feedback loop. | ||
|
||
First, let's author a function and save it to the [examples](./examples) directory. | ||
Here is an example function: | ||
|
||
```js | ||
function fail() { | ||
throw new Error("wheeeeeeeeeeeeeeee"); | ||
} | ||
``` | ||
|
||
Now, let's base64 encode this function and save the result to our clipboard. | ||
### 2) Encoding the Function | ||
|
||
With our new function written, we need to "base64 encode" it for the payload file. | ||
You can do that by executing the following: | ||
|
||
```bash | ||
cat examples/commandRunFailCode.js | base64 | tr -d '\n' | ||
cat examples/<code-file>.<js-or-ts> | base64 | tr -d '\n' | ||
``` | ||
|
||
Then, we can create a `json` file in the same directory that's in a format that `lang-js` expects. | ||
You'll want to copy the result to your clipboard. | ||
On macOS, you can execute the following to do it in one step: | ||
|
||
```json | ||
{ | ||
"executionId": "fail", | ||
"handler": "fail", | ||
"codeBase64": "ZnVuY3Rpb24gZmFpbCgpIHsKICAgIHRocm93IG5ldyBFcnJvcigid2hlZWVlZWVlZWVlZWVlZWVlIik7Cn0K" | ||
} | ||
```bash | ||
cat examples/<code-file>.<js-or-ts> | base64 | tr -d '\n' | pbcopy | ||
``` | ||
|
||
Finally, we can run our function in `lang-js` directly. | ||
### 3) Preparing the Payload File | ||
|
||
|
||
With the encoded function in our clipboard, we can create a payload file to send to `lang-js`. | ||
The payload file will be a `json` file in the same directory. | ||
|
||
At the time of writing the guide ([PR #4259](https://github.com/systeminit/si/pull/4259)), the shape the the `json` file has drifted from what it used to be, so developers will need to read the source code to learn its shape. | ||
|
||
### 4) Running the Function via the Payload File | ||
|
||
When we run our function in `lang-js`, let's set the debug flag to see what's going on! | ||
|
||
```bash | ||
cat examples/commandRunFail.json | SI_LANG_JS_LOG=* buck2 run :lang-js -- commandRun | ||
cat examples/<payload-file>.json | SI_LANG_JS_LOG=* buck2 run :lang-js -- <function-kind> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# TODO | ||
|
||
At the time of this file's creation, the existing examples did not work. | ||
The [README](../README.md) has been updated to be generic for any example in its guide. | ||
|
||
We should create new examples for testing `lang-js` locally without the entire stack. | ||
For now, use `dal` integration tests for `lang-js` testing or add new examples to this directory and delete this `TODO.md` file. | ||
|
||
See [PR #4259](https://github.com/systeminit/si/pull/4259) for more information. |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.