[messaging/calendar] cron jobs can run regardless of sub status if billing is disabled (#5218)

## Context
Messaging and calendar cron jobs are only working for workspace that
have sub status different than incomplete, this is because currently
this is the simplest way to know if a user is onboarded. This should not
be the source of truth and this will be updated in a later version. In
the meantime, to make self-hosting easier, we are adding an extra check
on IS_BILLING_ENABLED env var since sub status is not relevant for
people not using billing.
This commit is contained in:
Weiko 2024-04-30 15:01:22 +02:00 committed by GitHub
parent 7c605fc2f9
commit f512049381
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 21 additions and 9 deletions

View File

@ -12,6 +12,7 @@ import {
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
import { DataSourceEntity } from 'src/engine/metadata-modules/data-source/data-source.entity';
import { WorkspaceGoogleCalendarSyncService } from 'src/modules/calendar/services/workspace-google-calendar-sync/workspace-google-calendar-sync.service';
import { EnvironmentService } from 'src/engine/integrations/environment/environment.service';
@Injectable()
export class GoogleCalendarSyncCronJob implements MessageQueueJob<undefined> {
@ -23,14 +24,17 @@ export class GoogleCalendarSyncCronJob implements MessageQueueJob<undefined> {
@InjectRepository(FeatureFlagEntity, 'core')
private readonly featureFlagRepository: Repository<FeatureFlagEntity>,
private readonly workspaceGoogleCalendarSyncService: WorkspaceGoogleCalendarSyncService,
private readonly environmentService: EnvironmentService,
) {}
async handle(): Promise<void> {
const workspaceIds = (
await this.workspaceRepository.find({
where: {
subscriptionStatus: In(['active', 'trialing', 'past_due']),
},
where: this.environmentService.get('IS_BILLING_ENABLED')
? {
subscriptionStatus: In(['active', 'trialing', 'past_due']),
}
: {},
select: ['id'],
})
).map((workspace) => workspace.id);

View File

@ -11,6 +11,7 @@ import { InjectObjectMetadataRepository } from 'src/engine/object-metadata-repos
import { MessageChannelRepository } from 'src/modules/messaging/repositories/message-channel.repository';
import { MessageChannelObjectMetadata } from 'src/modules/messaging/standard-objects/message-channel.object-metadata';
import { GmailFetchMessageContentFromCacheService } from 'src/modules/messaging/services/gmail-fetch-message-content-from-cache/gmail-fetch-message-content-from-cache.service';
import { EnvironmentService } from 'src/engine/integrations/environment/environment.service';
@Injectable()
export class GmailFetchMessagesFromCacheCronJob
@ -24,14 +25,17 @@ export class GmailFetchMessagesFromCacheCronJob
@InjectObjectMetadataRepository(MessageChannelObjectMetadata)
private readonly messageChannelRepository: MessageChannelRepository,
private readonly gmailFetchMessageContentFromCacheService: GmailFetchMessageContentFromCacheService,
private readonly environmentService: EnvironmentService,
) {}
async handle(): Promise<void> {
const workspaceIds = (
await this.workspaceRepository.find({
where: {
subscriptionStatus: In(['active', 'trialing', 'past_due']),
},
where: this.environmentService.get('IS_BILLING_ENABLED')
? {
subscriptionStatus: In(['active', 'trialing', 'past_due']),
}
: {},
select: ['id'],
})
).map((workspace) => workspace.id);

View File

@ -16,6 +16,7 @@ import { MessageQueueService } from 'src/engine/integrations/message-queue/servi
import { InjectObjectMetadataRepository } from 'src/engine/object-metadata-repository/object-metadata-repository.decorator';
import { MessageChannelRepository } from 'src/modules/messaging/repositories/message-channel.repository';
import { MessageChannelObjectMetadata } from 'src/modules/messaging/standard-objects/message-channel.object-metadata';
import { EnvironmentService } from 'src/engine/integrations/environment/environment.service';
@Injectable()
export class GmailPartialSyncCronJob implements MessageQueueJob<undefined> {
@ -30,14 +31,17 @@ export class GmailPartialSyncCronJob implements MessageQueueJob<undefined> {
private readonly messageQueueService: MessageQueueService,
@InjectObjectMetadataRepository(MessageChannelObjectMetadata)
private readonly messageChannelRepository: MessageChannelRepository,
private readonly environmentService: EnvironmentService,
) {}
async handle(): Promise<void> {
const workspaceIds = (
await this.workspaceRepository.find({
where: {
subscriptionStatus: In(['active', 'trialing', 'past_due']),
},
where: this.environmentService.get('IS_BILLING_ENABLED')
? {
subscriptionStatus: In(['active', 'trialing', 'past_due']),
}
: {},
select: ['id'],
})
).map((workspace) => workspace.id);