Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion SW.Bitween.Api/Resources/ApiGateways/AddPartner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ public class AddPartner : ICommandHandler<int, ApiGatewayPartnerCreate, object>
private readonly BitweenDbContext _dbContext;
private readonly RequestContext _requestContext;
private readonly AdapterRequirements _adapterRequirements;
private readonly IInfolinkCache _cache;

public AddPartner(BitweenDbContext dbContext, RequestContext requestContext,
AdapterRequirements adapterRequirements)
AdapterRequirements adapterRequirements, IInfolinkCache cache)
{
_dbContext = dbContext;
_requestContext = requestContext;
_adapterRequirements = adapterRequirements;
_cache = cache;
}

public async Task<object> Handle(int gatewayId, ApiGatewayPartnerCreate model)
Expand Down Expand Up @@ -81,6 +83,9 @@ public async Task<object> Handle(int gatewayId, ApiGatewayPartnerCreate model)

_dbContext.Add(partnerLink);
await _dbContext.SaveChangesAsync();
// Attaching an existing integration changes nothing the cache holds, but staging a new
// one above creates a Subscription — and unconditional is what AddRoute does.
await _cache.BroadcastRevoke();

return null;
}
Expand Down
8 changes: 7 additions & 1 deletion SW.Bitween.Api/Resources/Documents/Create.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ public class Create : ICommandHandler<DocumentCreate,object>
private readonly BitweenDbContext _dbContext;
private readonly RequestContext _requestContext;
private readonly IBroadcast _broadcast;
private readonly IInfolinkCache _cache;

public Create(BitweenDbContext dbContext, RequestContext requestContext, IBroadcast broadcast)
public Create(BitweenDbContext dbContext, RequestContext requestContext, IBroadcast broadcast,
IInfolinkCache cache)
{
_dbContext = dbContext;
_requestContext = requestContext;
_broadcast = broadcast;
_cache = cache;
}

public async Task<object> Handle(DocumentCreate model)
Expand Down Expand Up @@ -78,6 +81,9 @@ public async Task<object> Handle(DocumentCreate model)
_dbContext.Add(trail);
_dbContext.Add(entity);
await _dbContext.SaveChangesAsync();
// Routing resolves an information type by name off the cache, so a new one is
// invisible to it until this lands.
await _cache.BroadcastRevoke();

// A bus-enabled type adds a queue, and the consumer set is only rebuilt when asked.
// Without this the queue is declared but nothing ever consumes it, until either an
Expand Down
5 changes: 4 additions & 1 deletion SW.Bitween.Api/Resources/Documents/Delete.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,21 @@ public class Delete : IDeleteHandler<int,object>
{
private readonly BitweenDbContext _dbContext;
private readonly RequestContext _requestContext;
private readonly IInfolinkCache _cache;

public Delete(BitweenDbContext dbContext, RequestContext requestContext)
public Delete(BitweenDbContext dbContext, RequestContext requestContext, IInfolinkCache cache)
{
_dbContext = dbContext;
_requestContext = requestContext;
_cache = cache;
}

async public Task<object> Handle(int key)
{
await _requestContext.EnsurePermission(_dbContext, Model.Permissions.Documents.Delete);

await _dbContext.DeleteByKeyAsync<Document>(key);
await _cache.BroadcastRevoke();
return null;
}
}
Expand Down
2 changes: 1 addition & 1 deletion SW.Bitween.Api/Resources/Documents/Update.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public async Task<object> Handle(int key, DocumentUpdate model)
trail.SetAfter(entity);
_dbContext.Add(trail);
await _dbContext.SaveChangesAsync();
_BitweenCache.BroadcastRevoke();
await _BitweenCache.BroadcastRevoke();
await _broadcast.RefreshConsumers();
return null;
}
Expand Down
5 changes: 4 additions & 1 deletion SW.Bitween.Api/Resources/GlobalAdapterValuesSets/Create.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ public class Create : ICommandHandler<GlobalAdapterValuesSetCreate, object>
{
private readonly BitweenDbContext _dbContext;
private readonly RequestContext _requestContext;
private readonly IInfolinkCache _cache;

public Create(BitweenDbContext dbContext, RequestContext requestContext)
public Create(BitweenDbContext dbContext, RequestContext requestContext, IInfolinkCache cache)
{
_dbContext = dbContext;
_requestContext = requestContext;
_cache = cache;
}

public async Task<object> Handle(GlobalAdapterValuesSetCreate request)
Expand All @@ -35,6 +37,7 @@ public async Task<object> Handle(GlobalAdapterValuesSetCreate request)

_dbContext.Add(entity);
await _dbContext.SaveChangesAsync();
await _cache.BroadcastRevoke();
return new
{
entity.Id
Expand Down
5 changes: 4 additions & 1 deletion SW.Bitween.Api/Resources/GlobalAdapterValuesSets/Delete.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ public class Delete : ICommandHandler<string, DeleteGlobalAdapterValuesSetModel,
{
private readonly BitweenDbContext _dbContext;
private readonly RequestContext _requestContext;
private readonly IInfolinkCache _cache;

public Delete(BitweenDbContext dbContext, RequestContext requestContext)
public Delete(BitweenDbContext dbContext, RequestContext requestContext, IInfolinkCache cache)
{
_dbContext = dbContext;
_requestContext = requestContext;
_cache = cache;
}

public async Task<object> Handle(string key, DeleteGlobalAdapterValuesSetModel _)
Expand All @@ -27,6 +29,7 @@ public async Task<object> Handle(string key, DeleteGlobalAdapterValuesSetModel _

_dbContext.Remove(entity);
await _dbContext.SaveChangesAsync();
await _cache.BroadcastRevoke();
return null;
}
}
Expand Down
5 changes: 4 additions & 1 deletion SW.Bitween.Api/Resources/GlobalAdapterValuesSets/Update.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ public class Update : ICommandHandler<string, GlobalAdapterValuesSetUpdate, obje
{
private readonly BitweenDbContext _dbContext;
private readonly RequestContext _requestContext;
private readonly IInfolinkCache _cache;

public Update(BitweenDbContext dbContext, RequestContext requestContext)
public Update(BitweenDbContext dbContext, RequestContext requestContext, IInfolinkCache cache)
{
_dbContext = dbContext;
_requestContext = requestContext;
_cache = cache;
}

public async Task<object> Handle(string key, GlobalAdapterValuesSetUpdate request)
Expand All @@ -29,6 +31,7 @@ public async Task<object> Handle(string key, GlobalAdapterValuesSetUpdate reques
entity.Values = request.Values;

await _dbContext.SaveChangesAsync();
await _cache.BroadcastRevoke();
return null;
}

Expand Down
5 changes: 4 additions & 1 deletion SW.Bitween.Api/Resources/Notifiers/Create.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ public class Create : ICommandHandler<NotifierCreate,object>
{
private readonly BitweenDbContext _dbContext;
private readonly RequestContext _requestContext;
private readonly IInfolinkCache _cache;

public Create(BitweenDbContext dbContext, RequestContext requestContext)
public Create(BitweenDbContext dbContext, RequestContext requestContext, IInfolinkCache cache)
{
this._dbContext = dbContext;
_requestContext = requestContext;
_cache = cache;
}

public async Task<object> Handle(NotifierCreate request)
Expand All @@ -25,6 +27,7 @@ public async Task<object> Handle(NotifierCreate request)

_dbContext.Add(notifier);
await _dbContext.SaveChangesAsync();
await _cache.BroadcastRevoke();
return notifier.Id;
}

Expand Down
5 changes: 4 additions & 1 deletion SW.Bitween.Api/Resources/Notifiers/Delete.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ public class Delete : IDeleteHandler<int,object>
{
private readonly BitweenDbContext _dbContext;
private readonly RequestContext _requestContext;
private readonly IInfolinkCache _cache;

public Delete(BitweenDbContext dbContext, RequestContext requestContext)
public Delete(BitweenDbContext dbContext, RequestContext requestContext, IInfolinkCache cache)
{
_dbContext = dbContext;
_requestContext = requestContext;
_cache = cache;
}

/// <remarks>
Expand All @@ -26,6 +28,7 @@ public async Task<object> Handle(int key)
await _requestContext.EnsurePermission(_dbContext, Model.Permissions.Notifiers.Delete);

await _dbContext.DeleteByKeyAsync<Notifier>(key);
await _cache.BroadcastRevoke();
return null;
}
}
Expand Down
5 changes: 4 additions & 1 deletion SW.Bitween.Api/Resources/Notifiers/Update.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ public class Update : ICommandHandler<int, NotifierUpdate,object>
{
private readonly BitweenDbContext _dbContext;
private readonly RequestContext _requestContext;
private readonly IInfolinkCache _cache;

public Update(BitweenDbContext dbContext, RequestContext requestContext)
public Update(BitweenDbContext dbContext, RequestContext requestContext, IInfolinkCache cache)
{
_dbContext = dbContext;
_requestContext = requestContext;
_cache = cache;
}

public async Task<object> Handle(int key, NotifierUpdate request)
Expand All @@ -37,6 +39,7 @@ public async Task<object> Handle(int key, NotifierUpdate request)


await _dbContext.SaveChangesAsync();
await _cache.BroadcastRevoke();
return null;
}

Expand Down
5 changes: 4 additions & 1 deletion SW.Bitween.Api/Resources/Subscriptions/Delete.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ public class Delete : IDeleteHandler<int,object>
{
private readonly BitweenDbContext _dbContext;
private readonly RequestContext _requestContext;
private readonly IInfolinkCache _cache;


public Delete(BitweenDbContext dbContext, RequestContext requestContext)
public Delete(BitweenDbContext dbContext, RequestContext requestContext, IInfolinkCache cache)
{
this._dbContext = dbContext;
_requestContext = requestContext;
_cache = cache;
}

public async Task<object> Handle(int key)
Expand All @@ -28,6 +30,7 @@ public async Task<object> Handle(int key)
await EnsureNothingPointsAtIt(key);

await _dbContext.DeleteByKeyAsync<Subscription>(key);
await _cache.BroadcastRevoke();
return null;
}

Expand Down
9 changes: 8 additions & 1 deletion SW.Bitween.Api/Resources/Subscriptions/Pause.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ public class Pause : ICommandHandler<int, SubscriptionPause,object>
{
private readonly BitweenDbContext _dbContext;
private readonly RequestContext _requestContext;
private readonly IInfolinkCache _cache;


public Pause(BitweenDbContext dbContext, RequestContext requestContext)
public Pause(BitweenDbContext dbContext, RequestContext requestContext, IInfolinkCache cache)
{
_dbContext = dbContext;
_requestContext = requestContext;
_cache = cache;
}

public async Task<object> Handle(int key, SubscriptionPause request)
Expand All @@ -40,6 +42,11 @@ public async Task<object> Handle(int key, SubscriptionPause request)
trail.SetAfter(entity);
_dbContext.Add(trail);
await _dbContext.SaveChangesAsync();
// The receiving path reads PausedOn off the cached copy, so without this a paused
// integration keeps taking messages for the rest of the cache's ten minutes. Resuming
// has the mirror problem: its handler re-reads the cache, finds the copy still paused
// and returns early, leaving everything it held on hold.
await _cache.BroadcastRevoke();
return new
{
entity.Id
Expand Down
2 changes: 1 addition & 1 deletion SW.Bitween.Api/Resources/Subscriptions/SaveMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public async Task<object> Handle(int key, SubscriptionSaveMapper model)
);

await _dbContext.SaveChangesAsync();
_BitweenCache.BroadcastRevoke();
await _BitweenCache.BroadcastRevoke();
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion SW.Bitween.Api/Resources/WorkGroups/Create.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public async Task<object> Handle(CreateWorkGroupModel request)
};
dbContext.Add(workgroup);
await dbContext.SaveChangesAsync();
_BitweenCache.BroadcastRevoke();
await _BitweenCache.BroadcastRevoke();
await _broadcast.RefreshConsumers();
return new
{
Expand Down
2 changes: 1 addition & 1 deletion SW.Bitween.Api/Resources/WorkGroups/Delete.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public async Task<object> Handle(int key, DeleteWorkGroupModel _)
//Todo chek rabbitMq
dbContext.Remove(category);
await dbContext.SaveChangesAsync();
_infolinkCache.BroadcastRevoke();
await _infolinkCache.BroadcastRevoke();
await _broadcast.RefreshConsumers();
return null;
}
Expand Down
Loading
Loading