← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 22181: Moved initialization of FileResourceCleanUpTask from FileResourceService to SchedulingManager

 

------------------------------------------------------------
revno: 22181
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2016-03-08 10:11:11 +0100
message:
  Moved initialization of FileResourceCleanUpTask from FileResourceService to SchedulingManager
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/fileresource/DefaultFileResourceService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/fileresource/FileResourceCleanUpTask.java
  dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/scheduling/DefaultSchedulingManager.java


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/fileresource/DefaultFileResourceService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/fileresource/DefaultFileResourceService.java	2016-01-15 17:50:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/fileresource/DefaultFileResourceService.java	2016-03-08 09:11:11 +0000
@@ -40,7 +40,6 @@
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.concurrent.ListenableFuture;
 
-import javax.annotation.PostConstruct;
 import java.io.File;
 import java.net.URI;
 import java.util.List;
@@ -55,8 +54,6 @@
 {
     private static final Log log = LogFactory.getLog(DefaultFileResourceService.class);
 
-    private static final String KEY_FILE_CLEANUP_TASK = "fileResourceCleanupTask";
-
     private static final Duration IS_ORPHAN_TIME_DELTA = Hours.TWO.toStandardDuration();
 
     private static final Predicate<FileResource> IS_ORPHAN_PREDICATE =
@@ -94,27 +91,6 @@
         this.uploadCallback = uploadCallback;
     }
 
-    private FileResourceCleanUpTask fileResourceCleanUpTask;
-
-    public void setFileResourceCleanUpTask( FileResourceCleanUpTask fileResourceCleanUpTask )
-    {
-        this.fileResourceCleanUpTask = fileResourceCleanUpTask;
-    }
-
-    // -------------------------------------------------------------------------
-    // Init
-    // -------------------------------------------------------------------------
-
-    @PostConstruct
-    public void init()
-    {
-        // Background task which queries for non-assigned or failed-upload
-        // FileResources and deletes them from the database and/or file store.
-        // Runs every day at 2 AM server time.
-
-        scheduler.scheduleTask( KEY_FILE_CLEANUP_TASK, fileResourceCleanUpTask, Scheduler.CRON_DAILY_2AM );
-    }
-
     // -------------------------------------------------------------------------
     // FileResourceService implementation
     // -------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/fileresource/FileResourceCleanUpTask.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/fileresource/FileResourceCleanUpTask.java	2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/fileresource/FileResourceCleanUpTask.java	2016-03-08 09:11:11 +0000
@@ -38,13 +38,16 @@
 import java.util.List;
 
 /**
- * Deletes any orphaned FileResources.
+ * Deletes any orphaned FileResources. Queries for non-assigned or failed-upload
+ * FileResources and deletes them from the database and/or file store.
  *
  * @author Halvdan Hoem Grelland
  */
 public class FileResourceCleanUpTask
     implements Runnable
 {
+    public static final String KEY_TASK = "fileResourceCleanupTask";
+    
     private static final Log log = LogFactory.getLog( FileResourceCleanUpTask.class );
 
     @Autowired

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml	2016-03-07 21:12:22 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml	2016-03-08 09:11:11 +0000
@@ -648,7 +648,6 @@
     <property name="fileResourceContentStore" ref="org.hisp.dhis.fileresource.FileResourceContentStore" />
     <property name="scheduler" ref="scheduler" />
     <property name="uploadCallback" ref="org.hisp.dhis.fileresource.FileResourceUploadCallback" />
-    <property name="fileResourceCleanUpTask" ref="org.hisp.dhis.fileresource.FileResourceCleanUpTask" />
   </bean>
 
   <bean id="org.hisp.dhis.dataelement.DataElementOperandService" class="org.hisp.dhis.dataelement.DefaultDataElementOperandService">

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/scheduling/DefaultSchedulingManager.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/scheduling/DefaultSchedulingManager.java	2016-03-07 18:04:27 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/scheduling/DefaultSchedulingManager.java	2016-03-08 09:11:11 +0000
@@ -34,10 +34,12 @@
 import java.util.Set;
 
 import org.hisp.dhis.common.ListMap;
+import org.hisp.dhis.fileresource.FileResourceCleanUpTask;
 import org.hisp.dhis.setting.SettingKey;
 import org.hisp.dhis.setting.SystemSettingManager;
 import org.hisp.dhis.system.scheduling.ScheduledTaskStatus;
 import org.hisp.dhis.system.scheduling.Scheduler;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.ApplicationListener;
 import org.springframework.context.event.ContextRefreshedEvent;
 
@@ -75,6 +77,9 @@
         this.tasks = tasks;
     }
     
+    @Autowired
+    private FileResourceCleanUpTask fileResourceCleanUpTask;
+    
     // TODO Avoid map, use bean identifier directly and get bean from context
 
     // -------------------------------------------------------------------------
@@ -85,6 +90,7 @@
     public void onApplicationEvent( ContextRefreshedEvent contextRefreshedEvent )
     {
         scheduleTasks();
+        scheduleFixedTasks();
     }
     
     @Override
@@ -103,6 +109,11 @@
         }
     }
     
+    private void scheduleFixedTasks()
+    {
+        scheduler.scheduleTask( FileResourceCleanUpTask.KEY_TASK, fileResourceCleanUpTask, Scheduler.CRON_DAILY_2AM );
+    }
+    
     @Override
     public void scheduleTasks( ListMap<String, String> cronKeyMap )
     {