0

I'm using spring jobs in a Grails 5.2.5 application. This application serves to run X (defined by the reports.total configuration) reports at the same time.

For correct operation, the spring.task.scheduling.pool.size configuration must be equal to or greater than the total number of jobs, to comply with reports.total it would need to be 3+reports.total (the value is 3 because currently there are 3 jobs that need to run concurrently)

reports:
    total: 1

spring:
    task:
        scheduling:
            pool:
                size: 3+reports.total

I tried the following values, but without success:

  • ${reports.total} + 3
  • {${reports.total} + 3}
  • 3 + reports.total
  • ${reports.total + 3}
  • ${4+1}
  • 4+1
  • #{${reports.total} + 3}
  • $(( ${reports.total} + 3 ))

Always return something like this:

Failed to bind properties under 'spring.task.scheduling.pool.size' to int:

    Property: spring.task.scheduling.pool.size
    Value: ${4+1}
    Origin: "spring.task.scheduling.pool.size" from property source "Config resource 'class path resource [application.yml]' via location 'optional:classpath:/'"
    Reason: failed to convert java.lang.String to int (caused by java.lang.NumberFormatException: For input string: "${4+1}")

Grails 5.2.5 - JDK 11.0.16

1 Answers1

1

Generally, you don't create calculated fields directly in a YAML file. However, if you need to include configuration data that is calculated or references classes in your application, you can add it to a runtime.groovy file.

The runtime.groovy file should be placed in the same location as your other configuration files. It is processed after your application classes are loaded, which means that you can include more complex configuration data in this file, including 'groovy' code.

David Brown
  • 3,021
  • 3
  • 26
  • 46
  • The `reports.total` configuration needs to be in the `application.yml` so that the technician can change it according to the server hardware during system deployment. I tried to move only the `spring.task.scheduling.pool.size` configuration to the runtime.groovy file, but the values contained in `application.yml` are inaccessible. P.S.: there are other settings required for `application.yml` to work, which is the default used by the company. – João G. Hartmann Apr 12 '23 at 13:51