刘光辉
118 分钟以前 06f314545ac3514d7ce28939920866ae8188d31c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package jnpf.dmsService;
 
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
 
/** Recovery consumes proven native terminal states; never expires a lease by age. */
@Service
@Slf4j
@RequiredArgsConstructor
public class DmsBusinessOccupancyTerminationJob {
    private final DmsBusinessLifecycleGuard guard;
    @Scheduled(cron="${dms.business-occupancy.termination-cron:0 * * * * ?}")
    public void releaseEndedApplications() {
        String after=null;
        for(int page=0;page<100;page++) {
            var rows=guard.terminationCandidates(after,100);
            for(var row:rows) try { guard.releaseEnded(row); }
            catch(RuntimeException error) { log.error("DMS terminal occupancy release failed tenant={} receipt={}",row.getTenantId(),row.getId(),error); }
            if(rows.size()<100) return;
            after=rows.get(rows.size()-1).getId();
        }
    }
}