-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upgrade Azure Storage SDK to a modern version #629
base: master
Are you sure you want to change the base?
Changes from 1 commit
dfaad75
a256c9e
ec2b539
e93f5a0
4078515
cf48366
3c54c27
9ed70ef
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 |
---|---|---|
|
@@ -2,14 +2,31 @@ | |
// SPDX-License-Identifier: MIT | ||
|
||
const AttenuatedQueue = require('./attenuatedQueue') | ||
const AzureStorage = require('azure-storage') | ||
const { QueueServiceClient } = require('@azure/storage-queue') | ||
const Request = require('../../lib/request') | ||
const StorageQueue = require('./storageQueue') | ||
const { DefaultAzureCredential } = require('@azure/identity') | ||
|
||
class StorageQueueManager { | ||
constructor(connectionString) { | ||
const retryOperations = new AzureStorage.ExponentialRetryPolicyFilter() | ||
this.client = AzureStorage.createQueueService(connectionString).withFilter(retryOperations) | ||
constructor(connectionString, options) { | ||
const pipelineOptions = { | ||
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 like the use of |
||
retryOptions: { | ||
maxTries: 3, | ||
retryDelayInMs: 1000, | ||
maxRetryDelayInMs: 120 * 1000, | ||
tryTimeoutInMs: 30000, | ||
retryPolicyType: StorageRetryPolicyType.EXPONENTIAL | ||
} | ||
} | ||
if (connectionString) { | ||
this.client = QueueServiceClient.fromConnectionString(connectionString, pipelineOptions) | ||
} else { | ||
this.client = new QueueServiceClient( | ||
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. This is a nice update here for maintaining the old approach and setting up a more flexible long term approach. |
||
`https://${options.account}.queue.core.windows.net`, | ||
new DefaultAzureCredential(), | ||
pipelineOptions | ||
) | ||
} | ||
} | ||
|
||
createQueueClient(name, formatter, options) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,44 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
const AzureStorage = require('azure-storage') | ||
// @ts-check | ||
const { BlobServiceClient, StorageRetryPolicyType } = require('@azure/storage-blob') | ||
const AzureStorageDocStore = require('./storageDocStore') | ||
const { DefaultAzureCredential } = require ('@azure/identity'); | ||
|
||
/** | ||
* @param {object} options | ||
* @param {string} options.account | ||
* @param {string} options.connection | ||
* @param {string} options.container | ||
* @param {object} options.logger | ||
*/ | ||
module.exports = options => { | ||
options.logger.info('creating azure storage store') | ||
const { account, key, connection, container } = options | ||
const retryOperations = new AzureStorage.ExponentialRetryPolicyFilter() | ||
const blobService = connection | ||
? AzureStorage.createBlobService(connection).withFilter(retryOperations) | ||
: AzureStorage.createBlobService(account, key).withFilter(retryOperations) | ||
return new AzureStorageDocStore(blobService, container, options) | ||
const { account, connection, container } = options | ||
|
||
const pipelineOptions = { | ||
retryOptions: { | ||
maxTries: 3, | ||
retryDelayInMs: 1000, | ||
maxRetryDelayInMs: 120 * 1000, | ||
tryTimeoutInMs: 30000, | ||
retryPolicyType: StorageRetryPolicyType.EXPONENTIAL | ||
} | ||
} | ||
|
||
let blobServiceClient | ||
if (connection) { | ||
options.logger.info('using connection string') | ||
blobServiceClient = BlobServiceClient.fromConnectionString(connection, pipelineOptions) | ||
} else if (account) { | ||
options.logger.info('using default credentials') | ||
blobServiceClient = new BlobServiceClient(`https://${account}.blob.core.windows.net`, new DefaultAzureCredential(), pipelineOptions) | ||
} else { | ||
throw new Error('either connection or account must be provided') | ||
} | ||
|
||
const containerClient = blobServiceClient.getContainerClient(container) | ||
|
||
return new AzureStorageDocStore(containerClient, options) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This likely applies in other places as well. In the original code, error handling logged the error. In the new code, it appears that error handling depends on how
await
handles exceptions instead of usingtry
andcatch
blocks to log the error in the same way as the original.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah it's a good point. There was one more place like this, I've updated it as well.