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

[FIX] Apps-Engine's scheduler failing to update run tasks #22882

Merged
merged 8 commits into from
Aug 13, 2021

Conversation

thassiov
Copy link
Contributor

@thassiov thassiov commented Aug 6, 2021

Proposed changes (including videos or screenshots)

Agenda, the library that manages scheduling, depended on setting a job property named nextRunAt as undefined to signal whether it should be run on schedule or not. Rocket.Chat's current Mongo driver ignores undefined values when updating documents and this was causing jobs to never stop running as Agenda couldn't clear that property (set them as undefined).
This updates Rocket.Chat's dependency on Agenda.js to point to a fork that fixes the problem.

Issue(s)

Steps to test or reproduce

Starting from Rocket.Chat@3.17.0:

Install this example app. At startup, it creates a job that should run only once 10 seconds after it is registered.
schedule-once_0.0.1.zip

It runs every 5 seconds (minimum amount of time allowed by Agenda) indefinitely.

Further comments

First iteration:

Make mongo driver's configuration about bson types explicit so undefined fields are recognized and not dropped by the query parser. The issue started happening after Meteor's 2.2 update.

Agenda, the Apps Engine's dependency that manages apps scheduling, needs this feature as it depends on setting certain values as undefined when updating documents. For the case of tasks that run only once, the property nextRunAt, that determines if a job must be run in the future, is never set to undefined, thus making the scheduler run it indefinitely.

Somewhere down the dependency tree some function is ignoring or changing this value. As of right now we couldn't identify where, but it prevented updates with fields having undefined as their values. The problem is solved when we set this mongodb property explicitly.

Related documentation:

Node.js MongoDB Driver API: https://mongodb.github.io/node-mongodb-native/3.6/api/Db.html

Second iteration (current):

Fix agenda.js itself and update Rocket.Chat's dependency to the fixed version.

@thassiov thassiov requested a review from a team August 6, 2021 23:24
Copy link
Member

@sampaiodiego sampaiodiego left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this change is breaking some endpoints, can you please take a look?

@d-gubert d-gubert changed the title [FIX] Apps Engine's scheduler failing to update run tasks [FIX] Apps-Engine's scheduler failing to update run tasks Aug 9, 2021
@thassiov thassiov requested a review from sampaiodiego August 9, 2021 16:49
@d-gubert d-gubert dismissed sampaiodiego’s stale review August 11, 2021 20:23

Approach has changed since review

@sampaiodiego sampaiodiego added this to the 3.17.1 milestone Aug 13, 2021
@sampaiodiego sampaiodiego merged commit 127a102 into develop Aug 13, 2021
@sampaiodiego sampaiodiego deleted the fix/apps-engine-scheduler-update-fail branch August 13, 2021 18:46
sampaiodiego pushed a commit that referenced this pull request Aug 16, 2021
Co-authored-by: Douglas Gubert <douglas.gubert@gmail.com>
@sampaiodiego sampaiodiego mentioned this pull request Aug 16, 2021
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

Successfully merging this pull request may close these issues.

3 participants