-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1136 from Giveth/f_1051_fix_add_campaigns_to_proj…
…ect_by_slug Add Other types of campaigns to projectBySlug webservice
- Loading branch information
Showing
10 changed files
with
110 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import config from '../../config'; | ||
import { logger } from '../../utils/logger'; | ||
import { schedule } from 'node-cron'; | ||
import { isTestEnv } from '../../utils/utils'; | ||
import { ModuleThread, Pool, spawn, Worker } from 'threads'; | ||
import { CacheProjectCampaignsWorker } from '../../workers/cacheProjectCampaignsWorker'; | ||
|
||
// every 10 minutes | ||
const cronJobTime = | ||
(config.get('CACHE_PROJECT_CAMPAIGNS_CRONJOB_EXPRESSION') as string) || | ||
'*/10 * * * *'; | ||
|
||
const projectsFiltersThreadPool: Pool< | ||
ModuleThread<CacheProjectCampaignsWorker> | ||
> = Pool( | ||
() => spawn(new Worker('../../workers/cacheProjectCampaignsWorker')), // create the worker, | ||
); | ||
export const runUpdateProjectCampaignsCacheJob = () => { | ||
// Run it first time to make sure it is cached | ||
projectsFiltersThreadPool.queue(async worker => { | ||
await worker.cacheSlugsOfCampaignProjects(); | ||
}); | ||
|
||
logger.debug( | ||
'runUpdateProjectCampaignsCacheJob() has been called, cronJobTime', | ||
cronJobTime, | ||
); | ||
schedule(cronJobTime, async () => { | ||
try { | ||
projectsFiltersThreadPool.queue(async worker => { | ||
await worker.cacheSlugsOfCampaignProjects(); | ||
}); | ||
} catch (e) { | ||
logger.error('runUpdateProjectCampaignsCacheJob() error', e); | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// workers/auth.js | ||
import { expose } from 'threads/worker'; | ||
import { WorkerModule } from 'threads/dist/types/worker'; | ||
import { cacheProjectCampaigns } from '../services/campaignService'; | ||
|
||
type ProjectsResolverWorkerFunctions = 'cacheSlugsOfCampaignProjects'; | ||
|
||
export type CacheProjectCampaignsWorker = | ||
WorkerModule<ProjectsResolverWorkerFunctions>; | ||
|
||
const worker: CacheProjectCampaignsWorker = { | ||
async cacheSlugsOfCampaignProjects() { | ||
await cacheProjectCampaigns(); | ||
}, | ||
}; | ||
|
||
expose(worker); |
Oops, something went wrong.