From 8b92a07acaec669c5b581f43d9b07e3cdd3f28df Mon Sep 17 00:00:00 2001 From: Mohammad Twin Date: Thu, 14 Sep 2023 16:28:36 +0400 Subject: [PATCH 1/3] feat: new saga was added --- src/enums/event.enum.ts | 11 +++++++++++ src/enums/queue.enum.ts | 3 +++ src/mongo/connection.ts | 1 + src/saga/choreography.ts | 10 ++++++++++ src/saga/transaction.ts | 28 ++++++++++++++++++++++++++++ 5 files changed, 53 insertions(+) diff --git a/src/enums/event.enum.ts b/src/enums/event.enum.ts index 793644c..2c49f17 100644 --- a/src/enums/event.enum.ts +++ b/src/enums/event.enum.ts @@ -26,8 +26,19 @@ const DiscordAnalyzerEvent = { ...AnalyzerEvent, }; +const TwitterBot = { + EXTRACT: { + TWEETS: "EXTRACT_TWEETS", + LIKES: "EXTRACT_LIKES", + PROFILES: "EXTRACT_PROFILES" + }, + SEND_MESSAGE: 'SEND_MESSAGE', +} + export const Event = { [Queue.SERVER_API]: ServerEvent, [Queue.DISCORD_BOT]: DiscordBotEvent, [Queue.DISCORD_ANALYZER]: DiscordAnalyzerEvent, + + [Queue.TWITTER_BOT]: TwitterBot } as const; diff --git a/src/enums/queue.enum.ts b/src/enums/queue.enum.ts index 06ce8cf..b1705b2 100644 --- a/src/enums/queue.enum.ts +++ b/src/enums/queue.enum.ts @@ -2,4 +2,7 @@ export enum Queue { SERVER_API = 'SERVER_API', DISCORD_BOT = 'DISCORD_BOT', DISCORD_ANALYZER = 'DISCORD_ANALYZER', + + // TWITTER + TWITTER_BOT = "TWITTER_BOT", } diff --git a/src/mongo/connection.ts b/src/mongo/connection.ts index bc1e2f4..61dfef4 100644 --- a/src/mongo/connection.ts +++ b/src/mongo/connection.ts @@ -18,6 +18,7 @@ class MBConnection { connect(uri: string) { this.connectionUri = uri; + // TODO: check if connection is success } get models() { diff --git a/src/saga/choreography.ts b/src/saga/choreography.ts index 8729db4..469cfb0 100644 --- a/src/saga/choreography.ts +++ b/src/saga/choreography.ts @@ -3,6 +3,7 @@ import { DISCORD_FETCH_MEMBERS_TRANSACTIONS, DISCORD_SCHEDULED_JOB_TRANSACTIONS, DISCORD_UPDATE_CHANNELS_TRANSACTIONS, + TWITTER_REFRESH_TRANSACTIONS } from './transaction'; /* define the DISCORD_UPDATE_CHANNELS choreography */ @@ -22,9 +23,18 @@ const DISCORD_FETCH_MEMBERS: IChoreography = { transactions: DISCORD_FETCH_MEMBERS_TRANSACTIONS, }; +const TWITTER_REFRESH: IChoreography = { + name: 'TWITTER_REFRESH', + transactions: TWITTER_REFRESH_TRANSACTIONS +} + /* all available Choreographies, will grow overtime */ export const ChoreographyDict = { DISCORD_UPDATE_CHANNELS, DISCORD_SCHEDULED_JOB, DISCORD_FETCH_MEMBERS, + + // Twitter + TWITTER_REFRESH, + } as const; diff --git a/src/saga/transaction.ts b/src/saga/transaction.ts index 139dfe4..9ccb477 100644 --- a/src/saga/transaction.ts +++ b/src/saga/transaction.ts @@ -54,3 +54,31 @@ export const DISCORD_FETCH_MEMBERS_TRANSACTIONS: ITransaction[] = [ ...DEFAULT_TRANSACTION_PROPERTY, }, ]; + + +export const TWITTER_REFRESH_TRANSACTIONS: ITransaction[] = [ + { + queue: Queue.TWITTER_BOT, + event: Event.TWITTER_BOT.EXTRACT.TWEETS, + order: 1, + ...DEFAULT_TRANSACTION_PROPERTY + }, + { + queue: Queue.TWITTER_BOT, + event: Event.TWITTER_BOT.EXTRACT.PROFILES, + order: 2, + ...DEFAULT_TRANSACTION_PROPERTY + }, + { + queue: Queue.TWITTER_BOT, + event: Event.TWITTER_BOT.EXTRACT.LIKES, + order: 3, + ...DEFAULT_TRANSACTION_PROPERTY + }, + { + queue: Queue.TWITTER_BOT, + event: Event.TWITTER_BOT.SEND_MESSAGE, + order: 4, + ...DEFAULT_TRANSACTION_PROPERTY + } +] \ No newline at end of file From dfcf0b89956eca00d367acf284a1850f9f3b556c Mon Sep 17 00:00:00 2001 From: Mohammad Twin Date: Thu, 14 Sep 2023 17:27:17 +0400 Subject: [PATCH 2/3] feat: order was changed --- src/saga/transaction.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/saga/transaction.ts b/src/saga/transaction.ts index 9ccb477..1fd72ec 100644 --- a/src/saga/transaction.ts +++ b/src/saga/transaction.ts @@ -65,13 +65,13 @@ export const TWITTER_REFRESH_TRANSACTIONS: ITransaction[] = [ }, { queue: Queue.TWITTER_BOT, - event: Event.TWITTER_BOT.EXTRACT.PROFILES, + event: Event.TWITTER_BOT.EXTRACT.LIKES, order: 2, ...DEFAULT_TRANSACTION_PROPERTY }, { queue: Queue.TWITTER_BOT, - event: Event.TWITTER_BOT.EXTRACT.LIKES, + event: Event.TWITTER_BOT.EXTRACT.PROFILES, order: 3, ...DEFAULT_TRANSACTION_PROPERTY }, From ff5cee1d4f72f0112b173103e15ce19d030846fb Mon Sep 17 00:00:00 2001 From: Mohammad Twin Date: Thu, 14 Sep 2023 17:28:10 +0400 Subject: [PATCH 3/3] Feat: version increased --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 660d13f..4cfdbef 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@togethercrew.dev/tc-messagebroker", - "version": "0.0.40", + "version": "0.0.41", "description": "a service that include common things that need in every microservies ", "main": "./dist/index.js", "types": "./dist/index.d.ts",