Skip to content

Commit

Permalink
Added the ability to optionally specify the visibility timeout when d…
Browse files Browse the repository at this point in the history
…equeuing 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)
  • Loading branch information
johnc-j committed Jul 21, 2016
1 parent aeb7925 commit 895ec3f
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/FSharp.Azure.StorageTypeProvider/Queue/ProvidedQueueTypes.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 895ec3f

Please sign in to comment.