Skip to content

Commit

Permalink
chore(job): update docs example
Browse files Browse the repository at this point in the history
  • Loading branch information
SewerynKras committed Dec 4, 2023
1 parent 62d7760 commit ab95254
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions examples/docs-examples/quickstarts/retrievable-task/task.mjs
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();

0 comments on commit ab95254

Please sign in to comment.