fluent-plugin-directory 0.1.0 → 0.1.1

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: fb482c43b627800e8bb1ead02767e4d8d456f575a20d02c90b6cde2bfeb91e2f
4
+ data.tar.gz: 66444cc9b59e73f4ab92d54ba3d22a54b070aa7e80439760957e72773f1f1aa6
5
5
  SHA512:
6
- metadata.gz: fb481b952c173b9d779931ef69dedb2aae46dcfe9bf1030774836b8c8cf95bdf64cd3295a650e151028b67b0b19f76bd48189d3064c9f42cd3d2811dde083683
7
- data.tar.gz: 5192a3f3c29a018662c007e2c9fe320d71837a84c312ce725250c38207eeae79f962787cf425e1a2dcc81931f9bf05c1827dd1f58b4745b14f69421e402b5b5b
6
+ metadata.gz: 3295463622de8cca2f93bc6f87c3599b9a8a7ad98bffecb885b60ef37e058ed5ce84533b993981875d99ca0a7c60dc08a04f1db5094e71e278e299d61ead454a
7
+ data.tar.gz: 1b1cd0443e6a6431b1a373e831560d96c6181479da92585b8538f5895d252a60abcee5b53805f1c532c20a074819df0bf328b921b78978a52ac7201d1ea5ec05
data/README.md CHANGED
@@ -26,13 +26,39 @@ $ 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 name of the key whose value is the content of the file.
32
+
33
+ Default value: `content`.
34
+
35
+ ### extension (string) (optional)
36
+
37
+ The extension that will be added to the processed files.
38
+
39
+ Default value: `.done`.
40
+
41
+ ### filename_key (string) (optional)
42
+
43
+ The name of the key whose value is the name of the file.
44
+
45
+ Default value: `filename`.
46
+
47
+ ### path (string) (required)
48
+
49
+ The path of the folder to be scanned by the plugin.
50
+
51
+ ### run_interval (integer) (optional)
52
+
53
+ The time interval (in seconds) to wait between scans.
54
+
55
+ Default value: `60`.
56
+
57
+ ### tag (string) (required)
58
+
59
+ The tag added to the output event.
34
60
 
35
- You can copy and paste generated documents here.
61
+ - See also: [Input Plugin Overview](https://docs.fluentd.org/v/1.0/input#overview)
36
62
 
37
63
  ## Copyright
38
64
 
@@ -3,7 +3,7 @@ $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"
6
+ spec.version = "0.1.1"
7
7
  spec.authors = ["remyduthu@icloud.com"]
8
8
  spec.email = ["remyduthu@icloud.com"]
9
9
 
@@ -20,19 +20,18 @@ 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
25
24
 
26
- desc 'The extension that will be added to the processed files.'
27
- config_param :extension, :string, default: '.done'
25
+ desc 'The field where the content of the file is stored in the output event.'
26
+ config_param :content_key, :string, default: 'content'
28
27
 
29
- desc 'The name of the key whose value is the name of the file.'
28
+ desc 'The field where the name of the file is stored in the output event.'
30
29
  config_param :filename_key, :string, default: 'filename'
31
30
 
32
- desc 'The path of the folder to be scanned by the plugin.'
31
+ desc 'The path of the folder to scan.'
33
32
  config_param :path, :string
34
33
 
35
- desc 'The time interval (in seconds) to wait between scans.'
34
+ desc 'The interval (in seconds) to wait between scans.'
36
35
  config_param :run_interval, :integer, default: 60
37
36
 
38
37
  desc 'The tag added to the output event.'
@@ -41,9 +40,9 @@ module Fluent
41
40
  def start
42
41
  super
43
42
 
44
- begin
45
- # Scan files indefinitely
46
- loop do
43
+ # See: https://docs.fluentd.org/plugin-helper-overview/api-plugin-helper-timer
44
+ timer_execute(:directory_timer, @run_interval) do
45
+ begin
47
46
  # Use a stream to submit multiple events at the same time
48
47
  multiEventStream = MultiEventStream.new
49
48
 
@@ -52,28 +51,22 @@ module Fluent
52
51
 
53
52
  # Read filenames in the directory
54
53
  Dir.glob(@path + '/*') do |filename|
55
- # Ignore already processed files
56
- next if filename.end_with? @extension
57
-
58
54
  # Add the record to the stream
59
55
  multiEventStream.add(
60
56
  time,
61
- { @content_key => File.read(filename), @file_key => filename }
57
+ { @content_key => File.read(filename), @file_key => filename },
62
58
  )
63
59
 
64
- # Mark the file as processed
65
- File.rename(filename, filename + @extension)
60
+ # Remove the file
61
+ File.delete(filename)
66
62
  end
67
63
 
68
64
  # Send the events
69
65
  router.emit_stream(tag, multiEventStream)
70
-
71
- # Wait before the next scan
72
- sleep(@run_interval)
66
+ rescue Exception => e
67
+ $log.warn 'Directory input error: ', e
68
+ $log.debug_backtrace(e.backtrace)
73
69
  end
74
- rescue Exception => e
75
- $log.warn 'Directory input error: ', e
76
- $log.debug_backtrace(e.backtrace)
77
70
  end
78
71
  end
79
72
  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.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - remyduthu@icloud.com
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-15 00:00:00.000000000 Z
11
+ date: 2021-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler