global class NFM609Schedule implements Schedulable {

    public  String objectType;
    global NFM609Schedule(String objectType){
        this.objectType = objectType;
    }
    global void execute(SchedulableContext SC) {
        System.debug('objectType---->'+objectType);
        Id execBTId = Database.executeBatch(new NFM609FiledDownloadBatch(objectType), 1);
    }

    public static void assignOneMinute(String objectType) {
        // delete 実行済み
        for (CronTrigger ct :
                [SELECT Id FROM CronTrigger WHERE CronJobDetail.Name like 'AttachmentDownload%']) {
            System.abortJob(ct.id);
        }
        Datetime addOneM = System.now().addMinutes(1);
        String CRON_EXP = '0 ' + addOneM.minute() + ' ' + addOneM.hour() + ' ' + addOneM.day() + ' ' + addOneM.month() + ' ? ' + addOneM.year();
        List<CronTrigger> oldcron = [select Id from CronTrigger where State = 'WAITING' and CronJobDetail.Name like 'AttachmentDownload%'];
        
        if (oldcron.size() == 0) {
            System.schedule('AttachmentDownload' + CRON_EXP, CRON_EXP, new NFM609Schedule(objectType));
        }
        
    }
}