The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
register all cron jobs in entrypoint (#12791)
nitin6aee42ab22d1
diff --git a/.dockerignore b/.dockerignoreindex f9fc785f92d..93efb8a60b4 100644--- a/.dockerignore+++ b/.dockerignore@@ -2,3 +2,4 @@.envnode_modules.nx/cache+packages/twenty-server/.envdiff --git a/packages/twenty-docker/docker-compose.yml b/packages/twenty-docker/docker-compose.ymlindex 617ce3c679b..e95fde62faf 100644--- a/packages/twenty-docker/docker-compose.yml+++ b/packages/twenty-docker/docker-compose.yml@@ -12,6 +12,8 @@ services:PG_DATABASE_URL: postgres://${PG_DATABASE_USER:-postgres}:${PG_DATABASE_PASSWORD:-postgres}@${PG_DATABASE_HOST:-db}:${PG_DATABASE_PORT:-5432}/defaultSERVER_URL: ${SERVER_URL}REDIS_URL: ${REDIS_URL:-redis://redis:6379}+ DISABLE_DB_MIGRATIONS: ${DISABLE_DB_MIGRATIONS}+ DISABLE_CRON_JOBS_REGISTRATION: ${DISABLE_CRON_JOBS_REGISTRATION}STORAGE_TYPE: ${STORAGE_TYPE}STORAGE_S3_REGION: ${STORAGE_S3_REGION}@@ -63,6 +65,7 @@ services:SERVER_URL: ${SERVER_URL}REDIS_URL: ${REDIS_URL:-redis://redis:6379}DISABLE_DB_MIGRATIONS: "true" # it already runs on the server+ DISABLE_CRON_JOBS_REGISTRATION: "true" # it already runs on the serverSTORAGE_TYPE: ${STORAGE_TYPE}STORAGE_S3_REGION: ${STORAGE_S3_REGION}diff --git a/packages/twenty-docker/twenty/entrypoint.sh b/packages/twenty-docker/twenty/entrypoint.shindex 5b523fe7760..51c2ebac8e9 100755--- a/packages/twenty-docker/twenty/entrypoint.sh+++ b/packages/twenty-docker/twenty/entrypoint.sh@@ -28,7 +28,23 @@ setup_and_migrate_db() {yarn command:prod upgradeecho "Successfully migrated DB!"}++register_background_jobs() {+ if [ "${DISABLE_CRON_JOBS_REGISTRATION}" = "true" ]; then+ echo "Cron job registration is disabled, skipping..."+ return+ fi++ echo "Registering background sync jobs..."+ if yarn command:prod cron:register:all; then+ echo "Successfully registered all background sync jobs!"+ else+ echo "Warning: Failed to register background jobs, but continuing startup..."+ fi+}+setup_and_migrate_db+register_background_jobs# Continue with the original Docker commandexec "$@"diff --git a/packages/twenty-server/src/database/commands/cron-register-all.command.ts b/packages/twenty-server/src/database/commands/cron-register-all.command.tsnew file mode 100644index 00000000000..c0975f7bf13--- /dev/null+++ b/packages/twenty-server/src/database/commands/cron-register-all.command.ts@@ -0,0 +1,94 @@+import { Logger } from '@nestjs/common';++import { Command, CommandRunner } from 'nest-commander';++import { CalendarEventListFetchCronCommand } from 'src/modules/calendar/calendar-event-import-manager/crons/commands/calendar-event-list-fetch.cron.command';+import { CalendarEventsImportCronCommand } from 'src/modules/calendar/calendar-event-import-manager/crons/commands/calendar-import.cron.command';+import { CalendarOngoingStaleCronCommand } from 'src/modules/calendar/calendar-event-import-manager/crons/commands/calendar-ongoing-stale.cron.command';+import { MessagingMessageListFetchCronCommand } from 'src/modules/messaging/message-import-manager/crons/commands/messaging-message-list-fetch.cron.command';+import { MessagingMessagesImportCronCommand } from 'src/modules/messaging/message-import-manager/crons/commands/messaging-messages-import.cron.command';+import { MessagingOngoingStaleCronCommand } from 'src/modules/messaging/message-import-manager/crons/commands/messaging-ongoing-stale.cron.command';+import { CronTriggerCronCommand } from 'src/modules/workflow/workflow-trigger/automated-trigger/crons/commands/cron-trigger.cron.command';++@Command({+ name: 'cron:register:all',+ description: 'Register all background sync cron jobs',+})+export class CronRegisterAllCommand extends CommandRunner {+ private readonly logger = new Logger(CronRegisterAllCommand.name);++ constructor(+ private readonly messagingMessagesImportCronCommand: MessagingMessagesImportCronCommand,+ private readonly messagingMessageListFetchCronCommand: MessagingMessageListFetchCronCommand,+ private readonly messagingOngoingStaleCronCommand: MessagingOngoingStaleCronCommand,+ private readonly calendarEventListFetchCronCommand: CalendarEventListFetchCronCommand,+ private readonly calendarEventsImportCronCommand: CalendarEventsImportCronCommand,+ private readonly calendarOngoingStaleCronCommand: CalendarOngoingStaleCronCommand,+ private readonly cronTriggerCronCommand: CronTriggerCronCommand,+ ) {+ super();+ }++ async run(): Promise<void> {+ this.logger.log('Registering all background sync cron jobs...');++ const commands = [+ {+ name: 'MessagingMessagesImport',+ command: this.messagingMessagesImportCronCommand,+ },+ {+ name: 'MessagingMessageListFetch',+ command: this.messagingMessageListFetchCronCommand,+ },+ {+ name: 'MessagingOngoingStale',+ command: this.messagingOngoingStaleCronCommand,+ },+ {+ name: 'CalendarEventListFetch',+ command: this.calendarEventListFetchCronCommand,+ },+ {+ name: 'CalendarEventsImport',+ command: this.calendarEventsImportCronCommand,+ },+ {+ name: 'CalendarOngoingStale',+ command: this.calendarOngoingStaleCronCommand,+ },+ { name: 'CronTrigger', command: this.cronTriggerCronCommand },+ ];++ let successCount = 0;+ let failureCount = 0;+ const failures: string[] = [];+ const successes: string[] = [];++ for (const { name, command } of commands) {+ try {+ this.logger.log(`Registering ${name} cron job...`);+ await command.run();+ this.logger.log(`Successfully registered ${name} cron job`);+ successCount++;+ successes.push(name);+ } catch (error) {+ this.logger.error(`Failed to register ${name} cron job:`, error);+ failureCount++;+ failures.push(name);+ }+ }++ this.logger.log(+ `Cron job registration completed: ${successCount} successful, ${failureCount} failed`,+ );++ if (failures.length > 0) {+ this.logger.warn(`Failed commands: ${failures.join(', ')}`);+ }++ if (successCount > 0) {+ this.logger.log(`Successful commands: ${successes.join(', ')}`);+ }+ }+}diff --git a/packages/twenty-server/src/database/commands/database-command.module.ts b/packages/twenty-server/src/database/commands/database-command.module.tsindex 38c1c23a1d4..34576bf232e 100644--- a/packages/twenty-server/src/database/commands/database-command.module.ts+++ b/packages/twenty-server/src/database/commands/database-command.module.ts@@ -1,5 +1,6 @@import { Module } from '@nestjs/common';+import { CronRegisterAllCommand } from 'src/database/commands/cron-register-all.command';import { DataSeedWorkspaceCommand } from 'src/database/commands/data-seed-dev-workspace.command';import { ConfirmationQuestion } from 'src/database/commands/questions/confirmation.question';import { UpgradeVersionCommandModule } from 'src/database/commands/upgrade-version-command/upgrade-version-command.module';@@ -10,11 +11,19 @@ import { ObjectMetadataModule } from 'src/engine/metadata-modules/object-metadatimport { WorkspaceCacheStorageModule } from 'src/engine/workspace-cache-storage/workspace-cache-storage.module';import { DevSeederModule } from 'src/engine/workspace-manager/dev-seeder/dev-seeder.module';import { WorkspaceManagerModule } from 'src/engine/workspace-manager/workspace-manager.module';+import { CalendarEventImportManagerModule } from 'src/modules/calendar/calendar-event-import-manager/calendar-event-import-manager.module';+import { MessagingImportManagerModule } from 'src/modules/messaging/message-import-manager/messaging-import-manager.module';+import { AutomatedTriggerModule } from 'src/modules/workflow/workflow-trigger/automated-trigger/automated-trigger.module';@Module({imports: [UpgradeVersionCommandModule,+ // Cron command dependencies+ MessagingImportManagerModule,+ CalendarEventImportManagerModule,+ AutomatedTriggerModule,+// Only needed for the data seed commandTypeORMModule,FieldMetadataModule,@@ -24,6 +33,10 @@ import { WorkspaceManagerModule } from 'src/engine/workspace-manager/workspace-mDataSourceModule,WorkspaceCacheStorageModule,],- providers: [DataSeedWorkspaceCommand, ConfirmationQuestion],+ providers: [+ DataSeedWorkspaceCommand,+ ConfirmationQuestion,+ CronRegisterAllCommand,+ ],})export class DatabaseCommandModule {}diff --git a/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/calendar-event-import-manager.module.ts b/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/calendar-event-import-manager.module.tsindex 37c618fbb11..7f5ba22da13 100644--- a/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/calendar-event-import-manager.module.ts+++ b/packages/twenty-server/src/modules/calendar/calendar-event-import-manager/calendar-event-import-manager.module.ts@@ -67,6 +67,12 @@ import { RefreshTokensManagerModule } from 'src/modules/connected-account/refresCalendarOngoingStaleCronCommand,CalendarOngoingStaleJob,],- exports: [CalendarEventsImportService, CalendarFetchEventsService],+ exports: [+ CalendarEventsImportService,+ CalendarFetchEventsService,+ CalendarEventListFetchCronCommand,+ CalendarEventsImportCronCommand,+ CalendarOngoingStaleCronCommand,+ ],})export class CalendarEventImportManagerModule {}diff --git a/packages/twenty-server/src/modules/messaging/message-import-manager/messaging-import-manager.module.ts b/packages/twenty-server/src/modules/messaging/message-import-manager/messaging-import-manager.module.tsindex e227af8a036..a516efd29b0 100644--- a/packages/twenty-server/src/modules/messaging/message-import-manager/messaging-import-manager.module.ts+++ b/packages/twenty-server/src/modules/messaging/message-import-manager/messaging-import-manager.module.ts@@ -83,6 +83,11 @@ import { MessagingMonitoringModule } from 'src/modules/messaging/monitoring/messMessagingCursorService,MessagingSendMessageService,],- exports: [MessagingSendMessageService],+ exports: [+ MessagingSendMessageService,+ MessagingMessageListFetchCronCommand,+ MessagingMessagesImportCronCommand,+ MessagingOngoingStaleCronCommand,+ ],})export class MessagingImportManagerModule {}diff --git a/packages/twenty-server/src/modules/workflow/workflow-trigger/automated-trigger/automated-trigger.module.ts b/packages/twenty-server/src/modules/workflow/workflow-trigger/automated-trigger/automated-trigger.module.tsindex bfb0d2ca894..fa2b83cb403 100644--- a/packages/twenty-server/src/modules/workflow/workflow-trigger/automated-trigger/automated-trigger.module.ts+++ b/packages/twenty-server/src/modules/workflow/workflow-trigger/automated-trigger/automated-trigger.module.ts@@ -19,6 +19,6 @@ import { DatabaseEventTriggerListener } from 'src/modules/workflow/workflow-trigCronTriggerCronJob,CronTriggerCronCommand,],- exports: [AutomatedTriggerWorkspaceService],+ exports: [AutomatedTriggerWorkspaceService, CronTriggerCronCommand],})export class AutomatedTriggerModule {}