package com.docus.server.common;

import com.docus.infrastructure.redis.listener.RedisKeyExpirationListener;
import com.docus.server.service.impl.RedisKeyExpirationService;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class RedisCollectorTaskKeyExpirationListener extends RedisKeyExpirationListener {

    @Resource
    private RedisKeyExpirationService redisKeyExpirationService;

    public RedisCollectorTaskKeyExpirationListener(RedisMessageListenerContainer listenerContainer) {
        super(listenerContainer);
    }

    @Override
    protected void processExpireKey(String expireKey) {
        redisKeyExpirationService.expired(expireKey);
    }

    @Override
    protected boolean validExpireKey(String expireKey) {
        return expireKey.startsWith("schCollectorRecord:noRetryTask:expireKey:")
            || expireKey.startsWith("schCollectorRecord:isRetryTask:expireKey:");
    }
}
