Merge pull request #22529 from drodil/signals_improvements

fix: signal disconnect loop on server start
This commit is contained in:
Patrik Oldsberg
2024-02-01 20:49:29 +01:00
committed by GitHub
18 changed files with 126 additions and 46 deletions
+3 -3
View File
@@ -16,15 +16,15 @@ export class DefaultSignalService implements SignalService {
// @public (undocumented)
export type SignalPayload = {
recipients: string[] | null;
recipients: string[] | string | null;
channel: string;
message: JsonObject;
};
// @public (undocumented)
export type SignalService = {
export interface SignalService {
publish(signal: SignalPayload): Promise<void>;
};
}
// @public (undocumented)
export const signalService: ServiceRef<SignalService, 'plugin'>;
@@ -0,0 +1,38 @@
/*
* Copyright 2024 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { DefaultSignalService } from './DefaultSignalService';
describe('DefaultSignalService', () => {
const mockEventBroker = {
publish: jest.fn(),
subscribe: jest.fn(),
};
const service = DefaultSignalService.create({ eventBroker: mockEventBroker });
it('should publish signal', () => {
const signal = {
channel: 'test-channel',
recipients: null,
message: { msg: 'hello world' },
};
service.publish(signal);
expect(mockEventBroker.publish).toHaveBeenCalledWith({
topic: 'signals',
eventPayload: signal,
});
});
});
@@ -37,14 +37,9 @@ export class DefaultSignalService implements SignalService {
* @param message - message to publish
*/
async publish(signal: SignalPayload) {
const { recipients, channel, message } = signal;
await this.eventBroker?.publish({
topic: 'signals',
eventPayload: {
recipients,
message,
channel,
},
eventPayload: signal,
});
}
}
+2 -2
View File
@@ -16,9 +16,9 @@
import { SignalPayload } from './types';
/** @public */
export type SignalService = {
export interface SignalService {
/**
* Publishes a message to user refs to specific topic
*/
publish(signal: SignalPayload): Promise<void>;
};
}
+1 -1
View File
@@ -25,7 +25,7 @@ export type SignalServiceOptions = {
/** @public */
export type SignalPayload = {
recipients: string[] | null;
recipients: string[] | string | null;
channel: string;
message: JsonObject;
};