-
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.
- Loading branch information
1 parent
62d7760
commit ab95254
Showing
1 changed file
with
11 additions
and
11 deletions.
There are no files selected for viewing
22 changes: 11 additions & 11 deletions
22
examples/docs-examples/quickstarts/retrievable-task/task.mjs
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,23 +1,23 @@ | ||
import { GolemNetwork, JobState } from "@golem-sdk/golem-js"; | ||
import { GolemNetwork } from "@golem-sdk/golem-js"; | ||
|
||
const golem = new GolemNetwork({ | ||
yagnaOptions: { apiKey: "try_golem" }, | ||
yagna: { apiKey: "try_golem" }, | ||
}); | ||
await golem.init(); | ||
const job = await golem.createJob(async (ctx) => { | ||
|
||
const job = golem.createJob({ | ||
package: { | ||
imageTag: "golem/alpine:latest", | ||
}, | ||
}); | ||
job.startWork(async (ctx) => { | ||
const response = await ctx.run("echo 'Hello, Golem!'"); | ||
return response.stdout; | ||
}); | ||
|
||
let state = await job.fetchState(); | ||
while (state === JobState.Pending || state === JobState.New) { | ||
console.log("Job is still running..."); | ||
await new Promise((resolve) => setTimeout(resolve, 1000)); | ||
state = await job.fetchState(); | ||
} | ||
const result = await job.waitForResult(); | ||
|
||
console.log("Job finished with state:", state); | ||
const result = await job.fetchResults(); | ||
console.log("Job finished with state:", job.state); | ||
console.log("Job results:", result); | ||
|
||
await golem.close(); |