Skip to content

Commit

Permalink
Rename, refactor the codebase (#89)
Browse files Browse the repository at this point in the history
* Rename, refactor the codebase

* Fix _ModelType, refactor repo func to named params

* typo
  • Loading branch information
mdtanrikulu committed Dec 16, 2020
1 parent d0c2149 commit 80f3940
Show file tree
Hide file tree
Showing 24 changed files with 415 additions and 388 deletions.
43 changes: 21 additions & 22 deletions examples/blender/blender.js
@@ -1,19 +1,19 @@
const path = require("path");
const dayjs = require("dayjs");
const duration = require("dayjs/plugin/duration");
const { Engine, Task, utils, vm } = require("yajsapi");
const { Executor, Task, utils, vm } = require("yajsapi");
const { program } = require("commander");

dayjs.extend(duration);

const { asyncWith, logUtils, range } = utils;

async function main(subnetTag) {
const _package = await vm.repo(
"9a3b5d67b0b27746283cb5f287c13eab1beaa12d92a9f536b747c7ae",
0.5,
2.0
);
const _package = await vm.repo({
image_hash: "9a3b5d67b0b27746283cb5f287c13eab1beaa12d92a9f536b747c7ae",
min_mem_gib: 0.5,
min_storage_gib: 2.0,
});

async function* worker(ctx, tasks) {
ctx.send_file(
Expand Down Expand Up @@ -42,7 +42,7 @@ async function main(subnetTag) {
OUTPUT_DIR: "/golem/output",
});
ctx.run("/golem/entrypoints/run-blender.sh");
const output_file = `output_${frame.toString()}.png`
const output_file = `output_${frame.toString()}.png`;
ctx.download_file(
`/golem/output/out${frame.toString().padStart(4, "0")}.png`,
path.join(__dirname, `./output_${frame}.png`)
Expand All @@ -51,7 +51,7 @@ async function main(subnetTag) {
// TODO: Check
// job results are valid // and reject by:
// task.reject_task(msg = 'invalid file')
task.accept_task(output_file);
task.accept_result(output_file);
}

ctx.log("no more frames to render");
Expand All @@ -62,30 +62,29 @@ async function main(subnetTag) {
const timeout = dayjs.duration({ minutes: 15 }).asMilliseconds();

await asyncWith(
await new Engine(
_package,
6,
timeout, //5 min to 30 min
"10.0",
undefined,
subnetTag,
logUtils.logSummary()
),
async (engine) => {
for await (let task of engine.map(
new Executor({
task_package: _package,
max_workers: 6,
timeout: timeout,
budget: "10.0",
subnet_tag: subnetTag,
event_consumer: logUtils.logSummary(),
}),
async (executor) => {
for await (let task of executor.result(
worker,
frames.map((frame) => new Task(frame))
)) {
console.log("result=", task.output());
console.log("result=", task.result());
}
}
);
return;
}

program
.option('--subnet-tag <subnet>', 'set subnet name', 'community.3')
.option('-d, --debug', 'output extra debugging');
.option("--subnet-tag <subnet>", "set subnet name", "community.3")
.option("-d, --debug", "output extra debugging");
program.parse(process.argv);
if (program.debug) {
utils.changeLogLevel("debug");
Expand Down
43 changes: 21 additions & 22 deletions examples/blender/blender.ts
@@ -1,19 +1,19 @@
import path from "path";
import dayjs from "dayjs";
import duration from "dayjs/plugin/duration";
import { Engine, Task, utils, vm, WorkContext } from "yajsapi";
import { Executor, Task, utils, vm, WorkContext } from "yajsapi";
import { program } from "commander";

dayjs.extend(duration);

const { asyncWith, logUtils, range } = utils;

async function main(subnetTag: string) {
const _package = await vm.repo(
"9a3b5d67b0b27746283cb5f287c13eab1beaa12d92a9f536b747c7ae",
0.5,
2.0
);
const _package = await vm.repo({
image_hash: "9a3b5d67b0b27746283cb5f287c13eab1beaa12d92a9f536b747c7ae",
min_mem_gib: 0.5,
min_storage_gib: 2.0,
});

async function* worker(ctx: WorkContext, tasks) {
ctx.send_file(
Expand Down Expand Up @@ -43,7 +43,7 @@ async function main(subnetTag: string) {
OUTPUT_DIR: "/golem/output",
});
ctx.run("/golem/entrypoints/run-blender.sh");
const output_file = `output_${frame.toString()}.png`
const output_file = `output_${frame.toString()}.png`;
ctx.download_file(
`/golem/output/out${frame.toString().padStart(4, "0")}.png`,
path.join(__dirname, `./output_${frame}.png`)
Expand All @@ -52,7 +52,7 @@ async function main(subnetTag: string) {
// TODO: Check
// job results are valid // and reject by:
// task.reject_task(msg = 'invalid file')
task.accept_task(output_file);
task.accept_result(output_file);
}

ctx.log("no more frames to render");
Expand All @@ -63,30 +63,29 @@ async function main(subnetTag: string) {
const timeout: number = dayjs.duration({ minutes: 15 }).asMilliseconds();

await asyncWith(
await new Engine(
_package,
6,
timeout, //5 min to 30 min
"10.0",
undefined,
subnetTag,
logUtils.logSummary()
),
async (engine: Engine): Promise<void> => {
for await (let task of engine.map(
new Executor({
task_package: _package,
max_workers: 6,
timeout: timeout,
budget: "10.0",
subnet_tag: subnetTag,
event_consumer: logUtils.logSummary(),
}),
async (executor: Executor): Promise<void> => {
for await (let task of executor.submit(
worker,
frames.map((frame) => new Task(frame))
)) {
console.log("result=", task.output());
console.log("result=", task.result());
}
}
);
return;
}

program
.option('--subnet-tag <subnet>', 'set subnet name', 'community.3')
.option('-d, --debug', 'output extra debugging');
.option("--subnet-tag <subnet>", "set subnet name", "community.3")
.option("-d, --debug", "output extra debugging");
program.parse(process.argv);
if (program.debug) {
utils.changeLogLevel("debug");
Expand Down
4 changes: 2 additions & 2 deletions examples/low-level-api/listOffers.js
Expand Up @@ -15,7 +15,7 @@ async function list_offers(conf, subnetTag) {
let market_api = new Market(client);
let dbuild = new yp.DemandBuilder();

let idx = new yp.Identification(subnetTag);
let idx = new yp.NodeInfo(subnetTag);
idx.name.value = "some scanning node";
dbuild.add(idx);

Expand All @@ -24,7 +24,7 @@ async function list_offers(conf, subnetTag) {
dbuild.add(act);

await asyncWith(
await market_api.subscribe(dbuild.props(), dbuild.cons()),
await market_api.subscribe(dbuild.properties(), dbuild.constraints()),
async (subscription) => {
for await (let event of subscription.events(cancellationToken)) {
console.log(`Offer: ${event.id()}`);
Expand Down
4 changes: 2 additions & 2 deletions examples/low-level-api/listOffers.ts
Expand Up @@ -16,7 +16,7 @@ async function list_offers(conf: rest.Configuration, subnetTag: string): Promise
let market_api = new Market(client);
let dbuild = new yp.DemandBuilder();

let idx = new yp.Identification(subnetTag);
let idx = new yp.NodeInfo(subnetTag);
idx.name.value = "some scanning node";
dbuild.add(idx);

Expand All @@ -25,7 +25,7 @@ async function list_offers(conf: rest.Configuration, subnetTag: string): Promise
dbuild.add(act);

await asyncWith(
await market_api.subscribe(dbuild.props(), dbuild.cons()),
await market_api.subscribe(dbuild.properties(), dbuild.constraints()),
async (subscription: Subscription) => {
for await (let event of subscription.events(cancellationToken)) {
console.log(`Offer: ${event.id()}`);
Expand Down
File renamed without changes.
5 changes: 2 additions & 3 deletions yajsapi/runner/events.ts → yajsapi/executor/events.ts
@@ -1,5 +1,4 @@
import { any } from "bluebird";
import { Identification } from "../props";
import { NodeInfo } from "../props";
import applyMixins from "../utils/applyMixins";

type ExcInfo = [Error, Error, any?]; // TracebackType
Expand Down Expand Up @@ -110,7 +109,7 @@ class AgreementEvent extends YaEvent {
}

export class AgreementCreated extends AgreementEvent {
provider_id?: Identification;
provider_id?: NodeInfo;
constructor({ agr_id, provider_id }) {
super();
if (agr_id) this.agr_id = agr_id;
Expand Down

0 comments on commit 80f3940

Please sign in to comment.