tresque 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +4 -0
- data/MIT-LICENSE +20 -0
- data/README.md +186 -0
- data/Rakefile +1 -0
- data/lib/tresque.rb +24 -0
- data/lib/tresque/delay.rb +115 -0
- data/lib/tresque/delay_execution_worker.rb +58 -0
- data/lib/tresque/queue_lock.rb +70 -0
- data/lib/tresque/registry.rb +94 -0
- data/lib/tresque/resque_spec/ext.rb +92 -0
- data/lib/tresque/resque_spec/helpers.rb +25 -0
- data/lib/tresque/resque_spec/matchers.rb +318 -0
- data/lib/tresque/resque_spec/resque_spec.rb +201 -0
- data/lib/tresque/resque_spec/scheduler.rb +93 -0
- data/lib/tresque/spec.rb +2 -0
- data/lib/tresque/spec/delay.rb +27 -0
- data/lib/tresque/util.rb +16 -0
- data/lib/tresque/version.rb +3 -0
- data/lib/tresque/worker.rb +228 -0
- data/lib/tresque/worker_lock.rb +53 -0
- data/tresque.gemspec +30 -0
- metadata +141 -0
@@ -0,0 +1,53 @@
|
|
1
|
+
module TResque
|
2
|
+
# If you want only one instance of your job running at a time,
|
3
|
+
# extend it with this module.
|
4
|
+
module WorkerLock
|
5
|
+
|
6
|
+
# Override in your job to control the worker lock experiation time. This
|
7
|
+
# is the time in seconds that the lock should be considered valid. The
|
8
|
+
# default is one hour (3600 seconds).
|
9
|
+
def worker_lock_timeout
|
10
|
+
3600
|
11
|
+
end
|
12
|
+
|
13
|
+
# Override in your job to control the workers lock key.
|
14
|
+
# def worker_lock_key(options)
|
15
|
+
# "#{name}-#{options.to_s}"
|
16
|
+
# end
|
17
|
+
|
18
|
+
# Called with the job options before perform.
|
19
|
+
# If it raises Resque::Job::DontPerform, the job is aborted.
|
20
|
+
def before_perform_worker_lock(options)
|
21
|
+
val = worker_lock_key(options)
|
22
|
+
if val
|
23
|
+
key = "workerslock:#{val}"
|
24
|
+
if Resque.redis.setnx(key, true)
|
25
|
+
Resque.redis.expire(key, worker_lock_timeout)
|
26
|
+
else
|
27
|
+
obj = self.new(options)
|
28
|
+
obj.requeue!
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def clear_worker_lock(options)
|
34
|
+
val = worker_lock_key(options)
|
35
|
+
if val
|
36
|
+
Resque.redis.del("workerslock:#{val}")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def around_perform_worker_lock(options)
|
41
|
+
yield
|
42
|
+
ensure
|
43
|
+
# Clear the lock. (even with errors)
|
44
|
+
clear_worker_lock(options)
|
45
|
+
end
|
46
|
+
|
47
|
+
def on_failure_worker_lock(exception, options)
|
48
|
+
# Clear the lock on DirtyExit
|
49
|
+
clear_worker_lock(options)
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
data/tresque.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'tresque/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "tresque"
|
8
|
+
spec.version = TResque::VERSION
|
9
|
+
spec.authors = ["Brian Leonard"]
|
10
|
+
spec.email = ["brian@bleonard.com"]
|
11
|
+
spec.description = %q{Background me}
|
12
|
+
spec.summary = %q{Background me}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
# spec.add_development_dependency "rake"
|
23
|
+
|
24
|
+
|
25
|
+
spec.add_dependency('resque', ['>= 1.10.0', '< 2.0'])
|
26
|
+
spec.add_dependency('activesupport', '4.1.8')
|
27
|
+
spec.add_dependency('resque-scheduler')
|
28
|
+
spec.add_dependency('resque-retry')
|
29
|
+
spec.add_dependency('resque-bus')
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tresque
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brian Leonard
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-03-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: resque
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.10.0
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '2.0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.10.0
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '2.0'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: activesupport
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - '='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 4.1.8
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - '='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 4.1.8
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: resque-scheduler
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: resque-retry
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
type: :runtime
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: resque-bus
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
type: :runtime
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
description: Background me
|
90
|
+
email:
|
91
|
+
- brian@bleonard.com
|
92
|
+
executables: []
|
93
|
+
extensions: []
|
94
|
+
extra_rdoc_files: []
|
95
|
+
files:
|
96
|
+
- Gemfile
|
97
|
+
- MIT-LICENSE
|
98
|
+
- README.md
|
99
|
+
- Rakefile
|
100
|
+
- lib/tresque.rb
|
101
|
+
- lib/tresque/delay.rb
|
102
|
+
- lib/tresque/delay_execution_worker.rb
|
103
|
+
- lib/tresque/queue_lock.rb
|
104
|
+
- lib/tresque/registry.rb
|
105
|
+
- lib/tresque/resque_spec/ext.rb
|
106
|
+
- lib/tresque/resque_spec/helpers.rb
|
107
|
+
- lib/tresque/resque_spec/matchers.rb
|
108
|
+
- lib/tresque/resque_spec/resque_spec.rb
|
109
|
+
- lib/tresque/resque_spec/scheduler.rb
|
110
|
+
- lib/tresque/spec.rb
|
111
|
+
- lib/tresque/spec/delay.rb
|
112
|
+
- lib/tresque/util.rb
|
113
|
+
- lib/tresque/version.rb
|
114
|
+
- lib/tresque/worker.rb
|
115
|
+
- lib/tresque/worker_lock.rb
|
116
|
+
- tresque.gemspec
|
117
|
+
homepage: ''
|
118
|
+
licenses:
|
119
|
+
- MIT
|
120
|
+
metadata: {}
|
121
|
+
post_install_message:
|
122
|
+
rdoc_options: []
|
123
|
+
require_paths:
|
124
|
+
- lib
|
125
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
requirements: []
|
136
|
+
rubyforge_project:
|
137
|
+
rubygems_version: 2.5.2
|
138
|
+
signing_key:
|
139
|
+
specification_version: 4
|
140
|
+
summary: Background me
|
141
|
+
test_files: []
|