Skip to content

Commit

Permalink
Debugging and cleanup (#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
agodwinrelay committed Dec 1, 2023
1 parent 6fe07c7 commit e3ee5d5
Show file tree
Hide file tree
Showing 12 changed files with 166 additions and 129 deletions.
9 changes: 6 additions & 3 deletions docs/workflow.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ USAGE
$ relay workflow:args:set -w <value> -s <value> [-a <value>] [-b <value>] [-r <value>]
FLAGS
-s, --subscriber-id=<value> (required) [default: 282b5c81-2410-4302-8f74-95207bdbe9d9] subscriber id
-s, --subscriber-id=<value> (required) [default: 282b5c81-2410-4302-8f74-95207bdbe9d9] subscriber id
-w, --workflow-id=<value> (required) workflow id
-a, --arg=<value>... String name/value pair workflow arg
-b, --boolean=arg1=[true|false]... Boolean name/value pair workflow arg
Expand Down Expand Up @@ -426,7 +426,7 @@ FLAGS
Number name/value pair workflow arg
-s, --start=<value>
[default: 2023-11-10T13:00:00]
[default: 2023-12-01T12:00:00]
-t, --[no-]transient
Allow workflow to run in the background; otherwise terminate workflow
Expand Down Expand Up @@ -514,7 +514,7 @@ List workflow configurations

```
USAGE
$ relay workflow:list -s <value> [--columns <value> | -x] [--sort <value>] [--filter <value>] [--output
$ relay workflow:list -s <value> [--json] [--columns <value> | -x] [--sort <value>] [--filter <value>] [--output
csv|json|yaml | | [--csv | --no-truncate]] [--no-header | ]
FLAGS
Expand All @@ -529,6 +529,9 @@ FLAGS
<options: csv|json|yaml>
--sort=<value> property to sort by (prepend '-' for descending)
GLOBAL FLAGS
--json Format output as json.
DESCRIPTION
List workflow configurations
```
Expand Down
59 changes: 6 additions & 53 deletions src/commands/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import debugFn = require('debug')

import * as flags from '../lib/flags'
import { CliUx } from '@oclif/core'
import { WorkflowEvent, WorkflowEventQuery, WorkflowEvents } from '../lib/api'
import { WorkflowEventQuery, WorkflowEvents } from '../lib/api'
import { isEmpty } from 'lodash'
import { Result, Ok } from 'ts-results'
// import { CliUx } from '@oclif/core'
import { printAnalytics } from '../lib/utils'

const debug = debugFn(`analytics`)

Expand Down Expand Up @@ -108,63 +108,16 @@ export default class Analytics extends Command {
let analytics: WorkflowEvents = []

try {

analytics = await this.relay.workflowEvents(subscriberId, query)
if (!this.jsonEnabled()) {
if (!isEmpty(analytics)) {
CliUx.ux.log(`=> Showing ${analytics?.length} events`)
CliUx.ux.table(analytics, {
workflow_id: {
header: `Workflow ID`,
},
source_type: {
header: `Type`,
},
category: {},
workflow_instance_id: {
header: `Instance ID`,
},
id: {
header: `Analytic ID`,
extended: true
},
timestamp: {},
user_id: {
header: `User ID`,
},
content_type: {
header: `Content Type`,
extended: true,
},
content: {
get: row => {
if (parse) {
return parseContent(row)
} else {
return row.content
}
}
},
})
CliUx.ux.log(`=> Showing ${analytics?.length} events`)
} else {
this.log(`No analytic events found from the provided criteria`)
}
if (isEmpty(analytics)) {
this.log(`No analytic events found from the provided criteria`)
} else if (!this.jsonEnabled()) {
printAnalytics(analytics, flags, parse)
}
} catch (err) {
debug(err)
this.safeError(err)
}

return Ok(analytics)
}
}


const parseContent = (row: WorkflowEvent): string => {
if (row.content_type === `application/json` || row.content_type == `application/vnd.relay.tasks.parameters.v2+json`) {
return JSON.stringify(JSON.parse(row.content), null, 2)
} else {
return row.content
}
}
3 changes: 1 addition & 2 deletions src/commands/task/groups/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ export default class TaskGroupsCreateCommand extends Command {
try {
const group = await createTaskGroup(taskGroupArgs)
const success = await this.relay.createTaskGroup(subscriberId, group)

if (success) {
this.log(`Successfully started created task group`)
this.log(`Successfully created task group`)
} else {
this.log(`Could not create task group`)
}
Expand Down
20 changes: 13 additions & 7 deletions src/commands/task/groups/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ import { printTaskGroups } from '../../../lib/utils'
// eslint-disable-next-line quotes
import debugFn = require('debug')
import { isEmpty } from 'lodash'
import { Err, Ok, Result } from 'ts-results'
import { TaskGroup } from '../../../lib/api'

const debug = debugFn(`task-groups:list`)

export default class TaskGroupsListCommand extends Command {
static description = `List task groups`
static strict = false
static enableJsonFlag = true

static hidden = true

Expand All @@ -22,26 +25,29 @@ export default class TaskGroupsListCommand extends Command {
...CliUx.ux.table.flags(),
}

async run(): Promise<void> {
async run(): Promise<Result<TaskGroup[], Error>> {
const { flags } = await this.parse(TaskGroupsListCommand)
const subscriberId = flags[`subscriber-id`]

const output = flags.output
try {
const groups = await this.relay.fetchTaskGroups(subscriberId)

debug(`groups`, groups)

if (isEmpty(groups)) {
this.log(`No task groups have been created.`)
} else {
printTaskGroups(groups, flags)
} else if (!this.jsonEnabled()) {
if (output == `json`) {
this.log(JSON.stringify(groups)) // to make assign-to proper json
} else {
printTaskGroups(groups, flags)
}
}

return Ok(groups)
} catch (err) {
debug(err)
this.safeError(err)
return Err(this.safeError(err))
}

}
}

36 changes: 23 additions & 13 deletions src/commands/task/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@ import { CliUx } from '@oclif/core'
import { Command } from '../../lib/command'
import * as flags from '../../lib/flags'
import { isEmpty } from 'lodash'
import { filterByTag, printScheduledTasks, printTasks } from '../../lib/utils'
import { filterByTag, getTaskGroup, printScheduledTasks, printTasks } from '../../lib/utils'
// eslint-disable-next-line quotes
import debugFn = require('debug')

import { ScheduledTask } from '../../lib/api'
import { ScheduledTask, Task } from '../../lib/api'
import { Err, Ok, Result } from 'ts-results'

const debug = debugFn(`tasks:list`)

export default class TaskListCommand extends Command {
static description = `List task configurations`
static enableJsonFlag = true

static hidden = true

static flags = {
Expand All @@ -39,45 +42,52 @@ export default class TaskListCommand extends Command {
exclusive: [`tag`]
})
}
async run(): Promise<void> {
async run(): Promise<Result<Task[], Error>> {
const { flags } = await this.parse(TaskListCommand)
const subscriberId = flags[`subscriber-id`]
const groupName = flags[`group-name`]

const output = flags.output
try {
let taskEndpoint
let tasks
if (flags.scheduled) {
taskEndpoint = `scheduled_task`
} else {
taskEndpoint = `task`
}
let tasks
if (groupName) {
tasks = await this.relay.fetchTasks(subscriberId, taskEndpoint, groupName)
const groups = await this.relay.fetchTaskGroups(subscriberId)
const group = getTaskGroup(groups, groupName)
if (group == undefined) {
this.error(`No group found with name ${groupName}`)
} else {
tasks = await this.relay.fetchTasks(subscriberId, taskEndpoint, group?.task_group_id)
}
} else {
tasks = await this.relay.fetchTasks(subscriberId, taskEndpoint)
}

if (flags.tag) {
tasks = filterByTag(tasks, flags.tag)
}

debug(`tasks`, tasks)

if (!isEmpty(tasks)) {
if (flags.scheduled) {
if (isEmpty(tasks)) {
this.log(`No tasks have been ${flags.scheduled ? `scheduled` : `started`} yet${groupName ? ` with group name ${groupName}` : ``}`)
} else if (!this.jsonEnabled()) {
if (output == `json`) {
this.log(JSON.stringify(tasks)) // to make assign-to and args attributes proper json
} else if (flags.scheduled) {
printScheduledTasks((tasks as ScheduledTask[]), flags)
} else {
printTasks(tasks, flags)
}
} else {
this.log(`No tasks have been ${flags.scheduled ? `scheduled` : `started`} yet${groupName ? ` with group ID ${groupName}` : ``}`)
}
return Ok(tasks)
} catch (err) {
debug(err)
this.safeError(err)
return Err(this.safeError(err))
}

}
}

16 changes: 11 additions & 5 deletions src/commands/task/types/dump.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ import debugFn = require('debug')
import { printDump } from '../../../lib/utils'
import { TaskTypeDump } from '../../../lib/api'
import { createTaskTypeDump } from '../../../lib/task-types'
import { Err, Ok, Result } from 'ts-results'
import { isEmpty } from 'lodash'

const debug = debugFn(`task-types:dump`)

export default class TaskTypesDumpCommand extends Command {
static description = `Dumps task types along with their latest minor, major, and comment`
static strict = false
static enableJsonFlag = true

static hidden = true

Expand All @@ -32,7 +35,7 @@ export default class TaskTypesDumpCommand extends Command {
hidden: false
}
]
async run(): Promise<void> {
async run(): Promise<Result<TaskTypeDump[], Error>> {
const { flags, argv } = await this.parse(TaskTypesDumpCommand)
const subscriberId = flags[`subscriber-id`]
const namespace = argv[0] as string
Expand All @@ -47,12 +50,15 @@ export default class TaskTypesDumpCommand extends Command {
const taskTypeDump = await createTaskTypeDump(type.name, major.major, minor.minor, minor.comment)
latestTaskTypes.push(taskTypeDump)
}

printDump(latestTaskTypes, flags, namespace)

if (isEmpty(latestTaskTypes)) {
this.log(`No task types have been created`)
} else if (!this.jsonEnabled()) {
printDump(latestTaskTypes, flags, namespace)
}
return Ok(latestTaskTypes)
} catch (err) {
debug(err)
this.safeError(err)
return Err(this.safeError(err))
}

}
Expand Down
15 changes: 8 additions & 7 deletions src/commands/task/types/list/majors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ import { printMajors } from '../../../../lib/utils'
// eslint-disable-next-line quotes
import debugFn = require('debug')
import { isEmpty } from 'lodash'
import { Err, Ok, Result } from 'ts-results'
import { Major } from '../../../../lib/api'

const debug = debugFn(`task-types:list`)

export default class TaskTypesListMajorsCommand extends Command {
static description = `List task type configurations`
static strict = false
static enableJsonFlag = true

static hidden = true

Expand All @@ -35,27 +38,25 @@ export default class TaskTypesListMajorsCommand extends Command {
description: `Task type name`,
}
]
async run(): Promise<void> {
async run(): Promise<Result<Major[], Error>> {
const { flags, argv } = await this.parse(TaskTypesListMajorsCommand)
const subscriberId = flags[`subscriber-id`]
const namespace = argv[0] as string
const type = argv[1] as string

try {
const majors = await this.relay.fetchMajors(subscriberId, namespace, type)

debug(`majors`, majors)

if (isEmpty(majors)) {
this.error(`No majors found: Check namespace and type args.`)
} else if (!this.jsonEnabled()) {
printMajors(majors, flags, type, namespace)
}

printMajors(majors, flags, type, namespace)

return Ok(majors)
} catch (err) {
debug(err)
this.safeError(err)
return Err(this.safeError(err))
}

}
}

0 comments on commit e3ee5d5

Please sign in to comment.