You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Renting a single machine and running a simple task on it
import{MarketOrderSpec,GolemNetwork}from"@golem-sdk/golem-js";// Define the order that we're going to place on the marketconstorder: MarketOrderSpec={demand: {workload: {imageTag: "golem/alpine:latest"},},market: {// We're only going to rent the provider for 15 minutes maxrentHours: 15/60,pricing: {model: "linear",maxStartPrice: 0.5,maxCpuPerHourPrice: 1.0,maxEnvPerHourPrice: 0.5,},},};(async()=>{constglm=newGolemNetwork();try{awaitglm.connect();// Rent a machineconstrental=awaitglm.oneOf({ order });awaitrental.getExeUnit().then((exe)=>exe.run("echo Hello, Golem! 👋")).then((res)=>console.log(res.stdout));awaitrental.stopAndFinalize();}catch(err){console.error("Failed to run the example",err);}finally{awaitglm.disconnect();}})().catch(console.error);
Renting many machines and running tasks in parallel
import{GolemNetwork,MarketOrderSpec}from"@golem-sdk/golem-js";// Define the order that we're going to place on the marketconstorder: MarketOrderSpec={demand: {workload: {imageTag: "golem/alpine:latest"},},market: {rentHours: 0.5,pricing: {model: "linear",maxStartPrice: 0.5,maxCpuPerHourPrice: 1.0,maxEnvPerHourPrice: 0.5,},},};(async()=>{constglm=newGolemNetwork();try{awaitglm.connect();// create a pool that can grow up to 3 rentals at the same timeconstpool=awaitglm.manyOf({poolSize: 3,
order,});// run 3 tasks in parallel on 3 different machinesawaitPromise.allSettled([pool.withRental(async(rental)=>rental.getExeUnit().then((exe)=>exe.run("echo Hello, Golem from the first machine! 👋")).then((res)=>console.log(res.stdout)),),pool.withRental(async(rental)=>rental.getExeUnit().then((exe)=>exe.run("echo Hello, Golem from the second machine! 👋")).then((res)=>console.log(res.stdout)),),pool.withRental(async(rental)=>rental.getExeUnit().then((exe)=>exe.run("echo Hello, Golem from the third machine! 👋")).then((res)=>console.log(res.stdout)),),]);}catch(err){console.error("Failed to run the example",err);}finally{awaitglm.disconnect();}})().catch(console.error);