-
Notifications
You must be signed in to change notification settings - Fork 20
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 #949 from golemfactory/mgordel/event-source-bugfix
fix(activity): fixed streaming batch via EventSource and runAndStrem example
- Loading branch information
Showing
4 changed files
with
71 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { MarketOrderSpec, GolemNetwork } from "@golem-sdk/golem-js"; | ||
import { pinoPrettyLogger } from "@golem-sdk/pino-logger"; | ||
|
||
/** | ||
* Example demonstrating the execution of a command on a provider which may take a long time | ||
* and returns the results from the execution during the command as a stream | ||
*/ | ||
|
||
const order: MarketOrderSpec = { | ||
demand: { | ||
workload: { imageTag: "golem/alpine:latest" }, | ||
}, | ||
market: { | ||
maxAgreements: 1, | ||
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 lease = await glm.oneOf(order); | ||
const exe = await lease.getExeUnit(); | ||
|
||
const remoteProcess = await exe.runAndStream( | ||
` | ||
sleep 1 | ||
echo -n 'Hello from stdout' >&1 | ||
echo -n 'Hello from stderr' >&2 | ||
sleep 1 | ||
echo -n 'Hello from stdout again' >&1 | ||
echo -n 'Hello from stderr again' >&2 | ||
sleep 1 | ||
echo -n 'Hello from stdout yet again' >&1 | ||
echo -n 'Hello from stderr yet again' >&2 | ||
`, | ||
); | ||
remoteProcess.stdout.on("data", (data) => console.log("stdout>", data)); | ||
remoteProcess.stderr.on("data", (data) => console.error("stderr>", data)); | ||
await remoteProcess.waitForExit(); | ||
|
||
await lease.finalize(); | ||
} 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