Class: LogStash::Outputs::Swift::TemporaryFileFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/logstash/outputs/swift/temporary_file_factory.rb

Overview

Since the file can contains dynamic part, we have to handle a more local structure to allow a nice recovery from a crash.

The local structure will look like this.

<TEMPORARY_PATH>/<UUID>/<prefix>/ls.s3.localhost.%Y-%m-%dT%H.%m.tag_es_fb.part1.txt.gz

Since the UUID should be fairly unique I can destroy the whole path when an upload is complete. I do not have to mess around to check if the other directory have file in it before destroying them.

Defined Under Namespace

Classes: IOWrappedGzip

Constant Summary collapse

FILE_MODE =
"a"
GZIP_ENCODING =
"gzip"
GZIP_EXTENSION =
"txt.gz"
TXT_EXTENSION =
"txt"
STRFTIME =
"%Y-%m-%dT%H.%M"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(prefix, tags, encoding, temporary_directory) ⇒ TemporaryFileFactory

Returns a new instance of TemporaryFileFactory.



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/logstash/outputs/swift/temporary_file_factory.rb', line 29

def initialize(prefix, tags, encoding, temporary_directory)
  @counter = 0
  @prefix = prefix

  @tags = tags
  @encoding = encoding
  @temporary_directory = temporary_directory
  @lock = Mutex.new

  rotate!
end

Instance Attribute Details

#counterObject

Returns the value of attribute counter.



27
28
29
# File 'lib/logstash/outputs/swift/temporary_file_factory.rb', line 27

def counter
  @counter
end

#currentObject

Returns the value of attribute current.



27
28
29
# File 'lib/logstash/outputs/swift/temporary_file_factory.rb', line 27

def current
  @current
end

#encodingObject

Returns the value of attribute encoding.



27
28
29
# File 'lib/logstash/outputs/swift/temporary_file_factory.rb', line 27

def encoding
  @encoding
end

#prefixObject

Returns the value of attribute prefix.



27
28
29
# File 'lib/logstash/outputs/swift/temporary_file_factory.rb', line 27

def prefix
  @prefix
end

#tagsObject

Returns the value of attribute tags.



27
28
29
# File 'lib/logstash/outputs/swift/temporary_file_factory.rb', line 27

def tags
  @tags
end

#temporary_directoryObject

Returns the value of attribute temporary_directory.



27
28
29
# File 'lib/logstash/outputs/swift/temporary_file_factory.rb', line 27

def temporary_directory
  @temporary_directory
end

Instance Method Details

#rotate!Object



41
42
43
44
45
46
47
# File 'lib/logstash/outputs/swift/temporary_file_factory.rb', line 41

def rotate!
  @lock.synchronize {
    @current = new_file
    increment_counter
    @current
  }
end