resque-compressible 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 27f7c85ee27c343792ebaa885b0109be805cf3b7
4
+ data.tar.gz: 3cd94462a7a2787732ac2a09370cb2222b2fb35a
5
+ SHA512:
6
+ metadata.gz: fe9c1bb3136484be492a06d533bc98c93fde3d72526ec7691a799d8567a40849a6b6152dc6336d918255baab133bde26f2b2e8765d33d49d8f4532c5b3d43b9c
7
+ data.tar.gz: e98e58eff1e7218e61db321d3b443fd30263c6f5e6c04f578d8a32f96946be24f01b538b7ae85b80f6def693f6c760452e3349ccf282962d530aba033ba82fee
@@ -0,0 +1,10 @@
1
+ .idea/
2
+ /.bundle/
3
+ /.yardoc
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in resque-compressible.gemspec
4
+ gemspec
@@ -0,0 +1,48 @@
1
+ # Resque::Compressible
2
+
3
+ Transparently compress and decompress resque job payloads!
4
+ Useful if you want to minimize memory footprint in redis or
5
+ minimize net IO.
6
+
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'resque-compressible'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install resque-compressible
23
+
24
+ ## Usage
25
+
26
+ Extend it in your resque job after your perform method.
27
+
28
+ ```ruby
29
+ class Jobs::Blah
30
+ @queue = :data_pipeline
31
+
32
+ def self.perform large_data_1, large_data_2, large_data_3, large_data_4
33
+ puts "large_data_1 is #{large_data_1}"
34
+ puts "large_data_2 is #{large_data_2}"
35
+ puts "large_data_3 is #{large_data_3}"
36
+ puts "large_data_4 is #{large_data_4}"
37
+ end
38
+
39
+ extend Resque::Plugins::Compressible
40
+ end
41
+
42
+ ```
43
+
44
+
45
+ ## Contributing
46
+
47
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/resque-compressible.
48
+
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "resque/compressible"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1 @@
1
+ require 'resque/plugins/compressible'
@@ -0,0 +1,44 @@
1
+ module Resque
2
+ module Plugins
3
+ module Compressible
4
+ VERSION = "0.0.1"
5
+
6
+ def before_enqueue_compressible *args
7
+ unless compressed? args
8
+ new_args = [{:resque_compressed => true, :payload => compressed_args(args)}]
9
+ new_args.push 0 while new_args.size < args.size
10
+ Resque.enqueue self, *new_args
11
+ false
12
+ end
13
+ end
14
+
15
+ def compressed? args
16
+ args.size > 0 && args.first.kind_of?(Hash) && (args.first[:resque_compressed] || args.first['resque_compressed'])
17
+ end
18
+
19
+ def perform_with_compressing *args
20
+ if compressed? args
21
+ perform_without_compressing *uncompressed_args(args.first[:payload] || args.first['payload'])
22
+ else
23
+ perform_without_compressing *args
24
+ end
25
+ end
26
+
27
+ def compressed_args args
28
+ Base64.encode64 Zlib::Deflate.deflate(args.to_json)
29
+ end
30
+
31
+ def uncompressed_args data
32
+ JSON.parse Zlib::Inflate.inflate(Base64.decode64(data))
33
+ end
34
+
35
+ def self.extended(base)
36
+ class << base
37
+ alias_method :perform_without_compressing, :perform
38
+ alias_method :perform, :perform_with_compressing
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'resque/plugins/compressible'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "resque-compressible"
8
+ spec.version = Resque::Plugins::Compressible::VERSION
9
+ spec.authors = ["Misha Conway"]
10
+ spec.email = ["mishaAconway@gmail.com"]
11
+
12
+ spec.summary = %q{Compress resque job payloads!}
13
+ spec.description = %q{Compress resque job payloads!}
14
+ spec.homepage = "https://github.com/MishaConway/resque-compressible"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.12"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec"
24
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: resque-compressible
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Misha Conway
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-04-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Compress resque job payloads!
56
+ email:
57
+ - mishaAconway@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - README.md
65
+ - Rakefile
66
+ - bin/console
67
+ - bin/setup
68
+ - lib/resque-compressible.rb
69
+ - lib/resque/plugins/compressible.rb
70
+ - resque-compressible.gemspec
71
+ homepage: https://github.com/MishaConway/resque-compressible
72
+ licenses: []
73
+ metadata: {}
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 2.6.7
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: Compress resque job payloads!
94
+ test_files: []