Skip to content

Conversation

@pmady
Copy link
Contributor

@pmady pmady commented Dec 26, 2025

Summary

This PR adds a scheduled task to periodically call the recalculate_subs() database function, eliminating the need for an external cronjob on the database server.

Problem

Subscription accountability has a condition where, when running at large scale, values can become out of date. The recalculate_subs() function was added in PR #1380 to fix this, but it needs to be called on a schedule. Currently, this requires an external cronjob on the database server, which is not ideal.

Solution

This PR integrates the subscription recalculation into cuebot's existing Quartz scheduler infrastructure:

  1. MaintenanceTask enum - Added LOCK_SUBSCRIPTION_RECALCULATION for database-level locking to prevent concurrent execution across multiple cuebot instances
  2. MaintenanceDao - Added recalculateSubscriptions() method to call the PostgreSQL function
  3. MaintenanceManagerSupport - Added recalculateSubscriptions() method with proper locking
  4. Quartz configuration - Added job and trigger to run every 2 hours (configurable)
  5. Configuration property - Added maintenance.subscription_recalculation_interval_ms (default: 2 hours)
  6. Database migration - Added V35 migration to insert the task_lock entry

Configuration

The interval can be configured via the maintenance.subscription_recalculation_interval_ms property in opencue.properties. Default is 7200000 ms (2 hours), matching SPI's production setup.

Multi-instance Support

The implementation uses the existing task_lock mechanism to ensure only one cuebot instance runs the recalculation at a time, even in multi-instance deployments.

Closes #1562

@pmady pmady force-pushed the feature/subscription-recalculation-scheduler branch from 9d12277 to e090665 Compare December 26, 2025 20:44
@pmady
Copy link
Contributor Author

pmady commented Dec 26, 2025

CI Failure Analysis

The failing checks (Build Cuebot and Run Unit Tests and Run Integration Test) are due to transient infrastructure issues with the Spring repository, not related to the code changes in this PR.

Error Details

The build is failing with HTTP 401 errors when trying to access repo.spring.io/plugins-snapshot:

Failed to get resource: GET. [HTTP HTTP/1.1 401 : https://repo.spring.io/plugins-snapshot/org/eclipse/ee4j/project/1.0.5/project-1.0.5.pom)]
Failed to get resource: GET. [HTTP HTTP/1.1 401 : https://repo.spring.io/plugins-snapshot/org/springframework/spring-framework-bom/5.2.1.RELEASE/spring-framework-bom-5.2.1.RELEASE.pom)]

Verification

The latest master branch run (#20526703128) passed successfully, confirming this is a transient issue.

Request

Could a maintainer please re-run the failed jobs when the Spring repository is accessible again? Thank you!

@lithorus
Copy link
Collaborator

Looks like it fails the spotless java checks.

@DiegoTavares
Copy link
Collaborator

Just a heads up, this PR is still failing CICD with the following error. I'm moving it to Draft state. Please only remove the draft state when it is ready for review.

java.lang.IllegalArgumentException: Could not resolve placeholder 'maintenance.subscription_recalculation_interval_ms' in value "${maintenance.subscription_recalculation_interval_ms}"
                at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:178)
                at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:124)
                at org.springframework.beans.factory.config.PropertyPlaceholderConfigurer$PlaceholderResolvingStringValueResolver.resolveStringValue(PropertyPlaceholderConfigurer.java:230)
                at org.springframework.beans.factory.config.BeanDefinitionVisitor.resolveStringValue(BeanDefinitionVisitor.java:296)
                at org.springframework.beans.factory.config.BeanDefinitionVisitor.resolveValue(BeanDefinitionVisitor.java:217)
                at org.springframework.beans.factory.config.BeanDefinitionVisitor.visitPropertyValues(BeanDefinitionVisitor.java:147)
                at org.springframework.beans.factory.config.BeanDefinitionVisitor.visitBeanDefinition(BeanDefinitionVisitor.java:85)
                at org.springframework.beans.factory.config.PlaceholderConfigurerSupport.doProcessProperties(PlaceholderConfigurerSupport.java:225)
                ... 51 more

@DiegoTavares DiegoTavares marked this pull request as draft January 12, 2026 17:24
@pmady pmady force-pushed the feature/subscription-recalculation-scheduler branch from 3c533ee to 451337f Compare January 12, 2026 18:00
@pmady
Copy link
Contributor Author

pmady commented Jan 12, 2026

@DiegoTavares fixed the missing parameter, now CI looks good. Thanks

@pmady pmady force-pushed the feature/subscription-recalculation-scheduler branch from 451337f to 6f95890 Compare January 12, 2026 21:56
Add a scheduled task to periodically call the recalculate_subs() database
function, eliminating the need for an external cronjob on the database server.

Changes:
- Add MaintenanceTask enum for subscription recalculation
- Add DAO method to call recalculate_subs() function
- Add recalculateSubscriptions() to MaintenanceManagerSupport
- Add configuration property for subscription recalculation interval
- Configure Quartz scheduler for subscription recalculation
- Add database migration for subscription recalculation task lock
- Bump version to 1.17 for database migration
- Add missing test property for subscription recalculation

The task uses a database lock to ensure only one Cuebot instance runs
the recalculation at a time in multi-instance deployments.

Configuration:
  maintenance.subscription_recalculation_interval_ms (default: 7200000 = 2 hours)

Issue Number: close AcademySoftwareFoundation#1562

Signed-off-by: pmady <pavan4devops@gmail.com>
@pmady pmady force-pushed the feature/subscription-recalculation-scheduler branch from 15dc216 to c35b528 Compare January 13, 2026 03:09
@pmady pmady marked this pull request as ready for review January 18, 2026 03:16
@DiegoTavares
Copy link
Collaborator

@htehara and @ramonfigueiredo FYI

@DiegoTavares
Copy link
Collaborator

@htehara can you review the migrations to confirm a task_lock is the best mechanism to prevent multiple executions?

@DiegoTavares DiegoTavares merged commit 453d6f4 into AcademySoftwareFoundation:master Jan 23, 2026
22 checks passed
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.

Recalculate subs logic needs a cron trigger

3 participants