Skip to content

[Refactor] Rewrite the ExecutorService to a cron supported scheduler #5899

@ramonvermeulen

Description

@ramonvermeulen

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request. Searching for pre-existing feature requests helps us consolidate datapoints for identical requirements into a single place, thank you!
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request.
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment.

Describe the user story

Currently, Atlantis handles scheduled tasks through the ExecutorService, which manages two main use-cases:

  1. Publishing runtime stats every 10 seconds via RuntimeStatsCollector.
  2. Rotating GitHub tokens every 30 seconds via GithubTokenRotator.

While this works for current needs, the scheduling capabilities are quite basic and lack cron support. Enhancing this would make it easier to implement features like:

For both of these features it would be beneficial to have a scheduler with cron support on the server.

Describe the solution you'd like

I suggest replacing the ExecutorService with a ScheduleManager singleton that uses gocron Scheduler. Jobs would be registered with the ScheduleManager but remain fully decoupled from it. The gocron package provides:

The gocron package supports a variety of Job types, including a CronJob. Also it supports built-in mechanisms for Job queues and a lot more beneficial features for scheduling server-side tasks.

I did some drafting at: ramonvermeulen/atlantis@main...f/refactor-scheduler to illustrate the direction (note: this is an early proof of concept, and far from a full implementation).

Describe the drawbacks of your solution

  • Adds a new dependency: github.com/go-co-op/gocron (a well-maintained and widely used package, but still it is a new dependency)
  • Requires refactoring ExecutorService into ScheduleManager, which will need thorough testing to ensure GitHub token rotation and stats publishing continue working reliably.

Describe alternatives you've considered

I looked at making the scheduler completely separate from the Atlantis server (multi-container setup, similar to Airflow), but this would require significant changes and doesn't align with Atlantis's single-server approach.

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew functionality/enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions