package com.github.italia.daf;

import com.github.italia.daf.metabase.HTTPClient;
import com.github.italia.daf.util.Configuration;
import com.github.italia.daf.util.LoggerFactory;
import redis.clients.jedis.Jedis;

import java.io.IOException;
import java.net.URL;
import java.util.Properties;
import java.util.logging.Logger;

public class Seeder {
    private static final Logger LOGGER = LoggerFactory.getLogger( CacheWorker.class.getName() );
    public static void main(String[] args) throws IOException {
        final Properties properties = new Configuration(args[0]).load();
        final Jedis jedis = new Jedis(properties.getProperty("caching.redis_host"));

        Runtime.getRuntime().addShutdownHook(new Thread(() -> jedis.close()));

        HTTPClient client = new HTTPClient(
                new URL(properties.getProperty("metabase.api_endpoint")),
                new HTTPClient.Token(properties.getProperty("metabase.api_token")));

        do {
            LOGGER.info("Fetch all public cards");
            for (final HTTPClient.Card card : client.getPublicCards()) {
                LOGGER.info("Card id " + card.public_uuid + " enqueued for caching");
                jedis.lpush("metabase-cacher:jobs", card.public_uuid);
            }

            try {
                LOGGER.info("Sleeping until the next iteration");
                Thread.sleep(Integer.parseInt(properties.getProperty("caching.refresh_every")) * 1000 * 60);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        } while (true);

    }
}

@@ -286,16 +286,68 @@
 erties;%0A
+import java.util.Timer;%0Aimport java.util.TimerTask;%0A
 import j
@@ -802,16 +802,22 @@
         
+final 
 HTTPClie
@@ -1016,13 +1016,105 @@
     
-do %7B%0A
+new Timer().schedule(new TimerTask() %7B%0A            @Override%0A            public void run() %7B%0A    
     
@@ -1156,24 +1156,54 @@
 ic cards%22);%0A
+                try %7B%0A        
             
@@ -1259,24 +1259,32 @@
 cCards()) %7B%0A
+        
             
@@ -1373,16 +1373,24 @@
         
+ 
+       
 jedis.lp
@@ -1452,28 +1452,118 @@
     
+     
-%7D%0A%0A            try %7B
+   %7D%0A                %7D catch (IOException e) %7B%0A                    e.printStackTrace();%0A                %7D
 %0A   
@@ -1633,24 +1633,30 @@
         
+    %7D%0A
         
 Thread.s
@@ -1651,21 +1651,15 @@
     
-Thread.sleep(
+%7D, 0,  
 Inte
@@ -1738,129 +1738,8 @@
 0);%0A
-            %7D catch (InterruptedException e) %7B%0A                e.printStackTrace();%0A            %7D%0A        %7D while (true);
 %0A%0A  

Replace pooling with task