|
1 |
| -using System.Reflection; |
2 |
| -using System.Threading.Tasks; |
3 |
| -using Amazon; |
4 |
| -using Amazon.DynamoDBv2; |
5 |
| -using Amazon.Kinesis; |
| 1 | +using System; |
| 2 | +using System.IO; |
6 | 3 | using Microsoft.Extensions.Configuration;
|
7 | 4 | using Serilog;
|
8 |
| -using WorkerService.EventProcessors; |
9 |
| -using KinesisNet; |
10 | 5 | using static System.Threading.Thread;
|
11 | 6 | using static System.Threading.Timeout;
|
12 | 7 |
|
13 | 8 | namespace WorkerService
|
14 | 9 | {
|
15 | 10 | public class Program
|
16 | 11 | {
|
17 |
| - private static Environment environment; |
18 |
| - private static KManager kManager; |
19 | 12 |
|
20 | 13 | public static void Main(string[] args)
|
21 | 14 | {
|
22 |
| - Log.Logger = new LoggerConfiguration() |
23 |
| - .MinimumLevel.Debug() |
24 |
| - .WriteTo.LiterateConsole() |
25 |
| - .CreateLogger(); |
26 |
| - |
27 |
| - Log.Debug("Testing debug logging"); |
| 15 | + var configuration = new ConfigurationBuilder() |
| 16 | + .AddEnvironmentVariables() |
| 17 | + .AddCommandLine(args) |
| 18 | + .SetBasePath(Path.Combine(AppContext.BaseDirectory)) |
| 19 | + .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) |
| 20 | + .Build(); |
28 | 21 |
|
29 |
| - environment = new Environment |
30 |
| - ( |
31 |
| - System.Environment.GetEnvironmentVariable("REGION"), |
32 |
| - System.Environment.GetEnvironmentVariable("DC"), |
33 |
| - System.Environment.GetEnvironmentVariable("ENV"), |
34 |
| - typeof(Program) |
35 |
| - .GetTypeInfo() |
36 |
| - .Assembly |
37 |
| - .GetCustomAttribute<AssemblyInformationalVersionAttribute>() |
38 |
| - .InformationalVersion |
39 |
| - ); |
40 | 22 |
|
41 |
| - Log.Information("{@Environment}", environment); |
| 23 | + var logger = new LoggerConfiguration() |
| 24 | + .ReadFrom.Configuration(configuration) |
| 25 | + .CreateLogger(); |
42 | 26 |
|
43 |
| - Log.Information("Starting configuration"); |
| 27 | + Log.Logger = logger; |
44 | 28 |
|
45 |
| - var configuration = new ConfigurationBuilder() |
46 |
| - .AddEnvironmentVariables() |
47 |
| - .AddCommandLine(args) |
48 |
| - .Build(); |
| 29 | + Console.WriteLine("Hello World"); |
49 | 30 |
|
50 |
| - StartListeningForEvents(); |
51 |
| - |
52 |
| - Log.Information("Going to sleep... zzzzz"); |
53 | 31 | // sleep indefinitely
|
54 | 32 | Sleep(Infinite);
|
55 |
| - |
56 |
| - StopListeningToEvents(); |
57 |
| - } |
58 |
| - |
59 |
| - private static void StopListeningToEvents() |
60 |
| - { |
61 |
| - kManager.Consumer.Stop(); |
62 |
| - } |
63 |
| - |
64 |
| - public static void StartListeningForEvents() |
65 |
| - { |
66 |
| - Log.Debug("Entering StartListeningForEvents"); |
67 |
| - var kinesisStreamName = "RoleStream.LIVE"; |
68 |
| - var kinesisWorkerId = Assembly.GetEntryAssembly().GetName().Name + "-" + environment.Env; |
69 |
| - |
70 |
| - Log.Information("KManager variables:"); |
71 |
| - Log.Information($" StreamName: {kinesisStreamName}"); |
72 |
| - Log.Information($" WorkerId: {kinesisWorkerId}"); |
73 |
| - |
74 |
| - Log.Debug("Creating Dyanmo client"); |
75 |
| - var dynamoClient = new AmazonDynamoDBClient(new AmazonDynamoDBConfig{RegionEndpoint = RegionEndpoint.GetBySystemName(environment.AwsRegion)}); |
76 |
| - Log.Debug("Creating Kinesis client"); |
77 |
| - var kinesisClient = new AmazonKinesisClient(new AmazonKinesisConfig{ RegionEndpoint = RegionEndpoint.GetBySystemName(environment.AwsRegion )}); |
78 |
| - |
79 |
| - Log.Debug("Starting Kmanager"); |
80 |
| - kManager = new KManager(dynamoClient, kinesisClient, kinesisStreamName, kinesisWorkerId); |
81 |
| - |
82 |
| - Log.Debug("Starting consumer"); |
83 |
| - Task.Run(() => kManager.Consumer.Start(new RolesEventProcessor())); |
84 | 33 | }
|
85 | 34 | }
|
86 | 35 | }
|
0 commit comments