package es.uv.dagarcos.master.scheduler;

import es.uv.dagarcos.master.domain.Shard;
import es.uv.dagarcos.master.service.ShardService;
import es.uv.dagarcos.master.service.ShardWorldSnapshotService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class ShardWorldSnapshotScheduler {

    @Autowired
    private ShardService shardService;
    @Autowired
    private ShardWorldSnapshotService snapshotService;

    @Scheduled(fixedRateString = "${master.snapshot.interval:120000}")
    public void takeSnapshots() {

        for (Shard shard : shardService.findAll()) {
            snapshotService.createSnapshot(shard);
        }
    }
}