fluent-plugin-directory 0.1.0 → 0.1.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e169ba627338c24ee1b4b2fa822d5a089847133e28515e975d90beaf2c72c9ba
4
- data.tar.gz: '09c89e36f8f8577abf33ab004436233ff97a468d14ac8a5e8aa6eee8e307d35e'
3
+ metadata.gz: 55d77adfb2d0512e04037176adff4a2b82e16cf9264efce510eb61d88af5c64c
4
+ data.tar.gz: cc44c79f31f7194f6c45080cff9a4b6ed8cf6f3ba55f7ef827ea1a88d0d94ef0
5
5
  SHA512:
6
- metadata.gz: fb481b952c173b9d779931ef69dedb2aae46dcfe9bf1030774836b8c8cf95bdf64cd3295a650e151028b67b0b19f76bd48189d3064c9f42cd3d2811dde083683
7
- data.tar.gz: 5192a3f3c29a018662c007e2c9fe320d71837a84c312ce725250c38207eeae79f962787cf425e1a2dcc81931f9bf05c1827dd1f58b4745b14f69421e402b5b5b
6
+ metadata.gz: ff2e8b35d7118616430406a4a6740ce9636d05c64fd2ec48e3a40f4108d2c927b2a6394a4ad1f7f58bfa579ab2dff5b5970cabeac6b7309ef001154d467c5233
7
+ data.tar.gz: 9e83689cd6e2da654949c702500798ded723e2d4f2db5c0a4635c2b165f483301faf62c0009761d2046862636e972a9b13cf98421acce63b0a0b0adf4a54aeb3
data/README.md CHANGED
@@ -26,16 +26,34 @@ $ bundle
26
26
 
27
27
  ## Configuration
28
28
 
29
- You can generate configuration template:
29
+ ### content_key (string) (optional)
30
30
 
31
- ```
32
- $ fluent-plugin-config-format input directory
33
- ```
31
+ The field where the content of the file is stored in the output event.
32
+
33
+ Default value: `content`.
34
+
35
+ ### filename_key (string) (optional)
36
+
37
+ The field where the name of the file is stored in the output event.
38
+
39
+ Default value: `filename`.
40
+
41
+ ### path (string) (required)
42
+
43
+ The path of the folder to scan.
44
+
45
+ ### run_interval (integer) (optional)
46
+
47
+ The interval (in seconds) to wait between scans.
48
+
49
+ Default value: `60`.
50
+
51
+ ### tag (string) (required)
34
52
 
35
- You can copy and paste generated documents here.
53
+ The tag added to the output event.
36
54
 
37
55
  ## Copyright
38
56
 
39
- - Copyright(c) 2021- TODO: Write your name
57
+ - Copyright(c) 2021- Rémy DUTHU
40
58
  - License
41
59
  - Apache License, Version 2.0
@@ -3,8 +3,8 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
4
  Gem::Specification.new do |spec|
5
5
  spec.name = "fluent-plugin-directory"
6
- spec.version = "0.1.0"
7
- spec.authors = ["remyduthu@icloud.com"]
6
+ spec.version = "0.1.4"
7
+ spec.authors = ["Rémy DUTHU"]
8
8
  spec.email = ["remyduthu@icloud.com"]
9
9
 
10
10
  spec.summary = "A Fluentd input plugin to scan files recurrently from a directory"
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright 2021- TODO: Write your name
2
+ # Copyright 2021- Rémy DUTHU
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
5
5
  # you may not use this file except in compliance with the License.
@@ -20,19 +20,21 @@ module Fluent
20
20
  class DirectoryInput < Fluent::Plugin::Input
21
21
  Fluent::Plugin.register_input('directory', self)
22
22
 
23
- desc 'The name of the key whose value is the content of the file.'
24
- config_param :content_key, :string, default: 'content'
23
+ helpers :timer
24
+
25
+ desc 'The maximum number of files processed in each run.'
26
+ config_param :batch_size, :integer, default: 10
25
27
 
26
- desc 'The extension that will be added to the processed files.'
27
- config_param :extension, :string, default: '.done'
28
+ desc 'The field where the content of the file is stored in the output event.'
29
+ config_param :content_key, :string, default: 'content'
28
30
 
29
- desc 'The name of the key whose value is the name of the file.'
31
+ desc 'The field where the name of the file is stored in the output event.'
30
32
  config_param :filename_key, :string, default: 'filename'
31
33
 
32
- desc 'The path of the folder to be scanned by the plugin.'
34
+ desc 'The path of the folder to scan.'
33
35
  config_param :path, :string
34
36
 
35
- desc 'The time interval (in seconds) to wait between scans.'
37
+ desc 'The interval (in seconds) to wait between scans.'
36
38
  config_param :run_interval, :integer, default: 60
37
39
 
38
40
  desc 'The tag added to the output event.'
@@ -41,9 +43,9 @@ module Fluent
41
43
  def start
42
44
  super
43
45
 
44
- begin
45
- # Scan files indefinitely
46
- loop do
46
+ # See: https://docs.fluentd.org/plugin-helper-overview/api-plugin-helper-timer
47
+ timer_execute(:directory_timer, @run_interval) do
48
+ begin
47
49
  # Use a stream to submit multiple events at the same time
48
50
  multiEventStream = MultiEventStream.new
49
51
 
@@ -51,29 +53,28 @@ module Fluent
51
53
  time = Fluent::Engine.now
52
54
 
53
55
  # Read filenames in the directory
54
- Dir.glob(@path + '/*') do |filename|
55
- # Ignore already processed files
56
- next if filename.end_with? @extension
57
-
58
- # Add the record to the stream
59
- multiEventStream.add(
60
- time,
61
- { @content_key => File.read(filename), @file_key => filename }
62
- )
63
-
64
- # Mark the file as processed
65
- File.rename(filename, filename + @extension)
66
- end
56
+ Dir
57
+ .glob(@path + '/*')
58
+ .take(@batch_size)
59
+ .each do |filename|
60
+ # Add the record to the stream
61
+ multiEventStream.add(
62
+ time,
63
+ {
64
+ @content_key => File.read(filename),
65
+ @filename_key => filename
66
+ }
67
+ )
68
+
69
+ # Remove the file
70
+ File.delete(filename)
71
+ end
67
72
 
68
73
  # Send the events
69
74
  router.emit_stream(tag, multiEventStream)
70
-
71
- # Wait before the next scan
72
- sleep(@run_interval)
75
+ rescue StandardError
76
+ yield(nil, nil)
73
77
  end
74
- rescue Exception => e
75
- $log.warn 'Directory input error: ', e
76
- $log.debug_backtrace(e.backtrace)
77
78
  end
78
79
  end
79
80
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-directory
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
- - remyduthu@icloud.com
7
+ - Rémy DUTHU
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-15 00:00:00.000000000 Z
11
+ date: 2021-11-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -106,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
106
  - !ruby/object:Gem::Version
107
107
  version: '0'
108
108
  requirements: []
109
- rubygems_version: 3.0.3
109
+ rubygems_version: 3.0.3.1
110
110
  signing_key:
111
111
  specification_version: 4
112
112
  summary: A Fluentd input plugin to scan files recurrently from a directory