-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/xunittests #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Feat/xunittests #23
Changes from all commits
4112890
3ab54d0
71582cb
1a8b2d3
823303d
194ea0e
28116b4
ad19e4b
f30084a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,33 +5,40 @@ on: | |
| branches: [ "master" ] | ||
| pull_request: | ||
| branches: [ "master" ] | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| build-push-deploy: | ||
| runs-on: "self-hosted" | ||
| steps: | ||
| - | ||
| name: checkout | ||
| - name: Checkout | ||
| uses: actions/checkout@v3 | ||
| - | ||
| name: get tag name | ||
| - name: Get tag name | ||
| run: echo "TAG_ENV=$(date +'%Y-%m-%dT%H%M%S')" >> "$GITHUB_ENV" | ||
| - | ||
| name: build | ||
| run: docker build -f ./Dockerfile -t databaseprojectapi:${{env.TAG_ENV}} . | ||
| - | ||
| name: tag | ||
| - name: Build | ||
| run: docker build -f ./Dockerfile -t databaseprojectapi:${{env.TAG_ENV}} . | ||
| - name: Tag | ||
| run: | | ||
| docker tag databaseprojectapi:${{env.TAG_ENV}} reg.dqcsapp.com/databaseprojectapi:${{env.TAG_ENV}} | ||
| docker tag databaseprojectapi:${{env.TAG_ENV}} reg.dqcsapp.com/databaseprojectapi:latest | ||
| - | ||
| name: push | ||
| - name: Push | ||
| run: | | ||
| docker push reg.dqcsapp.com/databaseprojectapi:${{env.TAG_ENV}} | ||
| docker push reg.dqcsapp.com/databaseprojectapi:latest | ||
| - | ||
| name: deploy kubernetes set image | ||
|
|
||
| approval: | ||
| needs: build-push-deploy | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Awaiting Manual Approval | ||
| run: echo "Waiting for manual approval. Go to GitHub Actions UI and approve the job." | ||
|
|
||
| deploy: | ||
| needs: approval | ||
| runs-on: "self-hosted" | ||
| steps: | ||
| - name: Deploy Kubernetes Set Image | ||
| run: | | ||
| kubectl set image deployments/databaseprojectapi databaseprojectapi=reg.dqcsapp.com/databaseprojectapi:${{env.TAG_ENV}} --kubeconfig=/etc/kube/config | ||
|
||
| - | ||
| name: remove local images | ||
| run : docker rmi -f $(docker images -aq) | ||
| - name: Remove Local Images | ||
| run: docker rmi -f $(docker images -aq) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,91 +1,88 @@ | ||
| using System; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using DatabaseProjectAPI.DataContext; | ||
| using Microsoft.EntityFrameworkCore; | ||
| using Microsoft.Extensions.Logging; | ||
| using DatabaseProjectAPI.DataContext; | ||
|
|
||
| namespace DatabaseProjectAPI.Actions | ||
| namespace DatabaseProjectAPI.Actions; | ||
|
|
||
| public interface IAutoDeleteService | ||
| { | ||
| Task DeleteOldStockHistoryAsync(CancellationToken cancellationToken); | ||
| Task DeleteOldApiCallLogsAsync(CancellationToken cancellationToken); | ||
| } | ||
|
|
||
| public class AutoDeleteAction : IAutoDeleteService | ||
| { | ||
| public interface IAutoDeleteService | ||
| private readonly DpapiDbContext _dbContext; | ||
| private readonly ILogger<AutoDeleteAction> _logger; | ||
|
|
||
| public AutoDeleteAction(DpapiDbContext dbContext, ILogger<AutoDeleteAction> logger) | ||
| { | ||
| Task DeleteOldStockHistoryAsync(CancellationToken cancellationToken); | ||
| Task DeleteOldApiCallLogsAsync(CancellationToken cancellationToken); | ||
| _dbContext = dbContext; | ||
| _logger = logger; | ||
| } | ||
|
|
||
| public class AutoDeleteAction : IAutoDeleteService | ||
| public async Task DeleteOldStockHistoryAsync(CancellationToken cancellationToken) | ||
| { | ||
| private readonly DpapiDbContext _dbContext; | ||
| private readonly ILogger<AutoDeleteAction> _logger; | ||
| var ninetyDaysAgo = DateTime.UtcNow.AddDays(-90); | ||
|
|
||
| public AutoDeleteAction(DpapiDbContext dbContext, ILogger<AutoDeleteAction> logger) | ||
| try | ||
| { | ||
| _dbContext = dbContext; | ||
| _logger = logger; | ||
| } | ||
|
|
||
| var oldHistories = await _dbContext.StockHistories | ||
| .Where(sh => sh.Timestamp < ninetyDaysAgo) | ||
| .ToListAsync(cancellationToken); | ||
|
|
||
| public async Task DeleteOldStockHistoryAsync(CancellationToken cancellationToken) | ||
| { | ||
| var ninetyDaysAgo = DateTime.UtcNow.AddDays(-90); | ||
|
|
||
| try | ||
| { | ||
|
|
||
| int deletedCount = await _dbContext.StockHistories | ||
| .Where(sh => sh.Timestamp < ninetyDaysAgo) | ||
| .ExecuteDeleteAsync(cancellationToken); | ||
|
|
||
| if (deletedCount > 0) | ||
| { | ||
| _logger.LogInformation("{Count} old stock history records deleted.", deletedCount); | ||
| } | ||
| else | ||
| { | ||
| _logger.LogInformation("No stock history records found to delete."); | ||
| } | ||
| } | ||
| catch (OperationCanceledException) | ||
| if (oldHistories.Any()) | ||
| { | ||
| _logger.LogInformation("Deletion of old stock history was cancelled."); | ||
| throw; | ||
| _dbContext.StockHistories.RemoveRange(oldHistories); | ||
| await _dbContext.SaveChangesAsync(cancellationToken); | ||
|
Comment on lines
+29
to
+36
|
||
| _logger.LogInformation("{Count} old stock history records deleted.", oldHistories.Count); | ||
| } | ||
| catch (Exception ex) | ||
| else | ||
| { | ||
| _logger.LogError(ex, "An error occurred while deleting old stock history records."); | ||
| throw; | ||
| _logger.LogInformation("No stock history records found to delete."); | ||
| } | ||
| } | ||
|
|
||
| public async Task DeleteOldApiCallLogsAsync(CancellationToken cancellationToken) | ||
| catch (OperationCanceledException) | ||
| { | ||
| var ninetyDaysAgo = DateTime.UtcNow.AddDays(-90); | ||
| _logger.LogInformation("Deletion of old stock history was cancelled."); | ||
| throw; | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| _logger.LogError(ex, "An error occurred while deleting old stock history records."); | ||
| throw; | ||
| } | ||
| } | ||
|
|
||
| try | ||
| { | ||
| // Use ExecuteDeleteAsync for efficient bulk deletion (EF Core 7.0+) | ||
| int deletedCount = await _dbContext.ApiCallLog | ||
| .Where(log => log.CallDate < ninetyDaysAgo) | ||
| .ExecuteDeleteAsync(cancellationToken); | ||
| public async Task DeleteOldApiCallLogsAsync(CancellationToken cancellationToken) | ||
| { | ||
| var ninetyDaysAgo = DateTime.UtcNow.AddDays(-90); | ||
|
|
||
| if (deletedCount > 0) | ||
| { | ||
| _logger.LogInformation("{Count} old API call log records deleted.", deletedCount); | ||
| } | ||
| else | ||
| { | ||
| _logger.LogInformation("No API call log records found to delete."); | ||
| } | ||
| } | ||
| catch (OperationCanceledException) | ||
| try | ||
| { | ||
| var oldLogs = await _dbContext.ApiCallLog | ||
| .Where(log => log.CallDate < ninetyDaysAgo) | ||
| .ToListAsync(cancellationToken); | ||
|
|
||
| if (oldLogs.Any()) | ||
| { | ||
| _logger.LogInformation("Deletion of old API call logs was cancelled."); | ||
| throw; | ||
| _dbContext.ApiCallLog.RemoveRange(oldLogs); | ||
| await _dbContext.SaveChangesAsync(cancellationToken); | ||
|
Comment on lines
+62
to
+69
|
||
| _logger.LogInformation("{Count} old API call log records deleted.", oldLogs.Count); | ||
| } | ||
| catch (Exception ex) | ||
| else | ||
| { | ||
| _logger.LogError(ex, "An error occurred while deleting old API call log records."); | ||
| throw; | ||
| _logger.LogInformation("No API call log records found to delete."); | ||
| } | ||
| } | ||
| catch (OperationCanceledException) | ||
| { | ||
| _logger.LogInformation("Deletion of old API call logs was cancelled."); | ||
| throw; | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| _logger.LogError(ex, "An error occurred while deleting old API call log records."); | ||
| throw; | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -8,7 +8,14 @@ namespace KubsConnect; | |||||
|
|
||||||
| public class KubsClient : IKubsClient | ||||||
| { | ||||||
| string K8SNameSpace = "default"; | ||||||
| private string K8SNameSpace = "default"; | ||||||
|
||||||
| private string K8SNameSpace = "default"; | |
| private readonly string K8SNameSpace = "default"; |
Copilot
AI
Oct 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected spelling of 'Constrictor' to 'Constructor'.
| /// Constrictor that will only be used when user secrets is available | |
| /// Constructor that will only be used when user secrets is available |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The approval job does not implement actual approval logic. A simple echo statement will not pause the workflow for manual approval. Consider using GitHub's
environmentfeature with protection rules or thetrstringer/manual-approvalaction to implement proper manual approval gates.