From 895ec3f2d018039c2f7f1015cd4b16a428defa75 Mon Sep 17 00:00:00 2001 From: John CavnarJohnson Date: Thu, 21 Jul 2016 09:49:12 -0500 Subject: [PATCH] Added the ability to optionally specify the visibility timeout when dequeuing a message from an Azure Storage Queue The existing Dequeue member of the ProvidedQueue type gains an additional optional Timespan parameter. I also added an overload that accepts a TimeSpan and uses the default connection string. The net effect is to allow the user to call Dequeue in the following ways: Dequeue() -> Dequeue(?connectionString, ?visibilityTimeout) Dequeue("some connection string") -> Dequeue(?connectionString, ?visibilityTimeout) Dequeue("some connection string", TimeSpan.FromMinutes(1..0) -> Dequeue(?connectionString, ?visibilityTimeout) Dequeue(TimeSpan.FromMinutes(1.0) -> Dequeue(visibilityTimeout) --- .../Queue/ProvidedQueueTypes.fs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/FSharp.Azure.StorageTypeProvider/Queue/ProvidedQueueTypes.fs b/src/FSharp.Azure.StorageTypeProvider/Queue/ProvidedQueueTypes.fs index 5c5a52b..41e6e27 100644 --- a/src/FSharp.Azure.StorageTypeProvider/Queue/ProvidedQueueTypes.fs +++ b/src/FSharp.Azure.StorageTypeProvider/Queue/ProvidedQueueTypes.fs @@ -72,16 +72,26 @@ type ProvidedQueue(defaultConnectionString, name) = if queueRef.ApproximateMessageCount.HasValue then queueRef.ApproximateMessageCount.Value else 0 - /// Dequeues the next message. - member __.Dequeue(?connectionString) = + /// Dequeues the next message and optionally sets the visibilityTimeout (i.e. how long you can work with the message before it reappears in the queue) + member __.Dequeue(?connectionString, ?visibilityTimeout) = async { - let! message = (getQueue connectionString).GetMessageAsync() |> Async.AwaitTask + let! message = (getQueue connectionString).GetMessageAsync(visibilityTimeout |> Option.toNullable, null, null) |> Async.AwaitTask return match message with | null -> None | _ -> Some(message |> Factory.toProvidedQueueMessage) } - + + /// Dequeues the next message using the default connection string and sets the visibilityTimeout (i.e. how long you can work with the message before it reappears in the queue) + member __.Dequeue(visibilityTimeout) = + async { + let! message = (getQueueRef name defaultConnectionString).GetMessageAsync(visibilityTimeout |> Nullable , null, null) |> Async.AwaitTask + return + match message with + | null -> None + | _ -> Some(message |> Factory.toProvidedQueueMessage) + } + /// Generates a full-access shared access signature, defaulting to start from now. member __.GenerateSharedAccessSignature(duration, ?start, ?connectionString) = getQueue connectionString |> generateSas start duration