lib/command/update.rb in narou-2.9.2 vs lib/command/update.rb in narou-2.9.3
- old
+ new
@@ -12,10 +12,26 @@
module Command
class Update < CommandBase
extend Memoist
+ class Interval
+ MIN = 2.5 # 作品間ウェイトの最低秒数(処理時間含む)
+
+ def initialize(interval)
+ @time = Time.now - MIN
+ interval = interval.to_f
+ @interval_time = interval >= MIN ? interval : MIN
+ end
+
+ def wait
+ wait_time = Time.now - @time
+ sleep(@interval_time - wait_time) if wait_time < @interval_time
+ @time = Time.now
+ end
+ end
+
LOG_DIR_NAME = "log"
LOG_NUM_LIMIT = 30 # ログの保存する上限数
LOG_FILENAME_FORMAT = "update_log_%s.txt"
HOTENTRY_DIR_NAME = "hotentry"
@@ -137,12 +153,15 @@
inv = Inventory.load("local_setting")
@options["hotentry"] = inv["hotentry"]
@options["hotentry.auto-mail"] = inv["hotentry.auto-mail"]
hotentry = {}
+ interval = Interval.new(@options["interval"])
+
update_log = $stdout.capture(quiet: false) do
sort_by_key(sort_key, update_target_list).each_with_index do |target, i|
+ interval.wait
display_message = nil
data = Downloader.get_data_by_target(target)
if !data
display_message = "<bold><red>[ERROR]</red></bold> #{target} は管理小説の中に存在しません".termcolor
elsif Narou.novel_frozen?(target) && !@options["force"]
@@ -333,10 +352,11 @@
display_inspector = false
ignore_force = false
ignore_default = false
converted_text_array = []
+ use_dakuten_font = false
Helper.print_horizontal_rule
puts "hotentry の変換を開始"
subtitles_size = hotentry.inject(0) { |sum, (_, subtitles)| subtitles.size + sum }
@@ -356,10 +376,11 @@
end
converted_text_array << {
setting: setting,
text: novel_converter.convert_main_for_novel(subtitles, true)
}
+ use_dakuten_font |= novel_converter.use_dakuten_font
total_progress += last_num + 1
end
ensure
progressbar.clear
@@ -376,9 +397,10 @@
create_inclusive_directory(txt_output_path)
File.write(txt_output_path, hotentry_text)
# テキストを書籍データに変換
relay_proc = -> {
NovelConverter.convert_txt_to_ebook_file(txt_output_path, {
+ use_dakuten_font: use_dakuten_font,
device: device
})
}
if device
cmd_convert.extend(device.get_hook_module)