Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions backend/config/custom-environment-variables.json
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@
"slackAlerting": {
"url": "CROWD_SLACK_ALERTING_URL"
},
"sampleData": {
"tenantId": "CROWD_SAMPLE_DATA_TENANT_ID"
},
"unleash": {
"url": "CROWD_UNLEASH_URL",
"adminApiKey": "CROWD_UNLEASH_ADMIN_API_KEY",
Expand Down
3 changes: 3 additions & 0 deletions backend/config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,8 @@
},
"slackAlerting": {
"url": ""
},
"sampleData": {
"tenantId": ""
}
}
2 changes: 2 additions & 0 deletions backend/src/bin/jobs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import refreshMaterializedViews from './refreshMaterializedViews'
import downgradeExpiredPlans from './downgradeExpiredPlans'
import eagleEyeEmailDigestTicks from './eagleEyeEmailDigestTicks'
import integrationDataChecker from './integrationDataChecker'
import refreshSampleData from './refreshSampleData'

const jobs: CrowdJob[] = [
weeklyAnalyticsEmailsCoordinator,
Expand All @@ -17,6 +18,7 @@ const jobs: CrowdJob[] = [
downgradeExpiredPlans,
eagleEyeEmailDigestTicks,
integrationDataChecker,
refreshSampleData,
]

export default jobs
19 changes: 19 additions & 0 deletions backend/src/bin/jobs/refreshSampleData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { CrowdJob } from '../../types/jobTypes'
import { sendNodeWorkerMessage } from '../../serverless/utils/nodeWorkerSQS'
import { NodeWorkerMessageType } from '../../serverless/types/workerTypes'
import { NodeWorkerMessageBase } from '../../types/mq/nodeWorkerMessageBase'

const job: CrowdJob = {
name: 'Refresh sample data',
// every hour
cronTime: '0 * * * *',
// cronTime: '0 0 * * *',
onTrigger: async () => {
await sendNodeWorkerMessage('refresh-sample-data', {
type: NodeWorkerMessageType.NODE_MICROSERVICE,
service: 'refresh-sample-data',
} as NodeWorkerMessageBase)
},
}

export default job
4 changes: 4 additions & 0 deletions backend/src/config/configTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,7 @@ export interface UnleashConfiguration {
export interface SlackAlertingConfiguration {
url: string
}

export interface SampleDataConfiguration {
tenantId: string
}
7 changes: 7 additions & 0 deletions backend/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
EagleEyeConfiguration,
UnleashConfiguration,
SlackAlertingConfiguration,
SampleDataConfiguration,
} from './configTypes'

// TODO-kube
Expand Down Expand Up @@ -240,3 +241,9 @@ export const SLACK_ALERTING_CONFIG: SlackAlertingConfiguration = KUBE_MODE
: {
url: process.env.SLACK_ALERTING_URL,
}

export const SAMPLE_DATA_CONFIG: SampleDataConfiguration = KUBE_MODE
? config.get<SampleDataConfiguration>('sampleData')
: {
tenantId: process.env.SAMPLE_DATA_TENANT_ID,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { QueryTypes } from 'sequelize'
import { API_CONFIG, SAMPLE_DATA_CONFIG } from '../../../../config'
import getUserContext from '../../../../database/utils/getUserContext'

async function refreshSampleDataWorker(): Promise<void> {
// This is only needed for hosted edition
if (API_CONFIG.edition === 'crowd-hosted') {
const tenantId = SAMPLE_DATA_CONFIG.tenantId
const userContext = await getUserContext(SAMPLE_DATA_CONFIG.tenantId)
const updateDays = 9 // Every day we need to refresh

// These are all the tables that have columns that need to be updated
const tables = [
{ name: 'activities', columns: ['createdAt', 'timestamp'] },
{ name: 'members', columns: ['joinedAt', 'createdAt'] },
{ name: 'notes', columns: ['createdAt'] },
{ name: 'conversations', columns: ['createdAt'] },
{ name: 'organizations', columns: ['createdAt'] },
{ name: 'tags', columns: ['createdAt'] },
]

// We are using a direct query because it is very specific functionality.
// There is no point creating repository methods.
for (const table of tables) {
for (const column of table.columns) {
const query = `
UPDATE ${table.name}
SET "${column}" = "${column}" + INTERVAL '${updateDays} days'
WHERE "tenantId" = '${tenantId}';
`
await userContext.database.sequelize.query(query, { type: QueryTypes.UPDATE })
}
}
}
}

export { refreshSampleDataWorker }
4 changes: 4 additions & 0 deletions backend/src/serverless/microservices/nodejs/workerFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { processSendgridWebhook } from '../../integrations/workers/sendgridWebho
import { bulkEnrichmentWorker } from './bulk-enrichment/bulkEnrichmentWorker'
import { eagleEyeEmailDigestWorker } from './eagle-eye-email-digest/eagleEyeEmailDigestWorker'
import { integrationDataCheckerWorker } from './integration-data-checker/integrationDataCheckerWorker'
import { refreshSampleDataWorker } from './integration-data-checker/refreshSampleDataWorker'

/**
* Worker factory for spawning different microservices
Expand Down Expand Up @@ -49,6 +50,9 @@ async function workerFactory(event: NodeMicroserviceMessage): Promise<any> {
integrationDataCheckerMessage.integrationId,
integrationDataCheckerMessage.tenantId,
)
case 'refresh-sample-data':
return refreshSampleDataWorker()

case 'csv-export':
const csvExportMessage = event as CsvExportMessage
return csvExportWorker(
Expand Down