Skip to content
This repository has been archived by the owner on Nov 14, 2019. It is now read-only.

Commit

Permalink
Merge pull request #115 from mesg-foundation/feature/workflow-compiler
Browse files Browse the repository at this point in the history
Workflow compilation
  • Loading branch information
antho1404 authored Jul 26, 2019
2 parents fec62ce + be4b5b0 commit dcf696b
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 13 deletions.
6 changes: 3 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: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"is-git-url": "^1.0.0",
"js-yaml": "^3.13.1",
"lodash.pick": "^4.4.0",
"mesg-js": "^4.1.0",
"mesg-js": "^4.2.0-beta3",
"node-docker-api": "^1.1.22",
"rimraf": "^2.6.3",
"tar": "^4.4.8",
Expand Down
2 changes: 1 addition & 1 deletion src/commands/service/compile.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {readFileSync} from 'fs'
import {Service} from 'mesg-js/lib/api'
import {Service} from 'mesg-js/lib/api/types'
import {join} from 'path'

import {WithoutPassphrase} from '../../account-command'
Expand Down
1 change: 1 addition & 0 deletions src/commands/service/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default class ServiceCreate extends Command {
const {args} = this.parse(ServiceCreate)
this.spinner.start('Create service')
const resp = await this.api.service.create(JSON.parse(args.DEFINITION))
if (!resp.hash) { throw new Error('invalid response') }
this.spinner.stop(resp.hash)
return resp
}
Expand Down
1 change: 1 addition & 0 deletions src/commands/service/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export default class ServiceExecute extends Command {
const instance = await this.api.instance.get({
hash: instanceHash
})
if (!instance.serviceHash) { throw new Error('invalid service hash') }
const service = await ServiceDetail.run([instance.serviceHash, '--silent'])

const task = service.tasks.find((x: any) => x.key === args.TASK)
Expand Down
10 changes: 5 additions & 5 deletions src/commands/service/list.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import cli from 'cli-ux'
import {Instance} from 'mesg-js/lib/api'
import {Instance, Service} from 'mesg-js/lib/api/types'

import Command from '../../root-command'

Expand All @@ -16,17 +16,17 @@ export default class ServiceList extends Command {
const {services} = await this.api.service.list({})
const {instances} = await this.api.instance.list({})
if (!services) return []
cli.table(services, {
cli.table<Service>(services, {
hash: {header: 'HASH', get: x => x.hash},
sid: {header: 'SID', get: x => x.sid},
instances: {
header: 'INSTANCES',
get: x => (instances || [])
get: x => (instances as Instance[])
.filter(y => y.serviceHash === x.hash)
.map(x => x.hash)
.map(y => y.hash)
.join('\n')
}
}, {printLine: this.log, ...flags})
return instances
return instances || []
}
}
2 changes: 1 addition & 1 deletion src/commands/service/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export default class ServiceLogs extends Command {
}

formatEvent(event: Event) {
return `EVENT[${event.key}]: ` + chalk.gray(event.data)
return `EVENT[${event.key}]: ` + chalk.gray(event.data || '')
}
formatResult(execution: Execution) {
if (execution.error) {
Expand Down
1 change: 1 addition & 0 deletions src/commands/service/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export default class ServiceStart extends Command {
serviceHash,
env: flags.env
})
if (!instance.hash) throw new Error('invalid instance')
this.spinner.stop(instance.hash)
return instance
}
Expand Down
4 changes: 3 additions & 1 deletion src/utils/compiler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import yaml from 'js-yaml'
import pick from 'lodash.pick'
import {Service} from 'mesg-js/lib/api/types'

const decode = (content: Buffer) => yaml.safeLoad(content.toString())

Expand All @@ -13,7 +14,7 @@ const parseParams = (params: any): any => mapToArray(params).map(x => ({
object: parseParams(x.object),
}))

export default async (content: Buffer): Promise<any> => {
export default async (content: Buffer): Promise<Service> => {
const definition = decode(content)
return {
...pick(definition, ['sid', 'name', 'description', 'configuration', 'repository']),
Expand All @@ -27,5 +28,6 @@ export default async (content: Buffer): Promise<any> => {
...pick(x, ['key', 'name', 'description']),
data: parseParams(x.data)
})),
workflows: mapToArray(definition.workflows).map(x => pick(x, ['key', 'trigger', 'task']))
}
}
2 changes: 1 addition & 1 deletion src/utils/service-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default async (api: API, sidOrHash: hash | string): Promise<hash> => {
return sidOrHash
} catch {
const {services} = await api.service.list({})
const match = services.filter(x => x.sid === sidOrHash)
const match = (services || []).filter(x => x.sid === sidOrHash)
if (match.length === 0) throw new Error(`no service matching ${sidOrHash}`)
if (match.length > 1) throw new Error(`multiple services matching ${sidOrHash}`)
return match[0].hash as hash
Expand Down

0 comments on commit dcf696b

Please sign in to comment.