Skip to content

Commit

Permalink
Merge pull request #1034 from golemfactory/beta
Browse files Browse the repository at this point in the history
Release beta to master
  • Loading branch information
grisha87 authored Jul 18, 2024
2 parents 338ed1c + cb35fdb commit b603c34
Show file tree
Hide file tree
Showing 22 changed files with 369 additions and 189 deletions.
17 changes: 16 additions & 1 deletion .github/actions/prepare-tests/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,26 @@ runs:
shell: bash
run: |
echo "Going to build the SDK on the requestor"
docker exec -t docker-requestor-1 /bin/sh -c "cd /golem-js && npm i && npm run build"
docker exec -t docker-requestor-1 /bin/sh -c "cd /golem-js && npm i --no-progress && npm run build"
echo "Successfully built the SDK on the requestor"
- name: Install Cypress
if: ${{ inputs.type == 'cypress' }}
shell: bash
run: |
docker exec -t docker-requestor-1 /bin/sh -c "cd /golem-js && ./node_modules/.bin/cypress install"
- name: Run a preliminary scan of offers
shell: bash
run: |
docker exec -t docker-requestor-1 /bin/sh -c "npm install --no-progress -g @prekucki/wait-for-n && wait-for-n --limit=6 --appkey=try_golem --subnet=$YAGNA_SUBNET"
- name: List down sessions seen on that requestor
shell: bash
run: |
docker exec docker-requestor-1 /bin/sh -c "yagna net sessions"
- name: Run a secondary scan of offers
shell: bash
run: |
docker exec -t docker-requestor-1 /bin/sh -c "npx --no-progress --yes @golem-sdk/cli market scan -k try_golem --subnet-tag $YAGNA_SUBNET --payment-network $PAYMENT_NETWORK"
39 changes: 23 additions & 16 deletions examples/experimental/express/server.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import express from "express";
import { JobManager, JobState } from "@golem-sdk/golem-js/experimental";
import { fileURLToPath } from "url";

const app = express();
const port = 3000;

// get the absolute path to the public directory in case this file is run from a different directory
const publicDirectoryPath = fileURLToPath(new URL("./public", import.meta.url));

app.use(express.text());

const golemClient = new JobManager();
const jobManager = new JobManager();

await golemClient
await jobManager
.init()
.then(() => {
console.log("Connected to the Golem Network!");
Expand All @@ -23,19 +27,17 @@ app.post("/tts", async (req, res) => {
res.status(400).send("Missing text parameter");
return;
}
const job = golemClient.createJob({
const job = jobManager.createJob({
demand: {
activity: {
imageTag: "severyn/espeak:latest",
},
workload: { imageTag: "severyn/espeak:latest" },
},
market: {
rentHours: 0.5,
pricing: {
model: "linear",
maxStartPrice: 1,
maxCpuPerHourPrice: 1,
maxEnvPerHourPrice: 1,
maxStartPrice: 0.5,
maxCpuPerHourPrice: 1.0,
maxEnvPerHourPrice: 0.5,
},
},
});
Expand All @@ -58,15 +60,19 @@ app.post("/tts", async (req, res) => {
await exe
.beginBatch()
.run(`espeak "${req.body}" -w /golem/output/output.wav`)
.downloadFile("/golem/output/output.wav", `public/${fileName}`)
.downloadFile("/golem/output/output.wav", `${publicDirectoryPath}/${fileName}`)
.end();
return fileName;
});
res.send(`Job started! ID: ${job.id}`);
res.send(
`Job started! ID: ${job.id}\n` +
`You can check it's state by calling:\ncurl http://localhost:${port}/tts/${job.id}\n` +
`And it's results by calling:\ncurl http://localhost:${port}/tts/${job.id}/results\n`,
);
});

app.get("/tts/:id", async (req, res) => {
const job = golemClient.getJobById(req.params.id);
const job = jobManager.getJobById(req.params.id);
if (!job) {
res.status(404).send("Job not found");
return;
Expand All @@ -75,10 +81,10 @@ app.get("/tts/:id", async (req, res) => {
});

// serve files in the /public directory
app.use("/results", express.static("public"));
app.use("/results", express.static(publicDirectoryPath));

app.get("/tts/:id/results", async (req, res) => {
const job = golemClient.getJobById(req.params.id);
const job = jobManager.getJobById(req.params.id);
if (!job) {
res.status(404).send("Job not found");
return;
Expand All @@ -89,7 +95,7 @@ app.get("/tts/:id/results", async (req, res) => {

const results = await job.results;
res.send(
`Job completed successfully! Open the following link in your browser to listen to the result: http://localhost:${port}/results/${results}`,
`Job completed successfully! Open the following link in your browser to listen to the result: http://localhost:${port}/results/${results}\n`,
);
});

Expand All @@ -98,8 +104,9 @@ app.listen(port, () => {
});

process.on("SIGINT", async () => {
console.log("Gracefully shutting down...");
// cancel and cleanup all running jobs
await golemClient.close();
await jobManager.close();
process.exit(0);
});

Expand Down
2 changes: 1 addition & 1 deletion examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
},
"dependencies": {
"@golem-sdk/golem-js": "file:..",
"@golem-sdk/pino-logger": "^1.0.1",
"@golem-sdk/pino-logger": "^1.0.2",
"commander": "^12.0.0",
"express": "^4.18.2",
"tsx": "^4.7.1"
Expand Down
2 changes: 2 additions & 0 deletions examples/web/hello.html
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,13 @@ <h3>Results</h3>
await glm.connect();
appendResults("Request for renting a provider machine");
const rental = await glm.oneOf({ order });
appendResults("Rented resources from", rental.agreement.provider.name);
await rental
.getExeUnit()
.then(async (exe) =>
appendResults("Reply: " + (await exe.run(`echo 'Hello Golem! 👋 from ${exe.provider.name}!'`)).stdout),
);
appendResults("Finished all work with the resources");
await rental.stopAndFinalize();
appendResults("Finalized renting process");
} catch (err) {
Expand Down
51 changes: 27 additions & 24 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
"exports": {
".": {
"types": "./dist/index.d.ts",
"browser": "./dist/golem-js.min.js",
"import": "./dist/golem-js.mjs",
"require": "./dist/golem-js.js"
},
"./experimental": {
"types": "./dist/experimental.d.ts",
"types": "./dist/experimental/index.d.ts",
"browser": null,
"import": "./dist/golem-js-experimental.mjs",
"require": "./dist/golem-js-experimental.js"
}
Expand Down Expand Up @@ -61,6 +63,7 @@
"node": ">=18.0.0"
},
"dependencies": {
"@golem-sdk/pino-logger": "^1.1.0",
"async-lock": "^1.4.1",
"async-retry": "^1.3.3",
"axios": "^1.6.7",
Expand All @@ -82,7 +85,7 @@
"devDependencies": {
"@commitlint/cli": "^19.0.3",
"@commitlint/config-conventional": "^19.0.3",
"@johanblumenberg/ts-mockito": "^1.0.41",
"@johanblumenberg/ts-mockito": "^1.0.43",
"@rollup/plugin-alias": "^5.1.0",
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-json": "^6.1.0",
Expand Down
11 changes: 8 additions & 3 deletions src/activity/exe-script-executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class ExeScriptExecutor {
const batchId = await this.send(script);
const batchSize = JSON.parse(script.text).length;

this.logger.debug(`Script sent.`, { batchId });
this.logger.debug(`Script sent.`, { batchId, script });
return { batchId, batchSize };
} catch (error) {
const message = getMessageFromApiError(error);
Expand Down Expand Up @@ -175,7 +175,8 @@ export class ExeScriptExecutor {
}
} catch (error) {
logger.debug(`Failed to fetch activity results. Attempt: ${attempt}. ${error}`);
if (RETRYABLE_ERROR_STATUS_CODES.includes(error?.status)) {
const errorStatus = error?.status ?? error.previous?.status;
if (RETRYABLE_ERROR_STATUS_CODES.includes(errorStatus)) {
throw error;
} else {
bail(error);
Expand Down Expand Up @@ -235,7 +236,7 @@ export class ExeScriptExecutor {
private parseEventToResult(event: StreamingBatchEvent, batchSize: number): Result {
// StreamingBatchEvent has a slightly more extensive structure,
// including a return code that could be added to the Result entity... (?)
return new Result({
const result = new Result({
index: event.index,
eventDate: event.timestamp,
result: event?.kind?.finished
Expand All @@ -250,5 +251,9 @@ export class ExeScriptExecutor {
message: event?.kind?.finished?.message,
isBatchFinished: event.index + 1 >= batchSize && Boolean(event?.kind?.finished),
});

this.logger.debug("Received stream batch execution result", { result });

return result;
}
}
2 changes: 1 addition & 1 deletion src/activity/exe-unit/batch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export class Batch {
this.executor.activity.agreement.provider,
error,
);
this.logger.debug("Error in batch script execution");
this.logger.debug("Error in batch script execution", { error });
this.script
.after(allResults)
.then(() => reject(golemError))
Expand Down
7 changes: 7 additions & 0 deletions src/activity/exe-unit/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,11 @@ export class RemoteProcess {
this.subscription.add(() => end());
});
}

/**
* Checks if the exe-script batch from Yagna has completed, reflecting all work and streaming to be completed
*/
isFinished() {
return this.lastResult?.isBatchFinished ?? false;
}
}
Loading

0 comments on commit b603c34

Please sign in to comment.