Skip to content

Commit

Permalink
Merge pull request #1487 from t-osakada/skip_refresh_on_startup
Browse files Browse the repository at this point in the history
Skip the refresh of watching list on startup.
  • Loading branch information
repeatedly authored Mar 6, 2017
2 parents c728188 + 51f8ded commit 297df6e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/fluent/plugin/in_tail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ def initialize
config_param :open_on_every_update, :bool, default: false
desc 'Limit the watching files that the modification time is within the specified time range (when use \'*\' in path).'
config_param :limit_recently_modified, :time, default: nil
desc 'Enable the option to skip the refresh of watching list on startup.'
config_param :skip_refresh_on_startup, :bool, default: false

attr_reader :paths

Expand Down Expand Up @@ -160,7 +162,7 @@ def start
@pf = PositionFile.parse(@pf_file)
end

refresh_watchers
refresh_watchers unless @skip_refresh_on_startup
timer_execute(:in_tail_refresh_watchers, @refresh_interval, &method(:refresh_watchers))
end

Expand Down
15 changes: 15 additions & 0 deletions test/plugin/test_in_tail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1198,4 +1198,19 @@ def test_limit_recently_modified
assert_equal expected_files, plugin.expand_paths.sort
end
end

def test_skip_refresh_on_startup
FileUtils.touch("#{TMP_DIR}/tail.txt")
config = config_element('', '', {
'format' => 'none',
'refresh_interval' => 1,
'skip_refresh_on_startup' => true
})
d = create_driver(config)
d.run(shutdown: false) {}
assert_equal 0, d.instance.instance_variable_get(:@tails).keys.size
# detect a file at first execution of in_tail_refresh_watchers timer
waiting(5) { sleep 0.1 until d.instance.instance_variable_get(:@tails).keys.size == 1 }
d.instance_shutdown
end
end

0 comments on commit 297df6e

Please sign in to comment.