Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Triggering or Stopping Multiple Cron Jobs results in Error #3

Open
rsromanowski opened this issue Oct 25, 2023 · 2 comments
Open

Triggering or Stopping Multiple Cron Jobs results in Error #3

rsromanowski opened this issue Oct 25, 2023 · 2 comments

Comments

@rsromanowski
Copy link
Contributor

Example test to reproduce

describe('Mulitple Cron', () => {
    it('run cronjobs', async () => {
        let done1 = false
        let done2 = false

        new Elysia().use(
            cron({
                pattern: '*/1 * * * * *',
                name: 'job_1',
                run() {
                    done1 = true
                }
            })
        ).use(
            cron({
                pattern: '*/1 * * * * *',
                name: 'job_2',
                run() {
                    done2 = true
                }
            })
        )

        await new Promise((resolve) => setTimeout(resolve, 1100))

        expect(done1).toBe(true)
        expect(done2).toBe(true)
    })
    it('stop cronjobs', async () => {
        let done1 = false
        let done2 = false

        const app = new Elysia()
            .use(
                cron({
                    pattern: '*/1 * * * * *',
                    name: 'job_1',
                    run() {
                        done1 = true
                    }
                })
            ).use(
                cron({
                    pattern: '*/1 * * * * *',
                    name: 'job_2',
                    run() {
                        done2 = true
                    }
                })
            )
            .get('/stop', ({ store }) => {
                store.cron.job_1.stop()
                store.cron.job_2.stop()

                return 'stop'
            })

        await app.handle(req('/stop'))

        expect(done1).toBe(false)
        expect(done2).toBe(false)
    })
})

results in error: TypeError: undefined is not an object (evaluating 'store.cron.job_2.stop')

@rsromanowski
Copy link
Contributor Author

First test passes, second test fails. In second test, job_1 is successfully stopped

@rsromanowski
Copy link
Contributor Author

Root cause found: multiple calls to app.state('key', 'value') do not update the value of the key

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant