metacrunch-redis 1.0.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 774482c4b0397c7515dd587ead6c63ccd1387cd0
4
+ data.tar.gz: 643b0b75a78e9b6423fd8b0c90eb9902a0289edd
5
+ SHA512:
6
+ metadata.gz: 9c5cde0ade90bd646c4b835b7d15418c5b87b27c05a3307f1d382c70afab7b6b6e1e69554d8a76de8ba29e5cdbd5fab46add4ccbfc6f6aa356edba6a060782be
7
+ data.tar.gz: 1b2b6b1b05cad27e6694ae5ad77da92a34ced50becc915df227d693486af37613a31888efdf46a387cd48529b514a76dddc2c0fea1db1bd121dd11e17d6dd0bf
data/.gitignore ADDED
@@ -0,0 +1,24 @@
1
+ .DS_Store
2
+ /doc
3
+ *.gem
4
+ *.rbc
5
+ .bundle
6
+ .config
7
+ .yardoc
8
+ Gemfile.lock
9
+ InstalledFiles
10
+ _yardoc
11
+ coverage
12
+ doc/
13
+ lib/bundler/man
14
+ pkg
15
+ rdoc
16
+ spec/reports
17
+ test/tmp
18
+ test/version_tmp
19
+ tmp
20
+ *.bundle
21
+ *.so
22
+ *.o
23
+ *.a
24
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format documentation
3
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ group :development do
6
+ gem "bundler", ">= 1.15"
7
+ gem "rake", ">= 12.1"
8
+ gem "rspec", ">= 3.5.0", "< 4.0.0"
9
+
10
+ if !ENV["CI"]
11
+ gem "pry-byebug", ">= 3.5.0"
12
+ end
13
+ end
14
+
15
+ group :test do
16
+ gem "simplecov", ">= 0.15.0"
17
+ end
data/License.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2017 René Sprotte
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "rspec/core/rake_task"
2
+ require "bundler/gem_tasks"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ require "bundler/setup"
3
+ require "metacrunch/redis"
4
+
5
+ begin
6
+ require "pry"
7
+ rescue LoadError ; end
8
+
9
+ if defined?(Pry)
10
+ Pry.start
11
+ else
12
+ require "irb"
13
+ IRB.start
14
+ end
@@ -0,0 +1,39 @@
1
+ require "metacrunch/redis"
2
+
3
+ module Metacrunch
4
+ class Redis::QueueDestination
5
+
6
+ def initialize(redis_connection_or_url, queue_name, options = {})
7
+ @queue_name = queue_name
8
+ raise ArgumentError, "queue_name must be a string" unless queue_name.is_a?(String)
9
+
10
+ @save_on_close = options.delete(:save_on_close) || true
11
+
12
+ @redis = if redis_connection_or_url.is_a?(String)
13
+ ::Redis.new(url: redis_connection_or_url)
14
+ else
15
+ redis_connection_or_url
16
+ end
17
+ end
18
+
19
+ def write(data)
20
+ @redis.rpush(@queue_name, data)
21
+ rescue RuntimeError => e
22
+ if e.message =~ /maxmemory/
23
+ puts "Redis has reached maxmemory. Waiting 10 seconds and trying again..."
24
+ sleep(10)
25
+ retry
26
+ else
27
+ raise e
28
+ end
29
+ end
30
+
31
+ def close
32
+ if @redis
33
+ @redis.bgsave if @save_on_close
34
+ @redis.close
35
+ end
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,42 @@
1
+ require "metacrunch/redis"
2
+
3
+ module Metacrunch
4
+ class Redis::QueueSource
5
+
6
+ def initialize(redis_connection_or_url, queue_name, options = {})
7
+ @queue_name = queue_name
8
+ raise ArgumentError, "queue_name must be a string" unless queue_name.is_a?(String)
9
+
10
+ @blocking_mode = options.delete(:blocking) || false
11
+ @blocking_timeout = options.delete(:blocking_timeout) || 0
12
+
13
+ @redis = if redis_connection_or_url.is_a?(String)
14
+ ::Redis.new(url: redis_connection_or_url)
15
+ else
16
+ redis_connection_or_url
17
+ end
18
+ end
19
+
20
+ def each(&block)
21
+ return enum_for(__method__) unless block_given?
22
+
23
+ if @blocking_mode
24
+ while true
25
+ list, result = @redis.blpop(@queue_name, timeout: @blocking_timeout)
26
+ if result.present?
27
+ yield JSON.parse(result)
28
+ else
29
+ yield nil
30
+ end
31
+ end
32
+ else
33
+ while result = @redis.lpop(@queue_name)
34
+ yield JSON.parse(result)
35
+ end
36
+ end
37
+
38
+ self
39
+ end
40
+
41
+ end
42
+ end
@@ -0,0 +1,5 @@
1
+ module Metacrunch
2
+ module Redis
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,10 @@
1
+ require "active_support"
2
+ require "active_support/core_ext"
3
+ require "redis"
4
+
5
+ module Metacrunch
6
+ module Redis
7
+ require_relative "redis/queue_source"
8
+ require_relative "redis/queue_destination"
9
+ end
10
+ end
@@ -0,0 +1,20 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "metacrunch/redis/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "metacrunch-redis"
8
+ spec.version = Metacrunch::Redis::VERSION
9
+ spec.authors = ["René Sprotte"]
10
+ spec.summary = %q{Redis package for the metacrunch ETL toolkit.}
11
+ spec.homepage = "http://github.com/ubpb/metacrunch-redis"
12
+ spec.license = "MIT"
13
+
14
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
15
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
16
+ spec.require_paths = ["lib"]
17
+
18
+ spec.add_dependency "activesupport", ">= 5.1.0"
19
+ spec.add_dependency "redis", ">= 4.0.0"
20
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: metacrunch-redis
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - René Sprotte
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-09-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 5.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 5.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: redis
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 4.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 4.0.0
41
+ description:
42
+ email:
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - ".gitignore"
48
+ - ".rspec"
49
+ - Gemfile
50
+ - License.txt
51
+ - Rakefile
52
+ - bin/console
53
+ - lib/metacrunch/redis.rb
54
+ - lib/metacrunch/redis/queue_destination.rb
55
+ - lib/metacrunch/redis/queue_source.rb
56
+ - lib/metacrunch/redis/version.rb
57
+ - metacrunch-redis.gemspec
58
+ homepage: http://github.com/ubpb/metacrunch-redis
59
+ licenses:
60
+ - MIT
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.6.11
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: Redis package for the metacrunch ETL toolkit.
82
+ test_files: []