Skip to content

Commit

Permalink
Disable jobs for disabled nodes on restart
Browse files Browse the repository at this point in the history
  • Loading branch information
RodriFS committed Sep 2, 2024
1 parent b63d8cf commit 6328d0c
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/Data/Repositories/Interfaces/INodeRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public interface INodeRepository

Task<List<Node>> GetAllManagedByUser(string userId);

Task<List<Node>> GetAllManagedByNodeGuard();
Task<List<Node>> GetAllManagedByNodeGuard(bool withDisabled = true);

Task<(bool, string?)> AddAsync(Node type);

Expand All @@ -45,4 +45,4 @@ public interface INodeRepository
(bool, string?) RemoveRange(List<Node> types);

(bool, string?) Update(Node type);
}
}
9 changes: 7 additions & 2 deletions src/Data/Repositories/NodeRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public async Task<List<Node>> GetAll()
.ToListAsync();
}

public async Task<List<Node>> GetAllManagedByNodeGuard()
public async Task<List<Node>> GetAllManagedByNodeGuard(bool withDisabled = true)
{
await using var applicationDbContext = await _dbContextFactory.CreateDbContextAsync();

Expand All @@ -119,6 +119,11 @@ public async Task<List<Node>> GetAllManagedByNodeGuard()
.ThenInclude(x => x.Keys)
.Include(x => x.ReturningFundsWallet)
.Where(node => node.Endpoint != null);
if (!withDisabled)
{
query = query.Where(node => !node.IsNodeDisabled);

}

var resultAsync = await query.ToListAsync();

Expand Down Expand Up @@ -182,4 +187,4 @@ public async Task<List<Node>> GetAllManagedByUser(string userId)
return _repository.Update(type, applicationDbContext);
}
}
}
}
4 changes: 2 additions & 2 deletions src/Jobs/ChannelAcceptorJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public async Task Execute(IJobExecutionContext context)
_logger.LogInformation("Starting {JobName}... ", nameof(ChannelAcceptorJob));
try
{
var managedNodes = await _nodeRepository.GetAllManagedByNodeGuard();
var managedNodes = await _nodeRepository.GetAllManagedByNodeGuard(false);

var scheduler = await _schedulerFactory.GetScheduler();
foreach (var managedNode in managedNodes)
Expand All @@ -70,4 +70,4 @@ public async Task Execute(IJobExecutionContext context)

_logger.LogInformation("{JobName} ended", nameof(ChannelAcceptorJob));
}
}
}
4 changes: 2 additions & 2 deletions src/Jobs/MonitorChannelsJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public async Task Execute(IJobExecutionContext context)
_logger.LogInformation("Starting {JobName}... ", nameof(MonitorChannelsJob));
try
{
var managedNodes = await _nodeRepository.GetAllManagedByNodeGuard();
var managedNodes = await _nodeRepository.GetAllManagedByNodeGuard(false);

var scheduler = await _schedulerFactory.GetScheduler();

Expand Down Expand Up @@ -51,4 +51,4 @@ public async Task Execute(IJobExecutionContext context)

_logger.LogInformation("{JobName} ended", nameof(MonitorChannelsJob));
}
}
}
4 changes: 2 additions & 2 deletions src/Jobs/NodeChannelSubscribeJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public async Task Execute(IJobExecutionContext context)
{
_logger.LogError(e, "Error while subscribing for the channel updates of node {NodeId}", nodeId);
//Sleep to avoid massive requests
await Task.Delay(1000);
await Task.Delay(5000);

throw new JobExecutionException(e, true);
}
Expand Down Expand Up @@ -176,4 +176,4 @@ public async Task NodeUpdateManagement(ChannelEventUpdate channelEventUpdate, No
break;
}
}
}
}
4 changes: 2 additions & 2 deletions src/Jobs/NodeSubscriptorJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public async Task Execute(IJobExecutionContext context)
_logger.LogInformation("Starting {JobName}... ", nameof(NodeSubscriptorJob));
try
{
var managedNodes = await _nodeRepository.GetAllManagedByNodeGuard();
var managedNodes = await _nodeRepository.GetAllManagedByNodeGuard(false);

var scheduler = await _schedulerFactory.GetScheduler();

Expand All @@ -48,4 +48,4 @@ public async Task Execute(IJobExecutionContext context)

_logger.LogInformation("{JobName} ended", nameof(NodeSubscriptorJob));
}
}
}
4 changes: 2 additions & 2 deletions src/Jobs/ProcessNodeChannelAcceptorJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,10 @@ await AcceptChannelOpeningRequestWithUpfrontShutdown(_nBXplorerService,
_logger.LogError(e, "Error on {JobName}", nameof(ProcessNodeChannelAcceptorJob));

//Sleep to avoid massive requests
await Task.Delay(1000);
await Task.Delay(5000);

throw new JobExecutionException(e, true);

}
}
}
}
4 changes: 2 additions & 2 deletions src/Jobs/SweepAllNodesWalletsJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public async Task Execute(IJobExecutionContext context)
_logger.LogInformation("Starting {JobName}... ", nameof(SweepAllNodesWalletsJob));
try
{
var managedNodes = await _nodeRepository.GetAllManagedByNodeGuard();
var managedNodes = await _nodeRepository.GetAllManagedByNodeGuard(false);

var scheduler = await _schedulerFactory.GetScheduler();
foreach (var managedNode in managedNodes.Where(managedNode => managedNode.ChannelAdminMacaroon != null && managedNode.AutosweepEnabled))
Expand All @@ -72,4 +72,4 @@ public async Task Execute(IJobExecutionContext context)
_logger.LogInformation("{JobName} ended", nameof(SweepAllNodesWalletsJob));
}
}
}
}

0 comments on commit 6328d0c

Please sign in to comment.