Skip to content

Commit d8f8e94

Browse files
committed
Content Service: health check
1 parent d085fce commit d8f8e94

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

HwProj.APIGateway/HwProj.APIGateway.API/Controllers/SystemController.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Threading.Tasks;
22
using HwProj.APIGateway.API.Models;
33
using HwProj.AuthService.Client;
4+
using HwProj.ContentService.Client;
45
using HwProj.CoursesService.Client;
56
using HwProj.NotificationsService.Client;
67
using HwProj.SolutionsService.Client;
@@ -15,16 +16,19 @@ public class SystemController : AggregationController
1516
private readonly ICoursesServiceClient _coursesServiceClient;
1617
private readonly INotificationsServiceClient _notificationsServiceClient;
1718
private readonly ISolutionsServiceClient _solutionsServiceClient;
19+
private readonly IContentServiceClient _contentServiceClient;
1820

1921
public SystemController(
2022
IAuthServiceClient authServiceClient,
2123
ICoursesServiceClient coursesServiceClient,
2224
INotificationsServiceClient notificationsServiceClient,
23-
ISolutionsServiceClient solutionsServiceClient) : base(authServiceClient)
25+
ISolutionsServiceClient solutionsServiceClient,
26+
IContentServiceClient contentServiceClient) : base(authServiceClient)
2427
{
2528
_coursesServiceClient = coursesServiceClient;
2629
_notificationsServiceClient = notificationsServiceClient;
2730
_solutionsServiceClient = solutionsServiceClient;
31+
_contentServiceClient = contentServiceClient;
2832
}
2933

3034
[HttpGet("status")]
@@ -34,6 +38,7 @@ public async Task<SystemInfo[]> Status()
3438
var coursesPing = _coursesServiceClient.Ping();
3539
var notificationsPing = _notificationsServiceClient.Ping();
3640
var solutionsPing = _solutionsServiceClient.Ping();
41+
var filesPing = _contentServiceClient.Ping();
3742

3843
await Task.WhenAll(authPing, coursesPing, notificationsPing, solutionsPing);
3944

@@ -59,6 +64,11 @@ public async Task<SystemInfo[]> Status()
5964
Service = "Solutions Service",
6065
IsAvailable = solutionsPing.Result
6166
},
67+
new SystemInfo
68+
{
69+
Service = "Content Service",
70+
IsAvailable = filesPing.Result
71+
},
6272
};
6373
}
6474
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
3+
namespace HwProj.ContentService.API.Controllers;
4+
5+
[Route("api/[controller]")]
6+
[ApiController]
7+
public class SystemController : ControllerBase
8+
{
9+
[HttpGet("status")]
10+
public IActionResult Status() => Ok();
11+
}

HwProj.ContentService/HwProj.ContentService.Client/ContentServiceClient.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,5 +167,18 @@ public async Task<Result> TransferFilesFromCourse(CourseFilesTransferDto filesTr
167167
return Result.Failed("Не удалось перенести информацию о файлах — попробуйте повторить позже");
168168
}
169169
}
170+
171+
public async Task<bool> Ping()
172+
{
173+
try
174+
{
175+
await _httpClient.GetAsync(_contentServiceUri + "api/system/ping");
176+
return true;
177+
}
178+
catch
179+
{
180+
return false;
181+
}
182+
}
170183
}
171184
}

HwProj.ContentService/HwProj.ContentService.Client/IContentServiceClient.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ public interface IContentServiceClient
1212
Task<Result<FileInfoDTO[]>> GetFilesInfo(long courseId);
1313
Task<Result<FileInfoDTO[]>> GetUploadedFilesInfo(long courseId);
1414
Task<Result> TransferFilesFromCourse(CourseFilesTransferDto filesTransfer);
15+
Task<bool> Ping();
1516
}
1617
}

0 commit comments

Comments
 (0)