Skip to content

Instantly share code, notes, and snippets.

@fabiomaulo
Created October 8, 2017 19:50
Show Gist options
  • Save fabiomaulo/06d38c2315aa0bbf5b595cac63717fa4 to your computer and use it in GitHub Desktop.
Save fabiomaulo/06d38c2315aa0bbf5b595cac63717fa4 to your computer and use it in GitHub Desktop.
WebJobs intensive
public class ContainerBasedJobActivator : IJobActivator
{
private readonly IDepencencyInjectionContainer container;
public ContainerBasedJobActivator(IDepencencyInjectionContainer container)
{
if (container == null) throw new ArgumentNullException(nameof(container));
this.container = container;
}
public T CreateInstance<T>()
{
return (T)container.GetInstance(typeof(T));
}
}
public class TollerantStorageClientFactory : StorageClientFactory
{
private readonly BlobRequestOptions blobRequestOptions;
private readonly QueueRequestOptions queueRequestOptions;
public TollerantStorageClientFactory()
{
blobRequestOptions = new BlobRequestOptions
{
MaximumExecutionTime = TimeSpan.FromMinutes(16),
RetryPolicy = new ExponentialRetry(TimeSpan.FromSeconds(20), 5),
ServerTimeout = TimeSpan.FromMinutes(16),
};
queueRequestOptions = new QueueRequestOptions
{
MaximumExecutionTime = TimeSpan.FromMinutes(4),
RetryPolicy = new ExponentialRetry(TimeSpan.FromSeconds(8), 5),
ServerTimeout = TimeSpan.FromMinutes(4),
};
}
public override CloudBlobClient CreateCloudBlobClient(StorageClientFactoryContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
var client = context.Account.CreateCloudBlobClient();
client.DefaultRequestOptions = blobRequestOptions;
return client;
}
public override CloudQueueClient CreateCloudQueueClient(StorageClientFactoryContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
var client = context.Account.CreateCloudQueueClient();
client.DefaultRequestOptions = queueRequestOptions;
return client;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment