Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.

Commit 82760de

Browse files
authored
Enable direct version publish (#1098)
1 parent 3725565 commit 82760de

File tree

5 files changed

+34
-21
lines changed

5 files changed

+34
-21
lines changed

packages/cli/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,7 @@ OPTIONS
771771
772772
--isStaging Publishes luis application to staging slot if set. Default to production slot
773773
774+
--directVersionPublish [default: false] Available only in direct version query. Do not publish to staging or production
774775
EXAMPLE
775776
776777
$ bf luis:build --in {INPUT_FILE_OR_FOLDER} --authoringKey {AUTHORING_KEY} --botName {BOT_NAME}

packages/lu/src/parser/lubuild/builder.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ export class Builder {
175175
let region = options.region || 'westus'
176176

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

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

200+
// set direct version publish flag
201+
// default to false
202+
let directVersionPublish = options.directVersionPublish || false
203+
200204
// settings assets like app id and version returned from luis api call
201205
let settingsAssets: any[] = []
202206

@@ -253,7 +257,7 @@ export class Builder {
253257

254258
if (needTrainAndPublish) {
255259
// train and publish application
256-
await this.trainAndPublishApplication(luBuildCore, recognizer, timeBucketOfRequests, isStaging)
260+
await this.trainAndPublishApplication(luBuildCore, recognizer, timeBucketOfRequests, isStaging, directVersionPublish)
257261
}
258262

259263
// init settings asset
@@ -421,7 +425,7 @@ export class Builder {
421425
return true
422426
}
423427

424-
async trainAndPublishApplication(luBuildCore: LuBuildCore, recognizer: Recognizer, timeBucket: number, isStaging: boolean) {
428+
async trainAndPublishApplication(luBuildCore: LuBuildCore, recognizer: Recognizer, timeBucket: number, isStaging: boolean, directVersionPublish: boolean) {
425429
// send train application request
426430
this.handler(`${recognizer.getLuPath()} training version=${recognizer.versionId}\n`)
427431
await delay(timeBucket)
@@ -448,7 +452,7 @@ export class Builder {
448452
// publish applications
449453
this.handler(`${recognizer.getLuPath()} publishing version=${recognizer.versionId}\n`)
450454
await delay(timeBucket)
451-
await luBuildCore.publishApplication(recognizer.getAppId(), recognizer.versionId, isStaging)
455+
await luBuildCore.publishApplication(recognizer.getAppId(), recognizer.versionId, isStaging, directVersionPublish)
452456
this.handler(`${recognizer.getLuPath()} publishing finished for ${isStaging ? 'Staging' : 'Production'} slot\n`)
453457
}
454458

packages/lu/src/parser/lubuild/core.ts

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -348,23 +348,26 @@ export class LuBuildCore {
348348
return status
349349
}
350350

351-
public async publishApplication(appId: string, versionId: string, isStaging: boolean) {
351+
public async publishApplication(appId: string, versionId: string, isStaging: boolean, directVersionPublish: boolean) {
352+
let url = this.endpoint + '/luis/authoring/v3.0-preview/apps/' + appId + '/publish'
353+
354+
let messageData
352355
let retryCount = this.retryCount + 1
353-
let error
356+
let error: any
354357
while (retryCount > 0) {
355-
if (error === undefined || error.statusCode === rateLimitErrorCode) {
356-
try {
357-
await this.client.apps.publish(appId,
358-
{
359-
versionId,
360-
isStaging
361-
})
362-
break
363-
} catch (e) {
364-
error = e
365-
retryCount--
366-
if (retryCount > 0) await delay(this.retryDuration)
367-
}
358+
if (error === undefined || error.code === rateLimitErrorCode.toString()) {
359+
let response = await fetch(url, {method: 'POST', headers: this.headers, body: JSON.stringify({
360+
versionId,
361+
isStaging,
362+
directVersionPublish
363+
})})
364+
messageData = await response.json()
365+
366+
if (messageData.error === undefined) break
367+
368+
error = messageData.error
369+
retryCount--
370+
if (retryCount > 0) await delay(this.retryDuration)
368371
} else {
369372
throw error
370373
}
@@ -373,6 +376,8 @@ export class LuBuildCore {
373376
if (retryCount === 0) {
374377
throw error
375378
}
379+
380+
return messageData
376381
}
377382

378383
private updateVersionValue(versionId: string) {

packages/luis/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ OPTIONS
374374
375375
--isStaging Publishes luis application to staging slot if set. Default to production slot
376376
377+
--directVersionPublish [default: false] Available only in direct version query. Do not publish to staging or production
377378
EXAMPLE
378379
379380
$ bf luis:build --in {INPUT_FILE_OR_FOLDER} --authoringKey {AUTHORING_KEY} --botName {BOT_NAME}

packages/luis/src/commands/luis/build.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export default class LuisBuild extends Command {
4141
endpoint: flags.string({description: 'Luis authoring endpoint for publishing'}),
4242
schema: flags.string({description: 'Defines $schema for generated .dialog files'}),
4343
isStaging: flags.boolean({description: 'Publishes luis application to staging slot if set. Default to production slot', default: false}),
44+
directVersionPublish: flags.boolean({description: 'Available only in direct version query. Do not publish to staging or production', default: false})
4445
}
4546

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

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

7475
flags.stdin = await this.readStdin()
@@ -141,7 +142,8 @@ export default class LuisBuild extends Command {
141142
region,
142143
keptVersionCount,
143144
isStaging,
144-
schema
145+
schema,
146+
directVersionPublish
145147
})
146148

147149
// write dialog assets based on config

0 commit comments

Comments
 (0)