Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into josh/fix-mech-request…
Browse files Browse the repository at this point in the history
…s-criteria
  • Loading branch information
truemiller committed Jun 19, 2024
2 parents be11cc7 + f7fc8c6 commit 200e321
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 42 deletions.
73 changes: 39 additions & 34 deletions electron/install.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Installation helpers.

const nfs = require('node:fs')
const nfs = require('node:fs');
const fs = require('fs');
const os = require('os');
const sudo = require('sudo-prompt');
Expand All @@ -9,14 +9,14 @@ const axios = require('axios');

const Docker = require('dockerode');
const { spawnSync } = require('child_process');
const { BrewScript } = require("./scripts")
const { BrewScript } = require('./scripts');

/**
* current version of the pearl release
* - use "" (nothing as a suffix) for latest release candidate, for example "0.1.0rc26"
* - use "alpha" for alpha release, for example "0.1.0rc26-alpha"
*/
const OlasMiddlewareVersion = '0.1.0rc46';
const OlasMiddlewareVersion = '0.1.0rc50';
const OperateDirectory = `${os.homedir()}/.operate`;
const VenvDir = `${OperateDirectory}/venv`;
const TempDir = `${OperateDirectory}/temp`;
Expand Down Expand Up @@ -86,9 +86,9 @@ function runCmdUnix(command, options) {
Error: ${output.error}; Stdout: ${output.stdout}; Stderr: ${output.stderr}`,
);
}
console.log(appendLog(`Executed ${command} ${options} with`))
console.log(appendLog(`===== stdout ===== \n${output.stdout}`))
console.log(appendLog(`===== stderr ===== \n${output.stderr}`))
console.log(appendLog(`Executed ${command} ${options} with`));
console.log(appendLog(`===== stdout ===== \n${output.stdout}`));
console.log(appendLog(`===== stderr ===== \n${output.stderr}`));
}

function runSudoUnix(command, options) {
Expand All @@ -112,10 +112,10 @@ function runSudoUnix(command, options) {
Error: ${output.error}; Stdout: ${output.stdout}; Stderr: ${output.stderr}`,
);
}
console.log(appendLog(`Executed ${command} ${options} with`))
console.log(appendLog(`===== stdout ===== \n${output.stdout}`))
console.log(appendLog(`===== stderr ===== \n${output.stderr}`))
resolve()
console.log(appendLog(`Executed ${command} ${options} with`));
console.log(appendLog(`===== stdout ===== \n${output.stdout}`));
console.log(appendLog(`===== stderr ===== \n${output.stderr}`));
resolve();
},
);
});
Expand All @@ -126,37 +126,42 @@ function isBrewInstalled() {
}

async function installBrew() {
console.log(appendLog("Fetching homebrew source"))
let outdir = `${os.homedir()}/homebrew`
let outfile = `${os.homedir()}/homebrew.tar`
console.log(appendLog('Fetching homebrew source'));
let outdir = `${os.homedir()}/homebrew`;
let outfile = `${os.homedir()}/homebrew.tar`;

// Make temporary source dir
fs.mkdirSync(outdir)
fs.mkdirSync(outdir);

// Fetch brew source
runCmdUnix("curl", ["-L", "https://github.com/Homebrew/brew/tarball/master", "--output", outfile])
runCmdUnix("tar", ["-xvf", outfile, "--strip-components", "1", "-C", outdir])

runCmdUnix('curl', [
'-L',
'https://github.com/Homebrew/brew/tarball/master',
'--output',
outfile,
]);
runCmdUnix('tar', ['-xvf', outfile, '--strip-components', '1', '-C', outdir]);

// Check for cache and uninstall leftovers
if (fs.existsSync("/opt/homebrew")) {
console.log(appendLog("Removing homebrew leftovers"))
if (fs.existsSync('/opt/homebrew')) {
console.log(appendLog('Removing homebrew leftovers'));
if (!Env.CI) {
await runSudoUnix("rm", `-rf /opt/homebrew`)
await runSudoUnix('rm', `-rf /opt/homebrew`);
} else {
fs.rmdirSync("/opt/homebrew")
fs.rmdirSync('/opt/homebrew');
}
}

console.log(appendLog("Installing homebrew"))
console.log(appendLog('Installing homebrew'));
if (!Env.CI) {
await runSudoUnix("mv", `${outdir} /opt/homebrew`)
await runSudoUnix("chown", `-R ${os.userInfo().username} /opt/homebrew`)
await runSudoUnix('mv', `${outdir} /opt/homebrew`);
await runSudoUnix('chown', `-R ${os.userInfo().username} /opt/homebrew`);
} else {
runCmdUnix("mv", [outdir, "/opt/homebrew"])
runCmdUnix("chown", ["-R", os.userInfo().username, "/opt/homebrew"])
runCmdUnix('mv', [outdir, '/opt/homebrew']);
runCmdUnix('chown', ['-R', os.userInfo().username, '/opt/homebrew']);
}
runCmdUnix("brew", ["doctor"])
fs.rmSync(outfile)
runCmdUnix('brew', ['doctor']);
fs.rmSync(outfile);
}

function isTendermintInstalledUnix() {
Expand All @@ -177,7 +182,7 @@ async function downloadFile(url, dest) {
writer.on('error', reject);
});
} catch (err) {
fs.unlink(dest, () => { }); // Delete the file if there is an error
fs.unlink(dest, () => {}); // Delete the file if there is an error
console.error('Error downloading the file:', err.message);
}
}
Expand All @@ -199,8 +204,8 @@ async function installTendermintUnix() {

// TOFIX: Install tendermint in .operate instead of globally
if (!Env.CI) {
if (!fs.existsSync("/usr/local/bin")) {
await runSudoUnix('mkdir', '/usr/local/bin')
if (!fs.existsSync('/usr/local/bin')) {
await runSudoUnix('mkdir', '/usr/local/bin');
}
await runSudoUnix('install', 'tendermint /usr/local/bin/tendermint');
}
Expand Down Expand Up @@ -479,4 +484,4 @@ module.exports = {
LogFile,
OperateInstallationLog,
},
};
};
4 changes: 2 additions & 2 deletions frontend/constants/serviceTemplates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { ServiceTemplate } from '@/client';
export const SERVICE_TEMPLATES: ServiceTemplate[] = [
{
name: 'Trader Agent',
hash: 'bafybeihv3nyh43rim6kcxdscdgsiojhbqfwndhwcrtxhi3gkxbnasdc7ui',
hash: 'bafybeieg45wcjcwd5znuwpjcp5scfhgdqwpfq43pzaare6nwvmy5bb56cm',
description: 'Trader agent for omen prediction markets',
image:
'https://operate.olas.network/_next/image?url=%2Fimages%2Fprediction-agent.png&w=3840&q=75',
configuration: {
nft: 'bafybeig64atqaladigoc3ds4arltdu63wkdrk3gesjfvnfdmz35amv7faq',
nft: 'bafybeiei7wb5jvrn7e7fss2t6ajnkjakgf7uaz42fvvlkolhpnez2dlfsy',
agent_id: 14,
threshold: 1,
use_staking: true,
Expand Down
21 changes: 20 additions & 1 deletion operate/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
from operate.account.user import UserAccount
from operate.constants import KEY, KEYS, OPERATE, SERVICES
from operate.ledger import get_ledger_type_from_chain_type
from operate.types import ChainType
from operate.types import ChainType, DeploymentStatus
from operate.wallet.master import MasterWalletManager


Expand Down Expand Up @@ -179,6 +179,25 @@ def cancel_funding_job(service: str) -> None:
if not status:
logger.info(f"Funding job cancellation for {service} failed")

def pause_all_services_on_startup():
logger.info(f"stopping services on startup")
services = [i["hash"] for i in operate.service_manager().json]

for service in services:
if not operate.service_manager().exists(service=service):
continue
deployment = operate.service_manager().create_or_load(service).deployment
if deployment.status == DeploymentStatus.DELETED:
continue
logger.info(f"stopping service {service}")
deployment.stop(force=True)
logger.info(f"Cancelling funding job for {service}")
cancel_funding_job(service=service)
logger.info(f"stopping services on startup: done")

# on backend app started we assume there are now started agents, so we force to pause all
pause_all_services_on_startup()

app = FastAPI()

app.add_middleware(
Expand Down
4 changes: 2 additions & 2 deletions operate/services/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -822,9 +822,9 @@ def start(self, use_docker: bool = False) -> None:
self.status = DeploymentStatus.DEPLOYED
self.store()

def stop(self, use_docker: bool = False) -> None:
def stop(self, use_docker: bool = False, force: bool=False) -> None:
"""Stop the deployment."""
if self.status != DeploymentStatus.DEPLOYED:
if self.status != DeploymentStatus.DEPLOYED and not force:
return

self.status = DeploymentStatus.STOPPING
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"main": "electron/main.js",
"name": "olas-operate-app",
"productName": "Pearl",
"version": "0.1.0-rc46",
"version": "0.1.0-rc50",
"dependencies": {
"@ant-design/cssinjs": "^1.18.4",
"@ant-design/icons": "^5.3.0",
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "olas-operate-middleware"
version = "0.1.0-rc46"
version = "0.1.0-rc50"
description = ""
authors = ["David Vilela <[email protected]>", "Viraj Patel <[email protected]>"]
readme = "README.md"
Expand Down
2 changes: 1 addition & 1 deletion templates/trader.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: "Trader Agent"
description: "Trader agent for omen prediction markets"
hash: bafybeihv3nyh43rim6kcxdscdgsiojhbqfwndhwcrtxhi3gkxbnasdc7ui
hash: bafybeieg45wcjcwd5znuwpjcp5scfhgdqwpfq43pzaare6nwvmy5bb56cm
image: https://operate.olas.network/_next/image?url=%2Fimages%2Fprediction-agent.png&w=3840&q=75
configuration:
nft: bafybeig64atqaladigoc3ds4arltdu63wkdrk3gesjfvnfdmz35amv7faq
Expand Down

0 comments on commit 200e321

Please sign in to comment.