-
Notifications
You must be signed in to change notification settings - Fork 20
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
Rename WorkContext to ExeUnit #982
Merged
Merged
Changes from 10 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
70c8ed0
refactor(work-context): rename WorkContext to ExeUnit
mgordel 12a488f
docs: fixed typedoc link
mgordel 31c4dcc
refactor: changed ctx to exe unit in logs
mgordel 1fd6eac
feat: added setup and teardown functions as options to exe-unit
mgordel 5fa2fb8
chore: sync beta
mgordel 5c120ba
docs: added example of the setup and terdown functions
mgordel 2c73ba0
test: fixed oneOf params in unit test
mgordel 387aee4
docs: fixed oneOf params in example
mgordel 1cd8f00
refactor(exe-unit): renamed `before` method to `setup` and added `tea…
mgordel 9dda67d
docs: added typedoc comments for oneOf and manyOf
mgordel dee024e
docs: added example (rendering) of using the setup and teardown funct…
mgordel 8b27838
test: fixed after removing fixtures
mgordel 55fcaa5
chore: sync beta
mgordel 80f0736
docs: removed rendering example
mgordel f65e0e0
docs: example for setup and teardown
SewerynKras 413cde3
docs: document setup and teardown in README
SewerynKras d04e8f4
Merge pull request #986 from golemfactory/decryption-example
mgordel a9336a7
docs: use golem image in setup and teardown example
SewerynKras 0ba718a
refactor: changed remaining `lease` names to `rental`
mgordel 042c76b
Merge remote-tracking branch 'origin/mgordel/JST-984/exe-unit-rename'…
mgordel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { MarketOrderSpec, GolemNetwork, LifecycleFunction } from "@golem-sdk/golem-js"; | ||
import { pinoPrettyLogger } from "@golem-sdk/pino-logger"; | ||
|
||
const order: MarketOrderSpec = { | ||
demand: { | ||
workload: { imageTag: "golem/alpine:latest" }, | ||
}, | ||
market: { | ||
rentHours: 0.5, | ||
pricing: { | ||
model: "linear", | ||
maxStartPrice: 0.5, | ||
maxCpuPerHourPrice: 1.0, | ||
maxEnvPerHourPrice: 0.5, | ||
}, | ||
}, | ||
}; | ||
|
||
(async () => { | ||
const glm = new GolemNetwork({ | ||
logger: pinoPrettyLogger({ | ||
level: "info", | ||
}), | ||
}); | ||
|
||
try { | ||
await glm.connect(); | ||
|
||
const setup: LifecycleFunction = async (exe) => | ||
exe | ||
.run(`echo This code is run on the start of the exe-unit ${exe.provider.name}`) | ||
.then((res) => console.log(res.stdout)); | ||
|
||
const teardown: LifecycleFunction = async (exe) => | ||
exe | ||
.run(`echo This code is run before the exe-unit ${exe.provider.name} is destroyed`) | ||
.then((res) => console.log(res.stdout)); | ||
|
||
const pool = await glm.manyOf({ | ||
concurrency: 2, | ||
order, | ||
setup, | ||
teardown, | ||
}); | ||
await Promise.allSettled([ | ||
pool.withLease(async (lease) => | ||
lease | ||
.getExeUnit() | ||
.then((exe) => exe.run(`echo Hello, Golem from the first machine! 👋 ${exe.provider.name}`)) | ||
.then((res) => console.log(res.stdout)), | ||
), | ||
pool.withLease(async (lease) => | ||
lease | ||
.getExeUnit() | ||
.then((exe) => exe.run(`echo Hello, Golem from the second machine! 👋 ${exe.provider.name}`)) | ||
.then((res) => console.log(res.stdout)), | ||
), | ||
]); | ||
} catch (err) { | ||
console.error("Failed to run the example", err); | ||
} finally { | ||
await glm.disconnect(); | ||
} | ||
})().catch(console.error); |
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
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
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
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
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
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
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
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a better example would be to show that if you re-use a lease the setup and teardown are only executed once (for example make w pool with concurrency 2 and run 10 tasks on it)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or we could borrow the example from TE where we upload a file, add lines to it in every task function and then display the contents at the end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or maybe... an example with rendering... 🫣 intentionally change the name to
rendering.ts
, this is the original example where it is necessary to use thesetup
.. (?)I added it for comparison - rendering.ts