-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from Project-OMOTES/WouterSpaak/issue11
Workflow definitions are not configured anymore on both sides but rather shared by the orchestrator on startup.
- Loading branch information
Showing
22 changed files
with
233 additions
and
39 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
export * from '@omotes/proto'; | ||
|
||
export * from './lib/Job'; | ||
export * from './lib/OmotesSDK'; | ||
export * from './lib/channel'; | ||
export * from './lib/handlers/ProgressHandler'; | ||
export * from './lib/handlers/ResultHandler'; | ||
export * from './lib/handlers/StatusHandler'; | ||
export * from './lib/Job'; | ||
export * from './lib/OmotesSDK'; | ||
export * from './lib/types'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import { Connection } from 'amqplib'; | ||
|
||
export async function getChannel(connection: Connection, queueName: string) { | ||
export async function getChannel(connection: Connection, queueName: string, routingKey?: string) { | ||
const channel = await connection.createChannel(); | ||
const exchange = await channel.assertExchange('omotes_exchange', 'direct'); | ||
const queue = await channel.assertQueue(queueName, { durable: true }); | ||
await channel.bindQueue(queue.queue, exchange.exchange, queueName); | ||
await channel.bindQueue(queue.queue, exchange.exchange, routingKey ?? queueName); | ||
return { channel, exchange }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { AvailableWorkflows, Workflow } from '@omotes/proto'; | ||
import { Channel } from 'amqplib'; | ||
import { of } from 'rxjs'; | ||
import { MockChannel } from '../../util/MockChannel.spec'; | ||
import { AvailableWorkflowsHandler } from './AvailableWorkflowsHandler'; | ||
|
||
describe('AvailableWorkflowsHandler', () => { | ||
describe('#getWorkflows', () => { | ||
let channel: MockChannel<AvailableWorkflows>; | ||
let handler: AvailableWorkflowsHandler; | ||
|
||
beforeEach(() => { | ||
channel = new MockChannel(); | ||
handler = new AvailableWorkflowsHandler( | ||
of(channel as unknown as Channel), | ||
'client_id' | ||
); | ||
}); | ||
|
||
it('should report workflows', (done) => { | ||
const { message, workflows } = getWorkflows(); | ||
handler.getWorkflows().subscribe((responses) => { | ||
expect(responses).toEqual(workflows); | ||
done(); | ||
}); | ||
channel.pushMessage(message); | ||
}); | ||
}); | ||
}); | ||
|
||
function getWorkflows() { | ||
const message = new AvailableWorkflows(); | ||
const workflows = [ | ||
{ typeName: 'workflow1', typeDescription: 'description1', parametersList: [] }, | ||
{ typeName: 'workflow2', typeDescription: 'description2', parametersList: [] }, | ||
]; | ||
const list = workflows.map(({ typeDescription, typeName }) => { | ||
const w = new Workflow(); | ||
w.setTypeDescription(typeDescription); | ||
w.setTypeName(typeName); | ||
return w; | ||
}) | ||
message.setWorkflowsList(list); | ||
return { | ||
workflows, | ||
message | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { AvailableWorkflows } from '@omotes/proto'; | ||
import { Channel } from 'amqplib'; | ||
import { Observable } from 'rxjs'; | ||
import { map } from 'rxjs/operators'; | ||
import { Handler } from './Handler'; | ||
|
||
export class AvailableWorkflowsHandler extends Handler { | ||
protected override queue = this.getQueueName(); | ||
constructor(protected override readonly channel$: Observable<Channel>, private readonly clientId?: string) { | ||
super(channel$); | ||
} | ||
|
||
public getWorkflows() { | ||
return this.channelToRx().pipe( | ||
map((message) => { | ||
return AvailableWorkflows.deserializeBinary(message.content).toObject().workflowsList; | ||
}) | ||
) | ||
} | ||
|
||
private getQueueName() { | ||
return `available_workflows.${this.clientId}`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Channel } from 'amqplib'; | ||
import { Observable } from 'rxjs'; | ||
import { Job } from '../Job'; | ||
import { Handler } from './Handler'; | ||
|
||
export abstract class JobHandler extends Handler { | ||
constructor(protected readonly job: Job, protected override readonly channel$: Observable<Channel>) { | ||
super(channel$); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
sdk/src/lib/handlers/RequestAvailableWorkflowsHandler.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { RequestAvailableWorkflows } from '@omotes/proto'; | ||
import { Channel } from 'amqplib'; | ||
import { MockChannel } from '../../util/MockChannel.spec'; | ||
import { RequestAvailableWorkflowsHandler } from './RequestAvailableWorkflowsHandler'; | ||
|
||
describe('RequestAvailableWorkflowsHandler', () => { | ||
let channel: MockChannel<RequestAvailableWorkflows>; | ||
let handler: RequestAvailableWorkflowsHandler; | ||
beforeEach(() => { | ||
channel = new MockChannel(); | ||
handler = new RequestAvailableWorkflowsHandler(); | ||
}); | ||
|
||
describe('#start', () => { | ||
it('should send a message to the channel', () => { | ||
handler.start(channel as unknown as Channel); | ||
expect(channel.sendToQueue).toHaveBeenCalledWith('request_available_workflows', expect.any(Buffer), { | ||
persistent: true | ||
}); | ||
}); | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { RequestAvailableWorkflows } from '@omotes/proto'; | ||
import { Channel } from 'amqplib'; | ||
|
||
export class RequestAvailableWorkflowsHandler { | ||
private queue = 'request_available_workflows'; | ||
|
||
public start(channel: Channel) { | ||
const message = new RequestAvailableWorkflows(); | ||
return channel.sendToQueue(this.queue, Buffer.from(message.serializeBinary()), { persistent: true }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.