Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: integrated TxSubmitWorker in cli
- Loading branch information
Showing
20 changed files
with
317 additions
and
80 deletions.
There are no files selected for viewing
10 changes: 6 additions & 4 deletions
10
packages/cardano-services/src/Program/ProgramOptionDescriptions.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 |
---|---|---|
@@ -1,9 +1,11 @@ | ||
export enum ProgramOptionDescriptions { | ||
import { CommonOptionDescriptions } from '../ProgramsCommon'; | ||
|
||
enum HttpServerOptionDescriptions { | ||
ApiUrl = 'API URL', | ||
DbConnection = 'DB Connection', | ||
LoggerMinSeverity = 'Log level', | ||
MetricsEnabled = 'Enable Prometheus Metrics', | ||
OgmiosUrl = 'Ogmios URL', | ||
RabbitMQUrl = 'RabbitMQ URL', | ||
UseQueue = 'Enables RabbitMQ' | ||
} | ||
|
||
export type ProgramOptionDescriptions = CommonOptionDescriptions | HttpServerOptionDescriptions; | ||
export const ProgramOptionDescriptions = { ...CommonOptionDescriptions, ...HttpServerOptionDescriptions }; |
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,10 +1,3 @@ | ||
import { createConnectionObject } from '@cardano-sdk/ogmios'; | ||
export { OGMIOS_URL_DEFAULT, RABBITMQ_URL_DEFAULT } from '../ProgramsCommon'; | ||
|
||
export const API_URL_DEFAULT = 'http://localhost:3000'; | ||
|
||
export const OGMIOS_URL_DEFAULT = (() => { | ||
const connection = createConnectionObject(); | ||
return connection.address.webSocket; | ||
})(); | ||
|
||
export const RABBITMQ_URL_DEFAULT = 'amqp://localhost:5672'; |
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
5 changes: 5 additions & 0 deletions
5
packages/cardano-services/src/ProgramsCommon/CommonOptionDescriptions.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,5 @@ | ||
export enum CommonOptionDescriptions { | ||
LoggerMinSeverity = 'Log level', | ||
OgmiosUrl = 'Ogmios URL', | ||
RabbitMQUrl = 'RabbitMQ URL' | ||
} |
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,8 @@ | ||
import { createConnectionObject } from '@cardano-sdk/ogmios'; | ||
|
||
export const OGMIOS_URL_DEFAULT = (() => { | ||
const connection = createConnectionObject(); | ||
return connection.address.webSocket; | ||
})(); | ||
|
||
export const RABBITMQ_URL_DEFAULT = 'amqp://localhost:5672'; |
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,3 @@ | ||
export * from './CommonOptionDescriptions'; | ||
export * from './defaults'; | ||
export * from './options'; |
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,12 @@ | ||
import { LogLevel } from 'bunyan'; | ||
|
||
/** | ||
* Common options for programs: | ||
* - HTTP server | ||
* - RabbitMQ worker | ||
*/ | ||
export interface CommonProgramOptions { | ||
loggerMinSeverity?: LogLevel; | ||
ogmiosUrl?: URL; | ||
rabbitmqUrl?: URL; | ||
} |
4 changes: 4 additions & 0 deletions
4
packages/cardano-services/src/TxWorker/TxWorkerOptionDescriptions.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,4 @@ | ||
export enum TxWorkerOptionDescriptions { | ||
Parallel = 'Parallel mode', | ||
PollingCycle = 'Polling cycle' | ||
} |
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,5 @@ | ||
export { OGMIOS_URL_DEFAULT, RABBITMQ_URL_DEFAULT } from '../ProgramsCommon'; | ||
|
||
export const PARALLEL_MODE_DEFAULT = false; | ||
|
||
export const POLLING_CYCLE_DEFAULT = 500; |
10 changes: 10 additions & 0 deletions
10
packages/cardano-services/src/TxWorker/errors/WrongTxWorkerOption.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,10 @@ | ||
import { CustomError } from 'ts-custom-error'; | ||
import { ServiceNames } from '../../Program'; | ||
import { TxWorkerOptionDescriptions } from '../TxWorkerOptionDescriptions'; | ||
|
||
export class WrongProgramOption extends CustomError { | ||
public constructor(service: ServiceNames, option: TxWorkerOptionDescriptions, expected: string[]) { | ||
super(); | ||
this.message = `${service} requires a valid ${option} program option. Expected: ${expected.join(', ')}`; | ||
} | ||
} |
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 @@ | ||
export * from './WrongTxWorkerOption'; |
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,4 @@ | ||
export * from './defaults'; | ||
export * from './errors'; | ||
export * from './loadTxWorker'; | ||
export * from './TxWorkerOptionDescriptions'; |
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 { CommonOptionDescriptions, CommonProgramOptions } from '../ProgramsCommon'; | ||
import { MissingProgramOption, ServiceNames } from '../Program'; | ||
import { TxSubmitWorker, TxSubmitWorkerOptions } from '@cardano-sdk/rabbitmq'; | ||
import { createLogger } from 'bunyan'; | ||
import { ogmiosTxSubmitProvider, urlToConnectionConfig } from '@cardano-sdk/ogmios'; | ||
|
||
export type TxWorkerOptions = CommonProgramOptions & Pick<TxSubmitWorkerOptions, 'parallel' | 'pollingCycle'>; | ||
|
||
export interface TxWorkerArgs { | ||
options: TxWorkerOptions; | ||
} | ||
|
||
export const loadTxWorker = async (args: TxWorkerArgs) => { | ||
const { loggerMinSeverity, ogmiosUrl, rabbitmqUrl } = args.options; | ||
const txSubmitProvider = ogmiosTxSubmitProvider(urlToConnectionConfig(ogmiosUrl)); | ||
const logger = createLogger({ level: loggerMinSeverity, name: 'tx-worker' }); | ||
|
||
// Ensure rabbitmqUrl is not undefined | ||
if (!rabbitmqUrl) throw new MissingProgramOption(ServiceNames.TxSubmit, CommonOptionDescriptions.RabbitMQUrl); | ||
|
||
return new TxSubmitWorker({ ...args.options, logger, rabbitmqUrl, txSubmitProvider }); | ||
}; |
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.