Skip to content

πŸ“¨ The ultimate agentic social media scheduling tool πŸ€–

feat: split servers

Nevo David5b0288fd5a21
diff --git a/libraries/nestjs-libraries/src/integrations/social/linkedin.provider.ts b/libraries/nestjs-libraries/src/integrations/social/linkedin.provider.ts
index e7224b902..4e66cec57 100644
--- a/libraries/nestjs-libraries/src/integrations/social/linkedin.provider.ts
+++ b/libraries/nestjs-libraries/src/integrations/social/linkedin.provider.ts
@@ -40,7 +40,7 @@ export class LinkedinProvider extends SocialAbstract implements SocialProvider {
'w_organization_social',
'r_organization_social',
];
- override maxConcurrentJob = 2; // LinkedIn has professional posting limits
+ override maxConcurrentJob = 1;
refreshWait = true;
editor = 'normal' as const;
maxLength() {
diff --git a/libraries/nestjs-libraries/src/temporal/temporal.module.ts b/libraries/nestjs-libraries/src/temporal/temporal.module.ts
index dace46cb9..4f9808770 100644
--- a/libraries/nestjs-libraries/src/temporal/temporal.module.ts
+++ b/libraries/nestjs-libraries/src/temporal/temporal.module.ts
@@ -6,6 +6,23 @@ export const getTemporalModule = (
path?: string,
activityClasses?: any[]
) => {
+ // Queues this worker server should NOT run, comma-separated
+ // (e.g. EXCLUDE_QUEUE="reddit,x,twitch"). Use it to pin a queue to a single
+ // server: exclude it on every server except the one that should own it.
+ // Meant for the providers whose concurrency is too low to split (limit 1).
+ const excludeQueues = (process.env.EXCLUDE_QUEUE || '')
+ .split(',')
+ .map((s) => s.trim())
+ .filter(Boolean);
+
+ // How many worker servers share each (non-excluded) queue. Per-server
+ // concurrency is divided by this so the GLOBAL concurrency stays correct.
+ // 1 server => 1 (full), 2 servers => 2 (half each), 3 servers => 3, etc.
+ const divider = Math.max(
+ 1,
+ Number(process.env.WORKER_CONCURRENCY_DIVIDER) || 1
+ );
+
return TemporalModule.register({
isGlobal: true,
connection: {
@@ -24,19 +41,33 @@ export const getTemporalModule = (
]
.filter((f) => f.identifier.indexOf('-') === -1)
.map((integration) => ({
+ integration,
taskQueue: integration.identifier.split('-')[0],
- workflowsPath: path!,
- activityClasses: activityClasses!,
- autoStart: true,
- ...(integration.maxConcurrentJob
- ? {
- workerOptions: {
- maxConcurrentActivityTaskExecutions:
- integration.maxConcurrentJob,
- },
- }
- : {}),
- })),
+ }))
+ .filter(({ taskQueue }) => !excludeQueues.includes(taskQueue))
+ .map(({ integration, taskQueue }) => {
+ // Split the per-provider cap across the servers sharing this
+ // queue. Floor (never below 1) so the global total never exceeds
+ // the provider's limit. Providers whose limit is smaller than the
+ // server count must be pinned via EXCLUDE_QUEUE instead.
+ const concurrency = integration.maxConcurrentJob
+ ? Math.max(1, Math.floor(integration.maxConcurrentJob / divider))
+ : undefined;
+
+ return {
+ taskQueue,
+ workflowsPath: path!,
+ activityClasses: activityClasses!,
+ autoStart: true,
+ ...(concurrency
+ ? {
+ workerOptions: {
+ maxConcurrentActivityTaskExecutions: concurrency,
+ },
+ }
+ : {}),
+ };
+ }),
}
: {}),
});