-
Notifications
You must be signed in to change notification settings - Fork 487
Refactor of Microsoft.Bot.Builder.Azure.Queues. #4692
Changes from 3 commits
cd143b8
5bad8d6
7e9f010
b349eeb
47a640e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,10 +6,9 @@ | |
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using AdaptiveExpressions.Properties; | ||
| using Microsoft.Bot.Builder.Dialogs; | ||
| using Newtonsoft.Json; | ||
|
|
||
| namespace Microsoft.Bot.Builder.Azure.Queues | ||
| namespace Microsoft.Bot.Builder.Dialogs.Adaptive.Actions | ||
| { | ||
| /// <summary> | ||
| /// Action which schedules a conversation to be continued later by writing a EventActivity(Name=ContinueConversation) to a Azure Storage queue. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
an #Resolved |
||
|
|
@@ -32,7 +31,7 @@ public class ContinueConversationLater : Dialog | |
| /// The Kind name for this dialog. | ||
| /// </summary> | ||
| [JsonProperty("$kind")] | ||
| public const string Kind = "AzureQueues.ContinueConversationLater"; | ||
| public const string Kind = "Microsoft.ContinueConversationLater"; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if we still do this, but I think we need to update test.schema with the new name (I don't know if test.schema gets regenerated on the build server but the copy in source control has the old name)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean the schema in libraries/Microsoft.Bot.Builder.Dialogs.Adaptive/Schemas/Actions? If so, that change is included in this PR. I have not found any other references in the source. Please let me know. In reply to: 501018849 [](ancestors = 501018849)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I searched on my local copy of schema.tests and I see a reference to the old name, I do see it too on your branch here, here and in a couple of other places. It seems that tests.schema gets regenerated by the unit tests so I am not sure if this is relevant or not (if tests.schema is regenerated every time we may want to added to the gitignore, would this be the case @chrimc62?) |
||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="ContinueConversationLater"/> class. | ||
|
|
@@ -74,23 +73,6 @@ public ContinueConversationLater([CallerFilePath] string callerPath = "", [Calle | |
| [JsonProperty("value")] | ||
| public ValueExpression Value { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the connectionString for the azure storage queue to use. | ||
| /// </summary> | ||
| /// <value> | ||
| /// The connectionString for the azure storage queue to use. | ||
| /// </value> | ||
| /// <example>'=settings.ConnectionString'.</example> | ||
| [JsonProperty("connectionString")] | ||
| public StringExpression ConnectionString { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the name of the queue to use. | ||
| /// </summary> | ||
| /// <value>default is 'activities'.</value> | ||
| [JsonProperty("queueName")] | ||
| public StringExpression QueueName { get; set; } = "activities"; | ||
|
|
||
| /// <inheritdoc/> | ||
| public override async Task<DialogTurnResult> BeginDialogAsync(DialogContext dc, object options = null, CancellationToken cancellationToken = default(CancellationToken)) | ||
| { | ||
|
|
@@ -105,12 +87,11 @@ public ContinueConversationLater([CallerFilePath] string callerPath = "", [Calle | |
| } | ||
|
|
||
| var dateString = Date.GetValue(dc.State); | ||
| DateTime date; | ||
| if (!DateTime.TryParse(dateString, out date)) | ||
| if (!DateTime.TryParse(dateString, out var date)) | ||
| { | ||
| throw new ArgumentException($"{nameof(Date)} is invalid"); | ||
| } | ||
|
|
||
| date = date.ToUniversalTime(); | ||
| if (date <= DateTime.UtcNow) | ||
| { | ||
|
|
@@ -124,10 +105,7 @@ public ContinueConversationLater([CallerFilePath] string callerPath = "", [Calle | |
| var visibility = date - DateTime.UtcNow; | ||
| var ttl = visibility + TimeSpan.FromMinutes(2); | ||
|
|
||
| var queueName = QueueName.GetValue(dc.State); | ||
| var connectionString = ConnectionString.GetValue(dc.State); | ||
|
|
||
| var queueStorage = new QueuesStorage(connectionString, queueName); | ||
| var queueStorage = dc.Context.TurnState.Get<QueueStorage>() ?? throw new NullReferenceException("Unable to locate QueueStorage in HostContext"); | ||
| var receipt = await queueStorage.QueueActivityAsync(activity, visibility, ttl, cancellationToken).ConfigureAwait(false); | ||
|
|
||
| // return the receipt as the result. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,23 +30,6 @@ | |
| "=addHours(utcNow(), 1)" | ||
| ] | ||
| }, | ||
| "connectionString": { | ||
| "$ref": "schema:#/definitions/stringExpression", | ||
| "title": "Connection String", | ||
| "description": "Connection string for connecting to an Azure Storage account.", | ||
| "examples": [ | ||
| "=settings.connectionString" | ||
| ] | ||
| }, | ||
| "queueName": { | ||
| "$ref": "schema:#/definitions/stringExpression", | ||
| "title": "Queue Name", | ||
| "description": "Name of the queue that your azure function is bound to.", | ||
| "examples": [ | ||
| "activities" | ||
| ], | ||
| "default": "activities" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like the class was changed to match the schema name is good, but if we have shipped this it is a breaking change. Have we shipped it? #Resolved
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It shipped as a preview, so we should be safe to change it. In reply to: 501232641 [](ancestors = 501232641) |
||
| }, | ||
| "value": { | ||
| "$ref": "schema:#/definitions/valueExpression", | ||
| "title": "Value", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| using System; | ||
|
gabog marked this conversation as resolved.
Outdated
|
||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.Bot.Schema; | ||
|
|
||
| namespace Microsoft.Bot.Builder | ||
| { | ||
| /// <summary> | ||
| /// A base class for enqueueing an Activity for later processing. | ||
| /// </summary> | ||
| public abstract class QueueStorage | ||
| { | ||
| /// <summary> | ||
| /// Enqueues an Activity for later processing. The visibility timeout specifies how long the message should be invisible | ||
| /// to Dequeue and Peek operations. The message content must be a UTF-8 encoded string that is up to 64KB in size. | ||
| /// </summary> | ||
| /// <param name="activity">The <see cref="Activity"/> to be queued for later processing.</param> | ||
| /// <param name="visibilityTimeout"> Visibility timeout. Optional with a default value of 0. Cannot be larger than 7 days. </param> | ||
| /// <param name="timeToLive">Specifies the time-to-live interval for the message.</param> | ||
| /// <param name="cancellationToken">Cancellation token for the async operation.</param> | ||
| /// <returns>A result string.</returns> | ||
| public abstract Task<string> QueueActivityAsync(Activity activity, TimeSpan? visibilityTimeout = null, TimeSpan? timeToLive = null, CancellationToken cancellationToken = default); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ | |
| using Microsoft.Bot.Builder.Adapters; | ||
| using Microsoft.Bot.Builder.Azure.Queues; | ||
| using Microsoft.Bot.Builder.Dialogs; | ||
| using Microsoft.Bot.Builder.Dialogs.Adaptive.Actions; | ||
| using Microsoft.Bot.Builder.Tests; | ||
| using Microsoft.Bot.Schema; | ||
| using Newtonsoft.Json; | ||
|
|
@@ -40,13 +41,15 @@ public async Task ContinueConversationLaterTests() | |
| .UseStorage(new MemoryStorage()) | ||
| .UseBotState(new ConversationState(new MemoryStorage()), new UserState(new MemoryStorage())); | ||
|
|
||
| var queueStorage = new AzureQueueStorage(ConnectionString, queueName); | ||
| var dm = new DialogManager(new ContinueConversationLater() | ||
| { | ||
| ConnectionString = ConnectionString, | ||
| QueueName = queueName, | ||
| Date = "=addSeconds(utcNow(), 2)", | ||
| Value = "foo" | ||
| }); | ||
|
|
||
| dm.InitialTurnState.Set<QueueStorage>(queueStorage); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are there any samples which did this in the old way? Do we need a sample? #Resolved
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are no samples to update with this change. We do have a plan to add this to a sample later. In reply to: 501233216 [](ancestors = 501233216) |
||
|
|
||
| await new TestFlow((TestAdapter)adapter, dm.OnTurnAsync) | ||
| .Send("hi") | ||
| .StartTestAsync(); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.