initializr/initializr-service/app.groovy
Stephane Nicoll 4d2fbfe856 Publish stats on project generation
If an elastic instance is available, publish a document to a
configurable index every time a `ProjectRequest` is handled by the
service.

In practice, this means that every attempt to generate a project leads to
a new document in the index. The document gathers the settings of the
required project, including invalid ones if any. If an exception is
thrown, the message of the cause is made available.

CloudFlare is explicitely supported and the IP and country of the request
is added to the document. If that information is not available and the
request contains a `X-Forwarded-For` header, the value is also associated
with the document. If an IPv4 is detected, it is set in a separate
`requestIpv4` property.

If for some reason the document could not be indexed, we attempt to retry
a configurable amount of times.

Closes gh-185
2016-02-13 09:38:15 +01:00

37 lines
973 B
Groovy

package app
import java.util.concurrent.Executor
import org.springframework.context.annotation.Configuration
import org.springframework.scheduling.annotation.AsyncConfigurerSupport
import org.springframework.scheduling.annotation.EnableAsync
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor
import io.spring.initializr.web.LegacyStsController
@Grab('io.spring.initalizr:initializr:1.0.0.BUILD-SNAPSHOT')
@Grab('spring-boot-starter-redis')
class InitializerService {
@Bean
@SuppressWarnings("deprecation")
LegacyStsController legacyStsController() {
new LegacyStsController()
}
@Configuration
@EnableAsync
static class AsyncConfiguration extends AsyncConfigurerSupport {
@Override
Executor getAsyncExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor()
executor.setCorePoolSize(1)
executor.setMaxPoolSize(5)
executor.setThreadNamePrefix("initializr-")
executor.initialize()
executor
}
}
}