[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:
@ -12,6 +12,7 @@ import {
|
|||||||
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
|
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
|
||||||
import { DataSourceEntity } from 'src/engine/metadata-modules/data-source/data-source.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 { 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()
|
@Injectable()
|
||||||
export class GoogleCalendarSyncCronJob implements MessageQueueJob<undefined> {
|
export class GoogleCalendarSyncCronJob implements MessageQueueJob<undefined> {
|
||||||
@ -23,14 +24,17 @@ export class GoogleCalendarSyncCronJob implements MessageQueueJob<undefined> {
|
|||||||
@InjectRepository(FeatureFlagEntity, 'core')
|
@InjectRepository(FeatureFlagEntity, 'core')
|
||||||
private readonly featureFlagRepository: Repository<FeatureFlagEntity>,
|
private readonly featureFlagRepository: Repository<FeatureFlagEntity>,
|
||||||
private readonly workspaceGoogleCalendarSyncService: WorkspaceGoogleCalendarSyncService,
|
private readonly workspaceGoogleCalendarSyncService: WorkspaceGoogleCalendarSyncService,
|
||||||
|
private readonly environmentService: EnvironmentService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async handle(): Promise<void> {
|
async handle(): Promise<void> {
|
||||||
const workspaceIds = (
|
const workspaceIds = (
|
||||||
await this.workspaceRepository.find({
|
await this.workspaceRepository.find({
|
||||||
where: {
|
where: this.environmentService.get('IS_BILLING_ENABLED')
|
||||||
subscriptionStatus: In(['active', 'trialing', 'past_due']),
|
? {
|
||||||
},
|
subscriptionStatus: In(['active', 'trialing', 'past_due']),
|
||||||
|
}
|
||||||
|
: {},
|
||||||
select: ['id'],
|
select: ['id'],
|
||||||
})
|
})
|
||||||
).map((workspace) => workspace.id);
|
).map((workspace) => workspace.id);
|
||||||
|
|||||||
@ -11,6 +11,7 @@ import { InjectObjectMetadataRepository } from 'src/engine/object-metadata-repos
|
|||||||
import { MessageChannelRepository } from 'src/modules/messaging/repositories/message-channel.repository';
|
import { MessageChannelRepository } from 'src/modules/messaging/repositories/message-channel.repository';
|
||||||
import { MessageChannelObjectMetadata } from 'src/modules/messaging/standard-objects/message-channel.object-metadata';
|
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 { 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()
|
@Injectable()
|
||||||
export class GmailFetchMessagesFromCacheCronJob
|
export class GmailFetchMessagesFromCacheCronJob
|
||||||
@ -24,14 +25,17 @@ export class GmailFetchMessagesFromCacheCronJob
|
|||||||
@InjectObjectMetadataRepository(MessageChannelObjectMetadata)
|
@InjectObjectMetadataRepository(MessageChannelObjectMetadata)
|
||||||
private readonly messageChannelRepository: MessageChannelRepository,
|
private readonly messageChannelRepository: MessageChannelRepository,
|
||||||
private readonly gmailFetchMessageContentFromCacheService: GmailFetchMessageContentFromCacheService,
|
private readonly gmailFetchMessageContentFromCacheService: GmailFetchMessageContentFromCacheService,
|
||||||
|
private readonly environmentService: EnvironmentService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async handle(): Promise<void> {
|
async handle(): Promise<void> {
|
||||||
const workspaceIds = (
|
const workspaceIds = (
|
||||||
await this.workspaceRepository.find({
|
await this.workspaceRepository.find({
|
||||||
where: {
|
where: this.environmentService.get('IS_BILLING_ENABLED')
|
||||||
subscriptionStatus: In(['active', 'trialing', 'past_due']),
|
? {
|
||||||
},
|
subscriptionStatus: In(['active', 'trialing', 'past_due']),
|
||||||
|
}
|
||||||
|
: {},
|
||||||
select: ['id'],
|
select: ['id'],
|
||||||
})
|
})
|
||||||
).map((workspace) => workspace.id);
|
).map((workspace) => workspace.id);
|
||||||
|
|||||||
@ -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 { InjectObjectMetadataRepository } from 'src/engine/object-metadata-repository/object-metadata-repository.decorator';
|
||||||
import { MessageChannelRepository } from 'src/modules/messaging/repositories/message-channel.repository';
|
import { MessageChannelRepository } from 'src/modules/messaging/repositories/message-channel.repository';
|
||||||
import { MessageChannelObjectMetadata } from 'src/modules/messaging/standard-objects/message-channel.object-metadata';
|
import { MessageChannelObjectMetadata } from 'src/modules/messaging/standard-objects/message-channel.object-metadata';
|
||||||
|
import { EnvironmentService } from 'src/engine/integrations/environment/environment.service';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class GmailPartialSyncCronJob implements MessageQueueJob<undefined> {
|
export class GmailPartialSyncCronJob implements MessageQueueJob<undefined> {
|
||||||
@ -30,14 +31,17 @@ export class GmailPartialSyncCronJob implements MessageQueueJob<undefined> {
|
|||||||
private readonly messageQueueService: MessageQueueService,
|
private readonly messageQueueService: MessageQueueService,
|
||||||
@InjectObjectMetadataRepository(MessageChannelObjectMetadata)
|
@InjectObjectMetadataRepository(MessageChannelObjectMetadata)
|
||||||
private readonly messageChannelRepository: MessageChannelRepository,
|
private readonly messageChannelRepository: MessageChannelRepository,
|
||||||
|
private readonly environmentService: EnvironmentService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async handle(): Promise<void> {
|
async handle(): Promise<void> {
|
||||||
const workspaceIds = (
|
const workspaceIds = (
|
||||||
await this.workspaceRepository.find({
|
await this.workspaceRepository.find({
|
||||||
where: {
|
where: this.environmentService.get('IS_BILLING_ENABLED')
|
||||||
subscriptionStatus: In(['active', 'trialing', 'past_due']),
|
? {
|
||||||
},
|
subscriptionStatus: In(['active', 'trialing', 'past_due']),
|
||||||
|
}
|
||||||
|
: {},
|
||||||
select: ['id'],
|
select: ['id'],
|
||||||
})
|
})
|
||||||
).map((workspace) => workspace.id);
|
).map((workspace) => workspace.id);
|
||||||
|
|||||||
Reference in New Issue
Block a user