diff --git a/examples/docs-examples/quickstarts/retrievable-task/task.mjs b/examples/docs-examples/quickstarts/retrievable-task/task.mjs index 830ace4f5..4e574bdc6 100644 --- a/examples/docs-examples/quickstarts/retrievable-task/task.mjs +++ b/examples/docs-examples/quickstarts/retrievable-task/task.mjs @@ -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(); diff --git a/src/agreement/agreement.ts b/src/agreement/agreement.ts index fa016cea7..8060b582e 100644 --- a/src/agreement/agreement.ts +++ b/src/agreement/agreement.ts @@ -58,7 +58,7 @@ export class Agreement { * @hidden */ constructor( - public readonly id, + public readonly id: string, public readonly provider: ProviderInfo, private readonly yagnaApi: YagnaApi, private readonly options: AgreementConfig, diff --git a/src/job/job.ts b/src/job/job.ts index 94805fb31..cedac22d3 100644 --- a/src/job/job.ts +++ b/src/job/job.ts @@ -186,7 +186,7 @@ export class Job { paymentService.acceptPayments(agreement); - const activity = await Activity.create(agreement.id, this.yagnaApi, options.activity); + const activity = await Activity.create(agreement, this.yagnaApi, options.activity); const storageProvider = this.defaultOptions.work?.storageProvider || options.work?.storageProvider || this._getDefaultStorageProvider(); diff --git a/tests/e2e/express.spec.ts b/tests/e2e/express.spec.ts index 595fed105..6d6df940e 100644 --- a/tests/e2e/express.spec.ts +++ b/tests/e2e/express.spec.ts @@ -20,7 +20,6 @@ describe("Express", function () { const port = 3000; app.use(express.text()); - app.listen(port); app.post("/tts", async (req, res) => { if (!req.body) { @@ -101,13 +100,17 @@ describe("Express", function () { expect(statusResponse.status).toEqual(200); expect(statusResponse.text === JobState.New || statusResponse.text === JobState.Pending).toBeTruthy(); - await new Promise((resolve) => { + await new Promise((resolve, reject) => { const interval = setInterval(async () => { const statusResponse = await supertest(app).get(`/tts/${jobId}`).set("Content-Type", "text/plain"); if (statusResponse.text === JobState.Done) { clearInterval(interval); resolve(undefined); } + if (statusResponse.text === JobState.Rejected) { + clearInterval(interval); + reject(new Error("Job rejected")); + } }, 500); });