Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 'v20.19.0'
node-version: 'v22.15.0'
- name: Cache node_modules
uses: actions/cache@v3
env:
Expand All @@ -42,7 +42,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
node: ['18.20.4', 'v20.19.0', 'v22.5.1']
node: ['18.20.4', 'v20.19.0', 'v22.15.0']

steps:
- uses: actions/checkout@v4
Expand All @@ -66,7 +66,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 'v20.19.0'
node-version: 'v22.15.0'
- name: Cache node_modules
uses: actions/cache@v3
env:
Expand Down Expand Up @@ -102,7 +102,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 'v20.19.0'
node-version: 'v22.15.0'
- name: Cache node_modules
uses: actions/cache@v3
env:
Expand Down Expand Up @@ -180,7 +180,7 @@ jobs:
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 'v20.19.0'
node-version: 'v22.15.0'

- name: Cache node_modules
uses: actions/cache@v3
Expand Down Expand Up @@ -313,7 +313,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 'v20.19.0'
node-version: 'v22.15.0'
- name: Cache node_modules
uses: actions/cache@v3
env:
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v20.19.0
22
11 changes: 7 additions & 4 deletions config.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"authorizedDecrypters": [],
"authorizedDecryptersList": [],
"authorizedDecryptersList": null,
"allowedValidators": [],
"allowedValidatorsList": [],
"allowedValidatorsList": null,
"authorizedPublishers": [],
"authorizedPublishersList": [],
"authorizedPublishersList": null,
"keys": {},
"hasIndexer": true,
"hasHttp": true,
Expand All @@ -19,6 +19,7 @@
"ipV4BindAddress": "0.0.0.0",
"ipV4BindTcpPort": 9000,
"ipV4BindWsPort": 9001,
"ipV4BindWssPort": 9005,
"ipV6BindAddress": "::",
"ipV6BindTcpPort": 9002,
"ipV6BindWsPort": 9003,
Expand Down Expand Up @@ -81,7 +82,7 @@
"accountPurgatoryUrl": null,
"assetPurgatoryUrl": null,
"allowedAdmins": [],
"allowedAdminsList": [],
"allowedAdminsList": null,
"rateLimit": 30,
"maxConnections": 30,
"denyList": {
Expand All @@ -104,6 +105,7 @@
],
"storageExpiry": 604800,
"maxJobDuration": 3600,
"minJobDuration": 60,
"access": {
"addresses": [],
"accessLists": []
Expand All @@ -122,6 +124,7 @@
},
"free": {
"maxJobDuration": 3600,
"minJobDuration": 60,
"maxJobs": 3,
"access": {
"addresses": [],
Expand Down
5 changes: 2 additions & 3 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions src/@types/C2D/C2D.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export interface ComputeEnvironmentFreeOptions {
// only if a compute env exposes free jobs
storageExpiry?: number
maxJobDuration?: number
minJobDuration?: number
maxJobs?: number // maximum number of simultaneous free jobs
resources?: ComputeResource[]
access: ComputeAccessList
Expand Down Expand Up @@ -133,6 +134,7 @@ export interface C2DDockerConfig {
keyPath: string
storageExpiry?: number
maxJobDuration?: number
minJobDuration?: number
maxJobs?: number
fees: ComputeEnvFeesStructure
resources?: ComputeResource[] // optional, owner can overwrite
Expand Down
72 changes: 42 additions & 30 deletions src/components/c2d/compute_engine_docker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ export class C2DEngineDocker extends C2DEngine {
// let's build the env. Swarm and k8 will build multiple envs, based on arhitecture
const config = await getConfiguration()
const envConfig = await this.getC2DConfig().connection
console.log(config)
console.log(envConfig)
let sysinfo = null
try {
sysinfo = await this.docker.info()
Expand Down Expand Up @@ -133,7 +131,7 @@ export class C2DEngineDocker extends C2DEngine {
envConfig.fees[feeChain][i].prices.length > 0
) {
if (!envConfig.fees[feeChain][i].feeToken) {
const tokenAddress = await getOceanTokenAddressForChain(parseInt(feeChain))
const tokenAddress = getOceanTokenAddressForChain(parseInt(feeChain))
if (tokenAddress) {
envConfig.fees[feeChain][i].feeToken = tokenAddress
tmpFees.push(envConfig.fees[feeChain][i])
Expand Down Expand Up @@ -172,7 +170,7 @@ export class C2DEngineDocker extends C2DEngine {
},
access: {
addresses: [],
accessLists: []
accessLists: null
},
fees,
queuedJobs: 0,
Expand All @@ -183,6 +181,8 @@ export class C2DEngineDocker extends C2DEngine {
if (`access` in envConfig) this.envs[0].access = envConfig.access

if (`storageExpiry` in envConfig) this.envs[0].storageExpiry = envConfig.storageExpiry
if (`minJobDuration` in envConfig)
this.envs[0].minJobDuration = envConfig.minJobDuration
if (`maxJobDuration` in envConfig)
this.envs[0].maxJobDuration = envConfig.maxJobDuration
if (`maxJobs` in envConfig) this.envs[0].maxJobs = envConfig.maxJobs
Expand Down Expand Up @@ -249,12 +249,14 @@ export class C2DEngineDocker extends C2DEngine {
this.envs[0].free = {
access: {
addresses: [],
accessLists: []
accessLists: null
}
}
if (`access` in envConfig.free) this.envs[0].free.access = envConfig.free.access
if (`storageExpiry` in envConfig.free)
this.envs[0].free.storageExpiry = envConfig.free.storageExpiry
if (`minJobDuration` in envConfig.free)
this.envs[0].free.minJobDuration = envConfig.free.minJobDuration
if (`maxJobDuration` in envConfig.free)
this.envs[0].free.maxJobDuration = envConfig.free.maxJobDuration
if (`maxJobs` in envConfig.free) this.envs[0].free.maxJobs = envConfig.free.maxJobs
Expand Down Expand Up @@ -794,36 +796,46 @@ export class C2DEngineDocker extends C2DEngine {
}
}

private async setNewTimer() {
private setNewTimer() {
if (this.cronTimer) {
return
}
// don't set the cron if we don't have compute environments
if ((await this.getComputeEnvironments()).length > 0)
this.cronTimer = setInterval(this.InternalLoop.bind(this), this.cronTime)
if (this.envs.length > 0)
this.cronTimer = setTimeout(this.InternalLoop.bind(this), this.cronTime)
}

private async InternalLoop() {
// this is the internal loop of docker engine
// gets list of all running jobs and process them one by one
clearInterval(this.cronTimer)
this.cronTimer = null
// get all running jobs
const jobs = await this.db.getRunningJobs(this.getC2DConfig().hash)
if (this.cronTimer) {
clearTimeout(this.cronTimer)
this.cronTimer = null
}
try {
// get all running jobs
const jobs = await this.db.getRunningJobs(this.getC2DConfig().hash)

if (jobs.length === 0) {
// CORE_LOGGER.info('No C2D jobs found for engine ' + this.getC2DConfig().hash)
if (jobs.length === 0) {
CORE_LOGGER.info('No C2D jobs found for engine ' + this.getC2DConfig().hash)
this.setNewTimer()
return
} else {
CORE_LOGGER.info(`Got ${jobs.length} jobs for engine ${this.getC2DConfig().hash}`)
CORE_LOGGER.debug(JSON.stringify(jobs))
}
const promises: any = []
for (const job of jobs) {
promises.push(this.processJob(job))
}
// wait for all promises, there is no return
await Promise.all(promises)
} catch (e) {
CORE_LOGGER.error(`Error in C2D InternalLoop: ${e.message}`)
} finally {
// set the cron again
this.setNewTimer()
return
} else {
CORE_LOGGER.info(`Got ${jobs.length} jobs for engine ${this.getC2DConfig().hash}`)
CORE_LOGGER.debug(JSON.stringify(jobs))
}
const promises: any = []
for (const job of jobs) {
promises.push(this.processJob(job))
}
// wait for all promises, there is no return
await Promise.all(promises)
// set the cron again
this.setNewTimer()
}

private async createDockerContainer(
Expand Down Expand Up @@ -935,7 +947,7 @@ export class C2DEngineDocker extends C2DEngine {
}
// resources are now available, let's start the job
const { algorithm } = job
if (algorithm.meta.container && algorithm.meta.container.dockerfile) {
if (algorithm?.meta.container && algorithm?.meta.container.dockerfile) {
job.status = C2DStatusNumber.BuildImage
job.statusText = C2DStatusText.BuildImage
this.buildImage(job, null)
Expand Down Expand Up @@ -1038,7 +1050,7 @@ export class C2DEngineDocker extends C2DEngine {
containerInfo.HostConfig.IpcMode = advancedConfig.IpcMode
if (advancedConfig.ShmSize)
containerInfo.HostConfig.ShmSize = advancedConfig.ShmSize
if (job.algorithm.meta.container.entrypoint) {
if (job.algorithm?.meta.container.entrypoint) {
const newEntrypoint = job.algorithm.meta.container.entrypoint.replace(
'$ALGO',
'data/transformations/algorithm'
Expand Down Expand Up @@ -1336,7 +1348,7 @@ export class C2DEngineDocker extends C2DEngine {
// console.error('Container not found! ' + e.message)
}
try {
const volume = await this.docker.getVolume(job.jobId + '-volume')
const volume = this.docker.getVolume(job.jobId + '-volume')
if (volume) {
try {
await volume.remove()
Expand All @@ -1347,7 +1359,7 @@ export class C2DEngineDocker extends C2DEngine {
} catch (e) {
// console.error('Container volume not found! ' + e.message)
}
if (job.algorithm.meta.container && job.algorithm.meta.container.dockerfile) {
if (job.algorithm?.meta.container && job.algorithm?.meta.container.dockerfile) {
const image = getAlgorithmImage(job.algorithm, job.jobId)
if (image) {
try {
Expand Down
Loading
Loading