I’m having a problem with my rake task hanging in an infinite loop. So far, I’ve been able to isolate the problem to a piece of code converting a date range to an array. Even if I directly invoke this:
(1.month.ago.beginning_of_month..1.month.ago.end_of_month).to_a.each {|d| p d}
the task hangs iterating over the same elements forever:
"2012-06-01 00:40:41 UTC"
"2012-06-01 00:40:41 UTC"
"2012-06-01 00:40:41 UTC"
"2012-06-01 00:40:41 UTC"
"2012-05-31 20:40:41 UTC"
"2012-05-31 20:40:41 UTC"
"2012-06-01 00:40:42 UTC"
"2012-06-01 00:40:42 UTC"
"2012-06-01 00:40:42 UTC"
"2012-06-01 00:40:42 UTC"
"2012-05-31 20:40:42 UTC"
"2012-05-31 20:40:42 UTC"
...
If instead I use this
(Date.new(2012,6,1)..Date.new(2012,6,30)).to_a.each {|d| p d}
everything works, so it has to be something with using ActiveSupport extensions for Date/Time specifically. Has anyone else seen this?
This happens in development environment on a Windows box with Rails 3.1 and Ruby 1.9.3, if that matters.
You are creating a
Timerange for a month with 1 second increments and ~2.5 million entries:To create a
Daterange use: