Skip to content

Commit

Permalink
Merge pull request #706 from golemfactory/bugfix/JST-621/fix-yagna-de…
Browse files Browse the repository at this point in the history
…code-errors

JST-621: fix yagna decode errors
  • Loading branch information
SewerynKras authored Dec 5, 2023
2 parents 8fda1c2 + 4cdf329 commit 36ec7f5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 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();
2 changes: 1 addition & 1 deletion src/agreement/agreement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/job/job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export class Job<Output = unknown> {

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();
Expand Down
7 changes: 5 additions & 2 deletions tests/e2e/express.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
});

Expand Down

0 comments on commit 36ec7f5

Please sign in to comment.