@Scheduled(fixedDelay = 10 * 60 * 1000) // 10 minutes - in milliseconds private void scheduledTaskUpdateCollections() { List<AidrCollection> collections; try { collections = collectionService.getRunningCollections(); } catch (Exception e) { logger.error("Error while executing update collections scheduled task", e); taggerService.sendMailService( "Error in ScheduledTask", "Error while executing update collections scheduled task in ScheduledTask.scheduledTaskUpdateCollections"); return; } if (collections != null) { logger.info( "Update collections scheduled task started for " + collections.size() + " collections"); for (AidrCollection item : collections) { try { collectionService.statusByCollection(item); } catch (Exception e) { logger.error("Error while updating collection with ID: " + item.getId(), e); taggerService.sendMailService( "Error in ScheduledTask", "Error while executing updating collection with ID: " + item.getId() + " in ScheduledTask.scheduledTaskUpdateCollections"); } } } logger.info("Update collections scheduled task completed."); }
private CollectionSummaryInfo adaptCollectionToCollectionSummaryInfo(Collection collection) { CollectionSummaryInfo summaryInfo = new CollectionSummaryInfo(); summaryInfo.setCode(collection.getCode()); summaryInfo.setName(collection.getName()); summaryInfo.setCurator(collection.getOwner().getUserName()); summaryInfo.setStartDate(collection.getStartDate()); summaryInfo.setEndDate(collection.getEndDate()); summaryInfo.setCollectionCreationDate(collection.getCreatedAt()); // TODO to fetch from collection log try { summaryInfo.setTotalCount( collectionLogService.countTotalDownloadedItemsForCollection(collection.getId())); } catch (Exception e) { logger.warn("Error in fetch count from collection log.", e); summaryInfo.setTotalCount(collection.getCount()); } summaryInfo.setStatus(collection.getStatus().getStatus()); // TODO summaryInfo.setCreatedAt(collection.getCreatedAt()); summaryInfo.setLanguage(collection.getLangFilters()); summaryInfo.setKeywords(collection.getTrack()); summaryInfo.setGeo(collection.getGeo()); summaryInfo.setLabelCount(taggerService.getLabelCount(collection.getId())); summaryInfo.setPubliclyListed(collection.isPubliclyListed()); summaryInfo.setProvider(collection.getProvider().toString()); return summaryInfo; }
@Scheduled(cron = "0 0 * * * *") // each hour private void scheduledTaskStopCollections() { List<AidrCollection> collections; try { collections = collectionService.getRunningCollections(); } catch (Exception e) { logger.error("Error while executing checking for collections running duration", e); taggerService.sendMailService( "Error in ScheduledTask", "Error while executing checking for collections running duration in ScheduledTask.scheduledTaskStopCollections"); return; } if (collections != null) { logger.info( "Checking for collections running duration started for " + collections.size() + " running collections"); for (AidrCollection item : collections) { Date stopAtTime = new Date(item.getStartDate().getTime() + item.getDurationHours() * HOUR); Date current = new Date(); if (current.compareTo(stopAtTime) > 0) { try { collectionService.stop(item.getId()); logger.info( "Collection with ID: " + item.getId() + " was automatically stopped as it reached duration interval."); } catch (Exception e) { logger.info("Error while stopping collection with ID: " + item.getId(), e); taggerService.sendMailService( "Error in ScheduledTask", "Error while stopping collection with ID: " + item.getId() + " in ScheduledTask.scheduledTaskStopCollections"); } } } } logger.info("Checking for collections running duration completed."); }