package cn.axzo.workflow.server.conf;

import cn.axzo.workflow.core.conf.CustomEventManager;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PreDestroy;

/**
 * 应用内事件处理
 *
 * @author wangli
 * @since 2025-04-07 17:09
 */
@Configuration
public class ShutdownConfig {

    private final CustomEventManager eventManager;

    public ShutdownConfig(CustomEventManager eventManager) {
        this.eventManager = eventManager;
    }

    @PreDestroy
    public void close() throws InterruptedException {
        System.out.println("Closing application, waiting for events to be processed...");
        eventManager.waitForEventsToBeProcessed();
        System.out.println("All events have been processed.");
    }
}