forked from branstraub/gzip-release
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
76 lines (66 loc) · 2.29 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Azure;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Auth;
using Microsoft.WindowsAzure.Storage.Blob;
using Microsoft.WindowsAzure.Storage.Queue;
namespace gzip
{
class Program
{
static async Task Main(string[] args)
{
var options = new Options();
options.BlobConnectionStringSource = args[0];
options.BlobConnectionStringDestination = args[1];
options.QueueConnectionString = args[2];
options.QueueName = args[3];
var storageAccountQueue = CloudStorageAccount.Parse(options.QueueConnectionString);
var queueClient = storageAccountQueue.CreateCloudQueueClient();
var queue = queueClient.GetQueueReference(options.QueueName);
//var stopWatch = new Stopwatch();
//stopWatch.Start();
var msg = ".";
//msg = "https://gzipo.blob.core.windows.net/gzipi/2018/april/0/ac583c70-df76-4e02-a70f-7a3d06a0985d.json";
var storageAccountS = CloudStorageAccount.Parse(options.BlobConnectionStringSource);
var storageAccountD = CloudStorageAccount.Parse(options.BlobConnectionStringDestination);
var blobClientS = storageAccountS.CreateCloudBlobClient();
var blobClientD = storageAccountD.CreateCloudBlobClient();
while (msg != "null")
{
try
{
var retrievedMessage = await queue.GetMessageAsync(TimeSpan.FromMinutes(1), null, null);
if (retrievedMessage != null)
{
msg = retrievedMessage.AsString;
}
else
{
msg = "null";
return;
}
var container = msg.Split('/')[3];
var fileName = string.Join("/", msg.Split('/').Skip(4));
var yearAndMonth = fileName.Substring(0, 6);
var blobContainerS = blobClientS.GetContainerReference(container);
var blobContainerD = blobClientD.GetContainerReference(container + yearAndMonth + "compressed");
// Do the compression work
await new Utility().EnsureGzipFiles(blobContainerS, blobContainerD, fileName);
await queue.DeleteMessageAsync(retrievedMessage);
}
catch (Exception)
{
await Task.Delay(60000);
}
}
//stopWatch.Stop();
//var ts = stopWatch.Elapsed;
}
}
}