Last active
December 16, 2015 18:09
-
-
Save robdmoore/5475809 to your computer and use it in GitHub Desktop.
Sample app to test Azure Web Farm background worker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Threading; | |
using AzureToolkit; | |
using Microsoft.WindowsAzure; | |
using Microsoft.WindowsAzure.StorageClient; | |
namespace ConsoleApplication1 | |
{ | |
public class ConsoleResult : TableServiceEntity | |
{ | |
public ConsoleResult(string filePath, string machineName, int consoleVersion, int count, bool continueRunning, bool runForever) | |
{ | |
PartitionKey = machineName + ";" + filePath; | |
RowKey = DateTime.UtcNow.ToString("o"); | |
ConsoleVersion = consoleVersion; | |
Count = count; | |
ContinueRunning = continueRunning; | |
RunForever = runForever; | |
} | |
public int ConsoleVersion { get; set; } | |
public int Count { get; set; } | |
public bool ContinueRunning { get; set; } | |
public bool RunForever { get; set; } | |
} | |
class Program | |
{ | |
static int Main() | |
{ | |
const string connectionString = "AccountName=ZZZ;AccountKey=ZZZ;DefaultEndpointsProtocol=https"; | |
var filePath = Assembly.GetExecutingAssembly().CodeBase.Replace("file:///", "").Replace("/", "_").Replace("\\", "_").Replace(" ", "_").Replace(":", "_"); | |
var storageFactory = new AzureStorageFactory(CloudStorageAccount.Parse(connectionString)); | |
var table = storageFactory.GetTable<ConsoleResult>(typeof(ConsoleResult).Name); | |
table.Initialize(); | |
var random = new Random(); | |
var count = 1; | |
while (count <= 5) | |
{ | |
var continueRunning = random.Next(0, 1000) < 750; | |
var runForever = random.Next(0, 1000) > 900; | |
table.Add(new ConsoleResult(filePath, Environment.MachineName, 1 /* Increment this every deploy to see the app updating */, count, continueRunning, runForever)); | |
if (!continueRunning) | |
return 1; | |
if (runForever) | |
while (true) { Thread.Sleep(TimeSpan.FromSeconds(1)); } | |
count++; | |
} | |
return 0; | |
} | |
} | |
} |
@MattDavies - this has been incredibly useful. I've done some really solid testing on this now and I'm pretty happy it's working great!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
cc @MattDavies