simple_hot_folder 0.1.4 → 0.1.5
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 +4 -4
- data/.gitlab-ci.yml +4 -27
- data/CHANGELOG.md +5 -0
- data/README.md +16 -5
- data/Rakefile +2 -0
- data/lib/simple_hot_folder/hot_folder.rb +21 -3
- data/lib/simple_hot_folder/version.rb +1 -1
- data/lib/simple_hot_folder.rb +2 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 309b622344dc4985cedfef8d20e50affe682406c
|
4
|
+
data.tar.gz: '01914ffa00e1d078a2b4f0803fdd41daec36f46b'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ebd65347cee871f5a77c9664ed2cca2f922056e8a4a1d743a3b0d50ec7f66d79ae020290b36a549a521f0c30bfd50c898497efface934419b1604836235d1ae
|
7
|
+
data.tar.gz: bba02a8e15d15c7b0f4e4a688356674ab306d5af6eb94bf4e46791040e7fab1f695f44aa9a8d49022ae0f9a6a9910d5457e982036f2e49bdfd4918c9f7c13aa4
|
data/.gitlab-ci.yml
CHANGED
@@ -1,33 +1,10 @@
|
|
1
|
-
# Official language image. Look for the different tagged releases at:
|
2
|
-
# https://hub.docker.com/r/library/ruby/tags/
|
3
1
|
image: "ruby:2.4"
|
4
2
|
|
5
|
-
# Pick zero or more services to be used on all builds.
|
6
|
-
# Only needed when using a docker container to run your tests in.
|
7
|
-
# Check out: http://docs.gitlab.com/ce/ci/docker/using_docker_images.html#what-is-a-service
|
8
|
-
# services:
|
9
|
-
# - mysql:latest
|
10
|
-
# - redis:latest
|
11
|
-
# - postgres:latest
|
12
|
-
|
13
|
-
# variables:
|
14
|
-
# POSTGRES_DB: database_name
|
15
|
-
|
16
|
-
# Cache gems in between builds
|
17
|
-
# cache:
|
18
|
-
# paths:
|
19
|
-
# - vendor/ruby
|
20
|
-
|
21
|
-
# This is a basic example for a gem or script which doesn't use
|
22
|
-
# services such as redis or postgres
|
23
3
|
before_script:
|
24
|
-
- ruby -v
|
25
|
-
|
26
|
-
|
27
|
-
- gem install bundler --no-ri --no-rdoc # Bundler is not installed with the image
|
28
|
-
# - bundle install -j $(nproc) --path vendor # Install dependencies into ./vendor/ruby
|
29
|
-
- bundle install --path vendor
|
4
|
+
- ruby -v
|
5
|
+
- gem install bundler --no-ri --no-rdoc
|
6
|
+
- bundle install
|
30
7
|
|
31
|
-
|
8
|
+
tests:
|
32
9
|
script:
|
33
10
|
- rake test
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -19,21 +19,27 @@ gem install simple_hot_folder
|
|
19
19
|
```ruby
|
20
20
|
require 'simple_hot_folder'
|
21
21
|
|
22
|
+
# Create a hot folder that listens for files.
|
22
23
|
hot_folder = SimpleHotFolder.for_files(
|
23
24
|
'/path/to/input_folder',
|
24
|
-
'/path/to/error_folder'
|
25
|
-
'/path/to/output_folder'
|
25
|
+
'/path/to/error_folder'
|
26
26
|
)
|
27
27
|
|
28
|
-
#
|
29
|
-
hot_folder.
|
28
|
+
# Listen input folder for incomming files.
|
29
|
+
hot_folder.listen_input! do |item|
|
30
30
|
puts "Processing file #{item.name}..."
|
31
31
|
puts "File path: #{item.path}"
|
32
32
|
puts "Now, the file is automatically deleted"
|
33
33
|
end
|
34
34
|
|
35
|
+
# Stop listening.
|
36
|
+
hot_folder.listen_input! do |item|
|
37
|
+
puts "Processing file #{item.name}..."
|
38
|
+
hot_folder.stop_listening_after_this_item
|
39
|
+
end
|
40
|
+
|
35
41
|
# On error
|
36
|
-
hot_folder.
|
42
|
+
hot_folder.listen_input! do |item|
|
37
43
|
puts "Processing file #{item.name}..."
|
38
44
|
puts "File path: #{item.path}"
|
39
45
|
puts "The file will be automatically moved to the error folder"
|
@@ -41,6 +47,11 @@ hot_folder.process_input! do |item|
|
|
41
47
|
puts "The process will continue with the next file"
|
42
48
|
raise 'Trigger error'
|
43
49
|
end
|
50
|
+
|
51
|
+
# Process input folder just once.
|
52
|
+
hot_folder.process_input! do |item|
|
53
|
+
puts "Processing file #{item.name}..."
|
54
|
+
end
|
44
55
|
```
|
45
56
|
|
46
57
|
## License
|
data/Rakefile
CHANGED
@@ -10,13 +10,12 @@ module SimpleHotFolder
|
|
10
10
|
#
|
11
11
|
# @param [String] input_path Input folder path
|
12
12
|
# @param [String] error_path Error folder path
|
13
|
-
# @param [String] output_path Error folder path
|
14
13
|
# @return [HotFolder]
|
15
|
-
def initialize(input_path, error_path
|
14
|
+
def initialize(input_path, error_path)
|
16
15
|
@input_path = input_path
|
17
16
|
@error_path = error_path
|
18
|
-
@output_path = output_path
|
19
17
|
@validate_file = default_validate_file_function
|
18
|
+
@stop = false
|
20
19
|
end
|
21
20
|
|
22
21
|
# Yield a {Item} for each file/folder in the input path.
|
@@ -28,6 +27,7 @@ module SimpleHotFolder
|
|
28
27
|
entries = read_input(@input_path)
|
29
28
|
entries.each do |item|
|
30
29
|
begin
|
30
|
+
return if @stop
|
31
31
|
yield item
|
32
32
|
FileUtils.rm(item.path) if File.exist?(item.path)
|
33
33
|
rescue Exception => e
|
@@ -36,6 +36,24 @@ module SimpleHotFolder
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
+
# Yield a {Item} for each file/folder in the input path.
|
40
|
+
# Each file/folder is automatically deleted after the yield
|
41
|
+
# block is executed.
|
42
|
+
#
|
43
|
+
# @yieldparam [Item] item The file/folder.
|
44
|
+
def listen_input!
|
45
|
+
while true
|
46
|
+
puts 'Listening...'
|
47
|
+
process_input! { |item| yield item }
|
48
|
+
return if @stop
|
49
|
+
sleep(1)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def stop_listening_after_this_item
|
54
|
+
@stop = true
|
55
|
+
end
|
56
|
+
|
39
57
|
private
|
40
58
|
|
41
59
|
def move_file_to_error!(item, exception)
|
data/lib/simple_hot_folder.rb
CHANGED
@@ -17,10 +17,9 @@ module SimpleHotFolder
|
|
17
17
|
#
|
18
18
|
# @param [String] input_path Input folder path
|
19
19
|
# @param [String] error_path Error folder path
|
20
|
-
# @param [String] output_path Error folder path
|
21
20
|
# @return [HotFolder]
|
22
|
-
def self.for_files(input_path, error_path
|
23
|
-
HotFolder.new(input_path, error_path
|
21
|
+
def self.for_files(input_path, error_path)
|
22
|
+
HotFolder.new(input_path, error_path)
|
24
23
|
end
|
25
24
|
|
26
25
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_hot_folder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Manu
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-07-
|
11
|
+
date: 2018-07-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|