Skip to content
This repository was archived by the owner on Mar 20, 2024. It is now read-only.

Commit

Permalink
Refinements
Browse files Browse the repository at this point in the history
* Return a Mono<ResponseEntity> and order results in /report endpoint
* Let cron schedule manage invocation of tasks, don't immediately invoke after startup
* Add a short delay to allow for assembly of aggregate portions of results in /report endpoint
  • Loading branch information
pacphi committed Dec 6, 2018
1 parent 082fccb commit a4535bd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package io.pivotal.cfapp.controller;

import java.time.Duration;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

Expand All @@ -26,21 +29,22 @@ public ServiceInfoController(
}

@GetMapping(value = { "/report" }, produces = MediaType.TEXT_PLAIN_VALUE )
public Mono<String> generateReport() {
public Mono<ResponseEntity<String>> generateReport() {
return service
.findAll()
.collectList()
.map(r -> new ServiceInfoRetrievedEvent(this)
.detail(r)
.serviceCounts(service.countServicesByType())
.organizationCounts(service.countServicesByOrganization())
)
.map(event ->
)
.delayElement(Duration.ofMillis(500))
.map(event -> ResponseEntity.ok(
String.join(
"\n\n",
report.generatePreamble(),
report.generateDetail(event),
report.generateSummary(event)));
report.generateSummary(event))));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public Mono<ServiceDetail> save(ServiceDetail entity) {
}

public Flux<ServiceDetail> findAll() {
String selectAll = "select id, organization, space, name, service, description, plan, type, bound_applications, last_operation, last_updated, dashboard_url, requested_state from service_detail";
String selectAll = "select id, organization, space, name, service, description, plan, type, bound_applications, last_operation, last_updated, dashboard_url, requested_state from service_detail order by organization, space, service, name";
Flowable<ServiceDetail> result = database
.select(selectAll)
.get(rs -> ServiceDetail
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public ServiceInstanceInfoTask(

@Override
public void run(ApplicationArguments args) throws Exception {
runTask();
// do nothing; cron managed
}

@Scheduled(cron = "${cron}")
Expand Down

0 comments on commit a4535bd

Please sign in to comment.