feedupdater 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ == FeedUpdater 0.2.2
2
+ * better distribution of work across threads
3
+ * fixed major threading bug
4
+ * added configuration variable for sleep time
1
5
  == FeedUpdater 0.2.1
2
6
  * no longer attempts to update feeds that have been updated very recently
3
7
  * fixed logging levels
@@ -9,6 +9,9 @@ load_script: example/custom_updater.rb
9
9
  # Never set it higher than 1 if you're on a shared server.
10
10
  threads: 5
11
11
 
12
+ # The amount of time to sleep between updates. Expressed in minutes.
13
+ sleep_time: 65
14
+
12
15
  # This is the path to store the pid files.
13
16
  pid_file_path: config
14
17
 
@@ -2,7 +2,7 @@ module FeedTools
2
2
  module FEED_UPDATER_VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 2
5
- TINY = 1
5
+ TINY = 2
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/lib/feed_updater.rb CHANGED
@@ -226,7 +226,8 @@ module FeedTools
226
226
  if !defined?(@updater_options) || @updater_options.nil?
227
227
  @updater_options = {
228
228
  :start_delay => true,
229
- :thread => 1,
229
+ :threads => 1,
230
+ :sleep_time => 60,
230
231
  :log_level => 0
231
232
  }
232
233
  end
@@ -334,7 +335,7 @@ module FeedTools
334
335
  # The main feed update loop.
335
336
  loop do
336
337
  result = nil
337
- sleepy_time = 1.hour
338
+ sleepy_time = self.updater_options[:sleep_time].to_i.minutes
338
339
  begin
339
340
  result = Benchmark.measure do
340
341
  self.update_feeds()
@@ -342,7 +343,9 @@ module FeedTools
342
343
  self.logger.info(
343
344
  "#{@feed_href_list.size} feed(s) updated " +
344
345
  "in #{result.real.round} seconds.")
345
- sleepy_time = 1.hour - result.real.round
346
+ sleepy_time =
347
+ (self.updater_options[:sleep_time].to_i.minutes -
348
+ result.real.round)
346
349
  rescue Exception => error
347
350
  self.logger.error("Feed update sequence errored out.")
348
351
  self.logger.error(error.class.name + ": " + error.message)
@@ -354,11 +357,14 @@ module FeedTools
354
357
  ObjectSpace.garbage_collect()
355
358
  if sleepy_time > 0
356
359
  self.logger.info(
357
- "Sleeping for #{(sleepy_time / 60.0).round} minutes...")
360
+ "Sleeping for #{(sleepy_time / 1.minute.to_f).round} " +
361
+ "minutes...")
358
362
  sleep(sleepy_time)
359
363
  else
360
364
  self.logger.info(
361
- "Update took more than 60 minutes, restarting immediately.")
365
+ "Update took more than " +
366
+ "#{self.updater_options[:sleep_time].to_i} minutes, " +
367
+ "restarting immediately.")
362
368
  end
363
369
  end
364
370
  end
@@ -432,6 +438,20 @@ module FeedTools
432
438
  self.start()
433
439
  end
434
440
 
441
+ def progress_precentage()
442
+ if !defined?(@remaining_href_list) || !defined?(@feed_href_list)
443
+ return nil
444
+ end
445
+ if @remaining_href_list.nil? || @feed_href_list.nil?
446
+ return nil
447
+ end
448
+ if @feed_href_list == []
449
+ return nil
450
+ end
451
+ return 100.0 - (100.0 *
452
+ (@remaining_href_list.size.to_f / @feed_href_list.size.to_f))
453
+ end
454
+
435
455
  # Updates all of the feeds.
436
456
  def update_feeds()
437
457
  self.logger.level = 0
@@ -467,22 +487,10 @@ module FeedTools
467
487
  end
468
488
  self.logger.info("Updating #{@feed_href_list.size} feed(s)...")
469
489
  self.logger.level = self.updater_options[:log_level]
470
- ObjectSpace.garbage_collect()
471
490
 
472
- threads = []
473
- thread_slices = []
474
- thread_slice_size =
475
- (@feed_href_list.size / self.updater_options[:threads])
491
+ @threads = []
492
+ @remaining_href_list = @feed_href_list.dup
476
493
 
477
- for i in 0...self.updater_options[:threads]
478
- if i != self.updater_options[:threads] - 1
479
- thread_slices << @feed_href_list[
480
- (i * thread_slice_size)...((i + 1) * thread_slice_size)]
481
- else
482
- thread_slices << @feed_href_list[
483
- (i * thread_slice_size)..-1]
484
- end
485
- end
486
494
  ObjectSpace.garbage_collect()
487
495
 
488
496
  begin_updating = false
@@ -501,7 +509,8 @@ module FeedTools
501
509
  Thread.pass
502
510
  end
503
511
  mutex.synchronize do
504
- self.logger.prefix = "Thread #{Thread.current.thread_id} ".ljust(20)
512
+ self.logger.prefix =
513
+ "Thread #{Thread.current.thread_id} ".ljust(20)
505
514
  self.logger.info("Thread started.")
506
515
 
507
516
  begin
@@ -512,23 +521,16 @@ module FeedTools
512
521
  rescue Exception => error
513
522
  self.logger.info(error)
514
523
  end
515
-
516
- self.logger.info(
517
- "Thread ##{Thread.current.thread_id} handling " +
518
- "#{thread_slices[Thread.current.thread_id].size} feeds...")
519
524
  end
520
525
 
521
526
  ObjectSpace.garbage_collect()
522
527
  Thread.pass
523
- href_list = thread_slices[Thread.current.thread_id]
524
528
 
525
- for i in 0...href_list.size
529
+ while @remaining_href_list.size > 0
526
530
  progress = nil
527
531
  mutex.synchronize do
528
- Thread.current.href = href_list[i]
529
- Thread.current.progress =
530
- (href_list.index(Thread.current.href).to_f /
531
- href_list.size.to_f) * 100
532
+ Thread.current.progress = self.progress_precentage()
533
+ Thread.current.href = @remaining_href_list.shift()
532
534
  progress = sprintf("%.2f", Thread.current.progress)
533
535
  end
534
536
  begin
@@ -594,7 +596,7 @@ module FeedTools
594
596
  Thread.pass
595
597
  end
596
598
  end
597
- threads << updater_thread
599
+ @threads << updater_thread
598
600
  class <<updater_thread
599
601
  attr_accessor :thread_id
600
602
  attr_accessor :progress
@@ -606,20 +608,20 @@ module FeedTools
606
608
  mutex.synchronize do
607
609
  self.logger.prefix = "FeedUpdater".ljust(20)
608
610
  self.logger.info(
609
- "#{threads.size} thread(s) successfully started...")
611
+ "#{@threads.size} thread(s) successfully started...")
610
612
  begin_updating = true
611
613
  end
612
614
  Thread.pass
613
615
 
614
616
  ObjectSpace.garbage_collect()
615
617
  Thread.pass
616
- for i in 0...threads.size
618
+ for i in 0...@threads.size
617
619
  mutex.synchronize do
618
620
  self.logger.prefix = "FeedUpdater".ljust(20)
619
621
  self.logger.info(
620
- "Joining on thread #{threads[i].thread_id}...")
622
+ "Joining on thread #{@threads[i].thread_id}...")
621
623
  end
622
- threads[i].join
624
+ @threads[i].join
623
625
  end
624
626
  self.logger.prefix = "FeedUpdater".ljust(20)
625
627
  ObjectSpace.garbage_collect()
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: feedupdater
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.2.1
7
- date: 2006-04-20 00:00:00 -07:00
6
+ version: 0.2.2
7
+ date: 2006-05-17 00:00:00 -04:00
8
8
  summary: Automatic feed updater daemon.
9
9
  require_paths:
10
10
  - lib