|
1 | 1 | using Hangfire; |
2 | 2 | using Hangfire.Dashboard; |
3 | | -using Hangfire.Redis; |
| 3 | +using Hangfire.Redis.StackExchange; |
4 | 4 |
|
5 | | -var configuration = GlobalConfiguration.Configuration; |
6 | | -configuration.UseRedisStorage("10.99.59.47:7000,DefaultDatabase=7,allowAdmin=true"); |
7 | | -configuration.UseColouredConsoleLogProvider(); |
8 | | -//todo: add a mini web dashboard? |
9 | | -foreach (var metric in DashboardMetrics.GetMetrics()) |
| 5 | +namespace HangfireTest.Server; |
| 6 | + |
| 7 | +internal static class Program |
10 | 8 | { |
11 | | - configuration.UseDashboardMetric(metric); |
12 | | -} |
13 | | -configuration.UseDashboardMetric( |
14 | | - RedisStorage.GetDashboardMetricFromRedisInfo("使用内存", RedisInfoKeys.used_memory_human)); |
15 | | -configuration.UseDashboardMetric( |
16 | | - RedisStorage.GetDashboardMetricFromRedisInfo("高峰内存", RedisInfoKeys.used_memory_peak_human)); |
17 | 9 |
|
18 | | -BackgroundJob.Enqueue(() => Console.WriteLine("Hello, world!")); |
| 10 | + #region Constants & Statics |
| 11 | + |
| 12 | + private static void Main(string[] args) |
| 13 | + { |
| 14 | + var configuration = GlobalConfiguration.Configuration; |
| 15 | + _ = configuration.UseRedisStorage("127.0.0.1:6379,DefaultDatabase=7,allowAdmin=true"); |
| 16 | + _ = configuration.UseColouredConsoleLogProvider(); |
| 17 | + //todo: add a mini web dashboard? |
| 18 | + foreach (var metric in DashboardMetrics.GetMetrics()) |
| 19 | + { |
| 20 | + _ = configuration.UseDashboardMetric(metric); |
| 21 | + } |
| 22 | + _ = configuration.UseDashboardMetric( |
| 23 | + RedisStorage.GetDashboardMetricFromRedisInfo("使用内存", RedisInfoKeys.used_memory_human)); |
| 24 | + _ = configuration.UseDashboardMetric( |
| 25 | + RedisStorage.GetDashboardMetricFromRedisInfo("高峰内存", RedisInfoKeys.used_memory_peak_human)); |
| 26 | + |
| 27 | + _ = BackgroundJob.Enqueue(() => Console.WriteLine("Hello, world!")); |
| 28 | + |
| 29 | + var jobServerOptions = |
| 30 | + new BackgroundJobServerOptions { ServerName = "HangfireTest.Web", Queues = new[] { "default", "console" } }; |
| 31 | + using var server = new BackgroundJobServer(jobServerOptions); |
| 32 | + |
| 33 | + Console.WriteLine("Hangfire Server started. Press any key to exit..."); |
| 34 | + _ = Console.ReadKey(); |
| 35 | + } |
| 36 | + |
| 37 | + #endregion |
19 | 38 |
|
20 | | -var jobServerOptions = |
21 | | - new BackgroundJobServerOptions { ServerName = "HangfireTest.Web", Queues = new[] { "default", "console" } }; |
22 | | -using (var server = new BackgroundJobServer(jobServerOptions)) |
23 | | -{ |
24 | | - Console.WriteLine("Hangfire Server started. Press any key to exit..."); |
25 | | - Console.ReadKey(); |
26 | 39 | } |
0 commit comments