package org.sagebionetworks.dashboard;

import javax.annotation.Resource;

import org.sagebionetworks.dashboard.dao.AccessRecordDao;
import org.sagebionetworks.dashboard.dao.AccessRecordEntityDao;
import org.sagebionetworks.dashboard.dao.LogFileDao;
import org.sagebionetworks.dashboard.dao.RawAccessRecordDao;
import org.sagebionetworks.dashboard.service.AccessRecordWorker;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component("accessRecordScheduler")
public class AccessRecordScheduler {

    private final Logger logger = LoggerFactory.getLogger(AccessRecordScheduler.class);

    @Resource
    private RawAccessRecordDao rawAccessRecordDao;

    @Resource
    private LogFileDao logFileDao;

    @Resource
    private AccessRecordWorker accessRecordWorker;

    @Resource
    private AccessRecordDao accessRecordDao;

    @Resource
    private AccessRecordEntityDao accessRecordEntityDao;

    /**
     * Copy the access record log files in S3 buckets to raw_access_record.
     * Initial delay of 0 minutes. Updates every 1.5 minutes.
     */
    @Scheduled(initialDelay=(0L * 60L * 1000L), fixedRate=(90L * 1000L))
    public void runRawRecordWorker() {
        logger.info(rawAccessRecordDao.count() + " raw access records, " +
                logFileDao.count() + " log files.");
        accessRecordWorker.copy();
    }
/*
    *//**
     * Update the access_record table.
     * Initial delay of 1.5 minutes. Updates every 3 minutes.
     *//*
    @Scheduled(initialDelay=(90L * 1000L), fixedRate=(3L * 60L * 1000L))
    public void runRecordWorker() {
        logger.info(accessRecordDao.count() + " access records.");
        accessRecordWorker.update();
    }

    *//**
     * Update the access_record_entity table.
     * Initial delay of 3 minutes. Updates every 3 minutes.
     *//*
    @Scheduled(initialDelay=(3L * 60L * 1000L), fixedRate=(3L * 60L * 1000L))
    public void updateEntityLookupTable() {
        logger.info(accessRecordEntityDao.count() + " entity lookup records.");
        accessRecordWorker.updateEntityLookupTable();
    }

    *//**
     * Clean up the access_record table.
     * Initial delay of 30 minutes. Updates every 4 hours.
     *//*
    @Scheduled(initialDelay=(30L * 60L * 1000L), fixedRate=(4* 60L * 60L * 1000L))
    public void vacuumAccessRecord() {
        accessRecordWorker.vacuumAccessRecord();
    }

    *//**
     * Clean up the raw_access_record table.
     * Initial delay of 30 minutes. Updates every 4 hours.
     *//*
    @Scheduled(initialDelay=(30L * 60L * 1000L), fixedRate=(4* 60L * 60L * 1000L))
    public void vacuumRawAccessRecord() {
        accessRecordWorker.vacuumRawAccessRecord();
    }

    *//**
     * Clean up the access_record_entity table.
     * Initial delay of 30 minutes. Updates every 4 hours.
     *//*
    @Scheduled(initialDelay=(30L * 60L * 1000L), fixedRate=(4* 60L * 60L * 1000L))
    public void vacuumEntityLookupTable() {
        accessRecordWorker.vacuumEntityLookupTable();
    }

    *//**
     * Clean up the log_file table.
     * Initial delay of 30 minutes. Updates every 4 hours.
     *//*
    @Scheduled(initialDelay=(30L * 60L * 1000L), fixedRate=(4* 60L * 60L * 1000L))
    public void vacuumLogFile() {
        accessRecordWorker.vacuumLogFile();
    }*/
}

@@ -1452,17 +1452,13 @@
   %7D%0A
-/*
 %0A    
-*/
 /**%0A
@@ -1543,33 +1543,30 @@
 dates every 
-3 minutes
+1 hour
 .%0A     *//*%0A
@@ -1554,34 +1554,32 @@
  1 hour.%0A     */
-/*
 %0A    @Scheduled(
@@ -1609,35 +1609,35 @@
 0L), fixedRate=(
-3L 
+60L
 * 60L * 1000L))%0A
@@ -1785,1602 +1785,7 @@
    %7D
-%0A%0A    *//**%0A     * Update the access_record_entity table.%0A     * Initial delay of 3 minutes. Updates every 3 minutes.%0A     *//*%0A    @Scheduled(initialDelay=(3L * 60L * 1000L), fixedRate=(3L * 60L * 1000L))%0A    public void updateEntityLookupTable() %7B%0A        logger.info(accessRecordEntityDao.count() + %22 entity lookup records.%22);%0A        accessRecordWorker.updateEntityLookupTable();%0A    %7D%0A%0A    *//**%0A     * Clean up the access_record table.%0A     * Initial delay of 30 minutes. Updates every 4 hours.%0A     *//*%0A    @Scheduled(initialDelay=(30L * 60L * 1000L), fixedRate=(4* 60L * 60L * 1000L))%0A    public void vacuumAccessRecord() %7B%0A        accessRecordWorker.vacuumAccessRecord();%0A    %7D%0A%0A    *//**%0A     * Clean up the raw_access_record table.%0A     * Initial delay of 30 minutes. Updates every 4 hours.%0A     *//*%0A    @Scheduled(initialDelay=(30L * 60L * 1000L), fixedRate=(4* 60L * 60L * 1000L))%0A    public void vacuumRawAccessRecord() %7B%0A        accessRecordWorker.vacuumRawAccessRecord();%0A    %7D%0A%0A    *//**%0A     * Clean up the access_record_entity table.%0A     * Initial delay of 30 minutes. Updates every 4 hours.%0A     *//*%0A    @Scheduled(initialDelay=(30L * 60L * 1000L), fixedRate=(4* 60L * 60L * 1000L))%0A    public void vacuumEntityLookupTable() %7B%0A        accessRecordWorker.vacuumEntityLookupTable();%0A    %7D%0A%0A    *//**%0A     * Clean up the log_file table.%0A     * Initial delay of 30 minutes. Updates every 4 hours.%0A     *//*%0A    @Scheduled(initialDelay=(30L * 60L * 1000L), fixedRate=(4* 60L * 60L * 1000L))%0A    public void vacuumLogFile() %7B%0A        accessRecordWorker.vacuumLogFile();%0A    %7D*/
 %0A%7D%0A

clean up scheduler