Skip to content

Commit

Permalink
Merge pull request permaweb#885 from permaweb/jfrain99/add-module-tag…
Browse files Browse the repository at this point in the history
…-to-spawn

fix(mu): add module tags to spawn permaweb#855
  • Loading branch information
jfrain99 authored Jul 16, 2024
2 parents 0c1fee7 + 96c06f5 commit 98c5f10
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 5 deletions.
5 changes: 3 additions & 2 deletions servers/mu/src/domain/api/processSpawn.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ export function processSpawnWith ({
locateNoRedirect,
writeDataItem,
buildAndSign,
fetchResult
fetchResult,
fetchSchedulerProcess
}) {
const spawnProcess = spawnProcessWith({ logger, writeDataItem, locateScheduler, locateNoRedirect, buildAndSign })
const spawnProcess = spawnProcessWith({ logger, writeDataItem, locateScheduler, locateNoRedirect, buildAndSign, fetchSchedulerProcess })
const buildSuccessTx = buildSuccessTxWith({ logger, buildAndSign })
const sendSpawnSuccess = sendSpawnSuccessWith({ logger, writeDataItem, locateProcess })
const pullResult = pullResultWith({ fetchResult, logger })
Expand Down
3 changes: 2 additions & 1 deletion servers/mu/src/domain/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,8 @@ export const createResultApis = async (ctx) => {
locateNoRedirect,
buildAndSign: signerClient.buildAndSignWith({ MU_WALLET, logger: processMsgLogger }),
writeDataItem: schedulerClient.writeDataItemWith({ fetch, histogram, logger: processSpawnLogger }),
fetchResult: cuClient.resultWith({ fetch: fetchWithCache, histogram, CU_URL, logger: processMsgLogger })
fetchResult: cuClient.resultWith({ fetch: fetchWithCache, histogram, CU_URL, logger: processMsgLogger }),
fetchSchedulerProcess: schedulerClient.fetchSchedulerProcessWith({ getByProcess, setByProcess, fetch, histogram, logger: processMsgLogger })
})

const processAssignLogger = logger.child('processAssign')
Expand Down
50 changes: 48 additions & 2 deletions servers/mu/src/domain/lib/spawn-process.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { of, fromPromise, Rejected, Resolved } from 'hyper-async'
import { assoc, identity, is } from 'ramda'
import { assoc, find, identity, is, map, prop, propEq, when } from 'ramda'
// import z from 'zod'

import { checkStage, parseTags } from '../utils.js'
Expand All @@ -9,8 +9,9 @@ import { checkStage, parseTags } from '../utils.js'
// }).passthrough()

export function spawnProcessWith (env) {
let { logger, writeDataItem, locateScheduler, locateNoRedirect, buildAndSign } = env
let { logger, writeDataItem, locateScheduler, locateNoRedirect, buildAndSign, fetchSchedulerProcess } = env

fetchSchedulerProcess = fromPromise(fetchSchedulerProcess)
writeDataItem = fromPromise(writeDataItem)
locateScheduler = fromPromise(locateScheduler)
locateNoRedirect = fromPromise(locateNoRedirect)
Expand Down Expand Up @@ -66,6 +67,28 @@ export function spawnProcessWith (env) {
transformedData.tags.push({ name: 'Scheduler', value: schedulerResult.address })
return of(transformedData.tags)
.chain(findModuleTag) // just needs to throw an error if not there
.chain(() => fetchSchedulerProcess(
ctx.cachedSpawn.processId,
schedulerResult.url
))
.map((process) => {
/**
* Grab module Id from SU response
*/
const moduleId = prop('value', find(propEq('Module', 'name'))(process.tags))
/**
* Replace 'Module', 'From-Module' tags with the module id from SU
*/
const replaceModuleTags = map(
when(
propEq('From-Module', 'name'),
(item) => { item.value = moduleId }
)
)

replaceModuleTags(transformedData.tags)
return process
})
.chain(
fromPromise(() => buildAndSign(transformedData))
)
Expand All @@ -78,6 +101,29 @@ export function spawnProcessWith (env) {
.chain((schedulerResult) => {
return of(transformedData.tags)
.chain(findModuleTag) // just needs to throw an error if not there
.chain(() => fetchSchedulerProcess(
ctx.cachedSpawn.processId,
schedulerResult.url
))
.map((process) => {
/**
* Grab module Id from SU response
*/
const moduleId = prop('value', find(propEq('Module', 'name'))(process.tags))

/**
* Replace 'Module', 'From-Module' tags with the module id from SU
*/
const replaceModuleTags = map(
when(
propEq('From-Module', 'name'),
(item) => { item.value = moduleId }
)
)

replaceModuleTags(transformedData.tags)
return process
})
.chain(
fromPromise(() => buildAndSign(transformedData))
)
Expand Down

0 comments on commit 98c5f10

Please sign in to comment.