2022-11-01 17:01:08 +01:00
|
|
|
import { GraphileWorker } from '../../src/main/graphile-worker/graphile-worker'
|
2022-10-18 16:44:41 +02:00
|
|
|
import { startGraphileWorker } from '../../src/main/graphile-worker/worker-setup'
|
2022-05-24 09:10:52 +02:00
|
|
|
import { Hub, LogLevel } from '../../src/types'
|
2023-07-11 16:09:28 +02:00
|
|
|
import { PluginServerMode, stringToPluginServerMode } from '../../src/types'
|
2022-05-24 09:10:52 +02:00
|
|
|
import { createHub } from '../../src/utils/db/hub'
|
2023-05-03 16:42:16 +02:00
|
|
|
import Piscina from '../../src/worker/piscina'
|
2022-05-24 09:10:52 +02:00
|
|
|
|
|
|
|
jest.mock('../../src/main/ingestion-queues/kafka-queue')
|
2022-10-18 16:44:41 +02:00
|
|
|
jest.mock('../../src/main/graphile-worker/schedule')
|
2022-05-24 09:10:52 +02:00
|
|
|
|
2023-07-11 16:09:28 +02:00
|
|
|
describe('stringToPluginServerMode', () => {
|
2023-10-13 20:09:57 +02:00
|
|
|
test('gives the right value for ingestion -> PluginServerMode.plugins_ingestion', () => {
|
|
|
|
expect(stringToPluginServerMode['ingestion']).toEqual(PluginServerMode.ingestion)
|
2023-07-11 16:09:28 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
test('gives undefined for invalid input', () => {
|
|
|
|
expect(stringToPluginServerMode['invalid']).toEqual(undefined)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2022-07-20 14:16:13 +02:00
|
|
|
describe('capabilities', () => {
|
|
|
|
let hub: Hub
|
|
|
|
let piscina: Piscina
|
|
|
|
let closeHub: () => Promise<void>
|
2022-05-24 09:10:52 +02:00
|
|
|
|
2022-07-20 14:16:13 +02:00
|
|
|
beforeEach(async () => {
|
|
|
|
;[hub, closeHub] = await createHub({
|
|
|
|
LOG_LEVEL: LogLevel.Warn,
|
2022-05-24 09:10:52 +02:00
|
|
|
})
|
2022-11-01 17:01:08 +01:00
|
|
|
piscina = { run: jest.fn(), on: jest.fn() } as any
|
2022-07-20 14:16:13 +02:00
|
|
|
})
|
2022-05-24 09:10:52 +02:00
|
|
|
|
2022-07-20 14:16:13 +02:00
|
|
|
afterEach(async () => {
|
|
|
|
await closeHub()
|
|
|
|
})
|
2022-05-24 09:10:52 +02:00
|
|
|
|
2022-10-12 15:24:22 +02:00
|
|
|
describe('startGraphileWorker()', () => {
|
2022-07-20 14:16:13 +02:00
|
|
|
it('sets up pluginJob handler if processPluginJobs is on', async () => {
|
2022-11-01 17:01:08 +01:00
|
|
|
const graphileWorker = new GraphileWorker(hub)
|
|
|
|
jest.spyOn(graphileWorker, 'start').mockImplementation(jest.fn())
|
2022-07-20 14:16:13 +02:00
|
|
|
hub.capabilities.ingestion = false
|
|
|
|
hub.capabilities.processPluginJobs = true
|
2022-10-18 16:44:41 +02:00
|
|
|
hub.capabilities.pluginScheduledTasks = false
|
2022-07-20 14:16:13 +02:00
|
|
|
|
2022-11-01 17:01:08 +01:00
|
|
|
await startGraphileWorker(hub, graphileWorker, piscina)
|
2022-07-20 14:16:13 +02:00
|
|
|
|
2022-11-01 17:01:08 +01:00
|
|
|
expect(graphileWorker.start).toHaveBeenCalledWith(
|
2022-10-18 16:44:41 +02:00
|
|
|
{
|
|
|
|
pluginJob: expect.anything(),
|
|
|
|
},
|
|
|
|
[]
|
|
|
|
)
|
2022-07-20 14:16:13 +02:00
|
|
|
})
|
|
|
|
|
2022-10-18 16:44:41 +02:00
|
|
|
it('sets up scheduled task handlers if pluginScheduledTasks is on', async () => {
|
2022-11-01 17:01:08 +01:00
|
|
|
const graphileWorker = new GraphileWorker(hub)
|
|
|
|
jest.spyOn(graphileWorker, 'start').mockImplementation(jest.fn())
|
2022-10-18 16:44:41 +02:00
|
|
|
|
|
|
|
hub.capabilities.ingestion = false
|
|
|
|
hub.capabilities.processPluginJobs = false
|
|
|
|
hub.capabilities.pluginScheduledTasks = true
|
|
|
|
|
2022-11-01 17:01:08 +01:00
|
|
|
await startGraphileWorker(hub, graphileWorker, piscina)
|
2022-10-18 16:44:41 +02:00
|
|
|
|
2022-11-01 17:01:08 +01:00
|
|
|
expect(graphileWorker.start).toHaveBeenCalledWith(
|
2022-10-18 16:44:41 +02:00
|
|
|
{
|
|
|
|
runEveryMinute: expect.anything(),
|
|
|
|
runEveryHour: expect.anything(),
|
|
|
|
runEveryDay: expect.anything(),
|
|
|
|
},
|
|
|
|
[
|
|
|
|
{
|
|
|
|
identifier: 'runEveryMinute',
|
|
|
|
options: {
|
|
|
|
backfillPeriod: 0,
|
|
|
|
maxAttempts: 1,
|
|
|
|
},
|
|
|
|
pattern: '* * * * *',
|
|
|
|
task: 'runEveryMinute',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
identifier: 'runEveryHour',
|
|
|
|
options: {
|
|
|
|
backfillPeriod: 0,
|
|
|
|
maxAttempts: 5,
|
|
|
|
},
|
|
|
|
pattern: '0 * * * *',
|
|
|
|
task: 'runEveryHour',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
identifier: 'runEveryDay',
|
|
|
|
options: {
|
|
|
|
backfillPeriod: 0,
|
|
|
|
maxAttempts: 10,
|
|
|
|
},
|
|
|
|
pattern: '0 0 * * *',
|
|
|
|
task: 'runEveryDay',
|
|
|
|
},
|
|
|
|
]
|
|
|
|
)
|
2022-07-20 14:16:13 +02:00
|
|
|
})
|
|
|
|
})
|
2022-05-24 09:10:52 +02:00
|
|
|
})
|