Skip to content

Commit

Permalink
Enable direct version publish (#1098)
Browse files Browse the repository at this point in the history
  • Loading branch information
feich-ms committed Jan 28, 2021
1 parent 3725565 commit 82760de
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 21 deletions.
1 change: 1 addition & 0 deletions packages/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,7 @@ OPTIONS
--isStaging Publishes luis application to staging slot if set. Default to production slot
--directVersionPublish [default: false] Available only in direct version query. Do not publish to staging or production
EXAMPLE
$ bf luis:build --in {INPUT_FILE_OR_FOLDER} --authoringKey {AUTHORING_KEY} --botName {BOT_NAME}
Expand Down
12 changes: 8 additions & 4 deletions packages/lu/src/parser/lubuild/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export class Builder {
let region = options.region || 'westus'

// set kept version count which means how many versions would be kept in luis service
let keptVersionCount = options.keptVersionCount && options.keptVersionCount > 0 ? options.keptVersionCount : maxVersionCount
let keptVersionCount = options.keptVersionCount && options.keptVersionCount > 0 && options.keptVersionCount <= maxVersionCount ? options.keptVersionCount : maxVersionCount

// set if publish this application to staging or production slot
// default to production
Expand All @@ -197,6 +197,10 @@ export class Builder {
// set retry duration for rate limit luis API failure
let retryDuration = options.retryDuration || 1000

// set direct version publish flag
// default to false
let directVersionPublish = options.directVersionPublish || false

// settings assets like app id and version returned from luis api call
let settingsAssets: any[] = []

Expand Down Expand Up @@ -253,7 +257,7 @@ export class Builder {

if (needTrainAndPublish) {
// train and publish application
await this.trainAndPublishApplication(luBuildCore, recognizer, timeBucketOfRequests, isStaging)
await this.trainAndPublishApplication(luBuildCore, recognizer, timeBucketOfRequests, isStaging, directVersionPublish)
}

// init settings asset
Expand Down Expand Up @@ -421,7 +425,7 @@ export class Builder {
return true
}

async trainAndPublishApplication(luBuildCore: LuBuildCore, recognizer: Recognizer, timeBucket: number, isStaging: boolean) {
async trainAndPublishApplication(luBuildCore: LuBuildCore, recognizer: Recognizer, timeBucket: number, isStaging: boolean, directVersionPublish: boolean) {
// send train application request
this.handler(`${recognizer.getLuPath()} training version=${recognizer.versionId}\n`)
await delay(timeBucket)
Expand All @@ -448,7 +452,7 @@ export class Builder {
// publish applications
this.handler(`${recognizer.getLuPath()} publishing version=${recognizer.versionId}\n`)
await delay(timeBucket)
await luBuildCore.publishApplication(recognizer.getAppId(), recognizer.versionId, isStaging)
await luBuildCore.publishApplication(recognizer.getAppId(), recognizer.versionId, isStaging, directVersionPublish)
this.handler(`${recognizer.getLuPath()} publishing finished for ${isStaging ? 'Staging' : 'Production'} slot\n`)
}

Expand Down
35 changes: 20 additions & 15 deletions packages/lu/src/parser/lubuild/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,23 +348,26 @@ export class LuBuildCore {
return status
}

public async publishApplication(appId: string, versionId: string, isStaging: boolean) {
public async publishApplication(appId: string, versionId: string, isStaging: boolean, directVersionPublish: boolean) {
let url = this.endpoint + '/luis/authoring/v3.0-preview/apps/' + appId + '/publish'

let messageData
let retryCount = this.retryCount + 1
let error
let error: any
while (retryCount > 0) {
if (error === undefined || error.statusCode === rateLimitErrorCode) {
try {
await this.client.apps.publish(appId,
{
versionId,
isStaging
})
break
} catch (e) {
error = e
retryCount--
if (retryCount > 0) await delay(this.retryDuration)
}
if (error === undefined || error.code === rateLimitErrorCode.toString()) {
let response = await fetch(url, {method: 'POST', headers: this.headers, body: JSON.stringify({
versionId,
isStaging,
directVersionPublish
})})
messageData = await response.json()

if (messageData.error === undefined) break

error = messageData.error
retryCount--
if (retryCount > 0) await delay(this.retryDuration)
} else {
throw error
}
Expand All @@ -373,6 +376,8 @@ export class LuBuildCore {
if (retryCount === 0) {
throw error
}

return messageData
}

private updateVersionValue(versionId: string) {
Expand Down
1 change: 1 addition & 0 deletions packages/luis/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ OPTIONS
--isStaging Publishes luis application to staging slot if set. Default to production slot
--directVersionPublish [default: false] Available only in direct version query. Do not publish to staging or production
EXAMPLE
$ bf luis:build --in {INPUT_FILE_OR_FOLDER} --authoringKey {AUTHORING_KEY} --botName {BOT_NAME}
Expand Down
6 changes: 4 additions & 2 deletions packages/luis/src/commands/luis/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export default class LuisBuild extends Command {
endpoint: flags.string({description: 'Luis authoring endpoint for publishing'}),
schema: flags.string({description: 'Defines $schema for generated .dialog files'}),
isStaging: flags.boolean({description: 'Publishes luis application to staging slot if set. Default to production slot', default: false}),
directVersionPublish: flags.boolean({description: 'Available only in direct version query. Do not publish to staging or production', default: false})
}

async run() {
Expand Down Expand Up @@ -68,7 +69,7 @@ export default class LuisBuild extends Command {
// Flags override userConfig
let luisBuildFlags = Object.keys(LuisBuild.flags)

let {inVal, authoringKey, botName, region, out, defaultCulture, fallbackLocale, suffix, dialog, force, luConfig, deleteOldVersion, log, endpoint, schema, isStaging}
let {inVal, authoringKey, botName, region, out, defaultCulture, fallbackLocale, suffix, dialog, force, luConfig, deleteOldVersion, log, endpoint, schema, isStaging, directVersionPublish}
= await utils.processInputs(flags, luisBuildFlags, this.config.configDir)

flags.stdin = await this.readStdin()
Expand Down Expand Up @@ -141,7 +142,8 @@ export default class LuisBuild extends Command {
region,
keptVersionCount,
isStaging,
schema
schema,
directVersionPublish
})

// write dialog assets based on config
Expand Down

0 comments on commit 82760de

Please sign in to comment.