Commits

Doug Burke committed 17d05e6

Fixed bug where would wait a max of 2147 s between searchs

Comments (0)

Files changed (4)

+Version 0.0.0.7
+
+Fixed issue where code would not wait as long as requested between
+searches.
+
 Version 0.0.0.6
 
 Try to retain the page-by-100 value for Twitter search results
 import Paths_grabtweets (version)
 import Data.Version (showVersion)
 
+{-
+Since Int has an upper bound there is a limit, which
+is 2147 seconds plus change on OS-X.
+-}
+
+maxDelay :: Int
+maxDelay = floor $ fromIntegral (maxBound :: Int) / (1.0e6::Float)
+
+waitBounded :: Int -> IO ()
+waitBounded = threadDelay . (1000000 *)
+  
+-- do not need to use Integer here for this script ;-)
 wait :: Int -> IO ()
-wait = threadDelay . (1000000 *)
-  
+wait n | n <= maxDelay = waitBounded n
+       | otherwise = waitBounded maxDelay >> 
+                     wait (n - maxDelay)
+       
 {-  
 Return the action's value or, if it takes 
 longer than timeout seconds, Nothing.
     regularly
 
   - dump to ASCII files rather than have a more-robust system
-    such as a database
+    such as a database, although I'm tempted to try storing
+    them in a Riak instance just because ...
 
-The code does not deal well with
+  - there is a rather cavalier approach to error handling,
+    which can be summarised as "ignore it and try again later"
 
-  - errors (in particular there is a known hole if an error occurs
-    whilst processing a page of search results when multiple pages
-    are returned; tweets will not be recorded in this case)
-
-  - being re-started
-
 Name:           grabtweets
-Version:        0.0.0.6
+Version:        0.0.0.7
 Stability:      experimental
 License:        LGPL
 License-file:   LICENSE