tasque 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: fe02e8efd7f9659a71065ff03456285a77c3738a
4
- data.tar.gz: 0148d4b75800c0249624d34a50af1902857ad804
2
+ SHA256:
3
+ metadata.gz: bf0b5935e1d4982bf36d127324ed8f3846b577c2ddacf031a339360626203e23
4
+ data.tar.gz: 64988b1ffc2200d333b289791978106686a04dd85fdb027b9bef62c5c0c4fb74
5
5
  SHA512:
6
- metadata.gz: 5446b19a1112207b663a3d91045da3c32f24d3fd4affd5d4adda441a22c412c27dc258a5f18a38f83e1409418c4cf9d8047b50c18fc7ba0f16c6cca96343b9a3
7
- data.tar.gz: 6af7d2e232ef54594ee8a0f9971693bbcd22666cbcc251fa0b7b3cebc3c9bdd9b30ac15079f0b10c5b74ee713b11dab0c4ae993f29aae6fb5dd8a9948d37536d
6
+ metadata.gz: 91853cbce23866722d4c39e7d045397d449b4078bd8e9902a7a1a823ef635f2721968f270e628b2060de7886ad03dd70c3d2147a6b85070f079de08b65ac7d71
7
+ data.tar.gz: 242a113c684536ab53dcf988b6ee3ddd95586b64cbbbceda4c5fede237950d19f8429719b6fbb85a4aa790cf9a2dd15efc96b65863eb1e783914ec9c240eb262
@@ -0,0 +1,68 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ tasque (0.0.3)
5
+ activerecord
6
+ json
7
+ state_machine
8
+ timers
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ activemodel (5.1.5)
14
+ activesupport (= 5.1.5)
15
+ activerecord (5.1.5)
16
+ activemodel (= 5.1.5)
17
+ activesupport (= 5.1.5)
18
+ arel (~> 8.0)
19
+ activesupport (5.1.5)
20
+ concurrent-ruby (~> 1.0, >= 1.0.2)
21
+ i18n (~> 0.7)
22
+ minitest (~> 5.1)
23
+ tzinfo (~> 1.1)
24
+ arel (8.0.0)
25
+ concurrent-ruby (1.0.5)
26
+ diff-lcs (1.3)
27
+ hitimes (1.2.6)
28
+ i18n (0.9.5)
29
+ concurrent-ruby (~> 1.0)
30
+ insque (0.6.3)
31
+ json (> 2)
32
+ redis (> 2)
33
+ json (2.1.0)
34
+ minitest (5.11.3)
35
+ redis (4.0.1)
36
+ rspec (3.7.0)
37
+ rspec-core (~> 3.7.0)
38
+ rspec-expectations (~> 3.7.0)
39
+ rspec-mocks (~> 3.7.0)
40
+ rspec-core (3.7.1)
41
+ rspec-support (~> 3.7.0)
42
+ rspec-expectations (3.7.0)
43
+ diff-lcs (>= 1.2.0, < 2.0)
44
+ rspec-support (~> 3.7.0)
45
+ rspec-mocks (3.7.0)
46
+ diff-lcs (>= 1.2.0, < 2.0)
47
+ rspec-support (~> 3.7.0)
48
+ rspec-support (3.7.1)
49
+ sqlite3 (1.3.13)
50
+ state_machine (1.2.0)
51
+ thread_safe (0.3.6)
52
+ timers (4.1.2)
53
+ hitimes
54
+ tzinfo (1.2.5)
55
+ thread_safe (~> 0.1)
56
+
57
+ PLATFORMS
58
+ ruby
59
+
60
+ DEPENDENCIES
61
+ activesupport
62
+ insque
63
+ rspec
64
+ sqlite3
65
+ tasque!
66
+
67
+ BUNDLED WITH
68
+ 1.12.5
data/README.md CHANGED
@@ -48,12 +48,27 @@ Now to process the task:
48
48
  # register a handler for test tasks
49
49
  processor.add_handler('test') do |task|
50
50
  puts "Got task ##{task.id}. Task says: '#{task.params['text']}'"
51
+ task.complete!
51
52
  { log: 'got task, printed text' } # returning task result
52
53
  end
53
54
 
54
55
  # start processor and wait
55
56
  processor.start
56
57
 
58
+
59
+ ### Using with Insque
60
+
61
+ Tasque can send task and worker state updates via [Insque](https://github.com/Gropher/insque).
62
+
63
+ To enable this featute uncomment following lines in your tasque initializer:
64
+
65
+ # Send task state updates and progress notifications via Insque
66
+ config.notify = true
67
+
68
+ # Send worker heartbeat via Insque
69
+ config.heartbeat = true
70
+ config.heartbeat_interval = 10 # seconds
71
+
57
72
 
58
73
  ## Contributing
59
74
 
Binary file
@@ -0,0 +1,10 @@
1
+ version: '3.2'
2
+
3
+ services:
4
+ redis:
5
+ image: redis
6
+ ports:
7
+ - target: 6379
8
+ published: 63790
9
+ protocol: tcp
10
+ mode: host
@@ -35,6 +35,8 @@ module Tasque
35
35
  has_task = Tasque::Task.fetch(type) do |task|
36
36
  @handlers[type.to_sym].call(task)
37
37
  end
38
+ rescue ActiveRecord::Deadlocked
39
+ retry
38
40
  end while has_task
39
41
  end
40
42
  end
@@ -1,3 +1,3 @@
1
1
  module Tasque
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -0,0 +1,100 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
16
+ RSpec.configure do |config|
17
+ # rspec-expectations config goes here. You can use an alternate
18
+ # assertion/expectation library such as wrong or the stdlib/minitest
19
+ # assertions if you prefer.
20
+ config.expect_with :rspec do |expectations|
21
+ # This option will default to `true` in RSpec 4. It makes the `description`
22
+ # and `failure_message` of custom matchers include text for helper methods
23
+ # defined using `chain`, e.g.:
24
+ # be_bigger_than(2).and_smaller_than(4).description
25
+ # # => "be bigger than 2 and smaller than 4"
26
+ # ...rather than:
27
+ # # => "be bigger than 2"
28
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
29
+ end
30
+
31
+ # rspec-mocks config goes here. You can use an alternate test double
32
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
33
+ config.mock_with :rspec do |mocks|
34
+ # Prevents you from mocking or stubbing a method that does not exist on
35
+ # a real object. This is generally recommended, and will default to
36
+ # `true` in RSpec 4.
37
+ mocks.verify_partial_doubles = true
38
+ end
39
+
40
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
41
+ # have no way to turn it off -- the option exists only for backwards
42
+ # compatibility in RSpec 3). It causes shared context metadata to be
43
+ # inherited by the metadata hash of host groups and examples, rather than
44
+ # triggering implicit auto-inclusion in groups with matching metadata.
45
+ config.shared_context_metadata_behavior = :apply_to_host_groups
46
+
47
+ # The settings below are suggested to provide a good initial experience
48
+ # with RSpec, but feel free to customize to your heart's content.
49
+ =begin
50
+ # This allows you to limit a spec run to individual examples or groups
51
+ # you care about by tagging them with `:focus` metadata. When nothing
52
+ # is tagged with `:focus`, all examples get run. RSpec also provides
53
+ # aliases for `it`, `describe`, and `context` that include `:focus`
54
+ # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
55
+ config.filter_run_when_matching :focus
56
+
57
+ # Allows RSpec to persist some state between runs in order to support
58
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
59
+ # you configure your source control system to ignore this file.
60
+ config.example_status_persistence_file_path = "spec/examples.txt"
61
+
62
+ # Limits the available syntax to the non-monkey patched syntax that is
63
+ # recommended. For more details, see:
64
+ # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
65
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
66
+ # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
67
+ config.disable_monkey_patching!
68
+
69
+ # This setting enables warnings. It's recommended, but in some cases may
70
+ # be too noisy due to issues in dependencies.
71
+ config.warnings = true
72
+
73
+ # Many RSpec users commonly either run the entire suite or an individual
74
+ # file, and it's useful to allow more verbose output when running an
75
+ # individual spec file.
76
+ if config.files_to_run.one?
77
+ # Use the documentation formatter for detailed output,
78
+ # unless a formatter has already been configured
79
+ # (e.g. via a command-line flag).
80
+ config.default_formatter = "doc"
81
+ end
82
+
83
+ # Print the 10 slowest examples and example groups at the
84
+ # end of the spec run, to help surface which specs are running
85
+ # particularly slow.
86
+ config.profile_examples = 10
87
+
88
+ # Run specs in random order to surface order dependencies. If you find an
89
+ # order dependency and want to debug it, you can fix the order by providing
90
+ # the seed, which is printed after each run.
91
+ # --seed 1234
92
+ config.order = :random
93
+
94
+ # Seed global randomization in this process using the `--seed` CLI option.
95
+ # Setting this allows you to use `--seed` to deterministically reproduce
96
+ # test failures related to randomization by passing the same `--seed` value
97
+ # as the one that triggered the failure.
98
+ Kernel.srand config.seed
99
+ =end
100
+ end
@@ -0,0 +1,156 @@
1
+ require 'json'
2
+ require 'active_support/all'
3
+ require 'active_record'
4
+ require 'tasque'
5
+ require 'insque'
6
+
7
+ RSpec.describe 'tasque' do
8
+ before(:all) do
9
+ system "docker swarm init || true"
10
+ system "docker stack deploy -c insque.local.yml insque"
11
+ sleep 10
12
+ Insque.debug = false
13
+ Insque.sender = 'myapp'
14
+ Insque.redis_config = { host: 'localhost', port: 63790 }
15
+ Thread.abort_on_exception=true
16
+ ActiveRecord::Base.establish_connection(
17
+ :adapter => 'sqlite3',
18
+ :database => 'db/test.db'
19
+ )
20
+ ActiveRecord::Base.connection.execute('create table tasque_tasks(id INTEGER PRIMARY KEY AUTOINCREMENT, tag TEXT, task TEXT, params TEXT, result TEXT, worker TEXT, status TEXT DEFAULT "new", attempts INTEGER DEFAULT 0, progress INTEGER DEFAULT 0, priority INTEGER DEFAULT 0, started_at DATETIME, finished_at DATETIME, updated_at DATETIME, created_at DATETIME);')
21
+ end
22
+
23
+ after(:all) do
24
+ system "docker stack rm insque"
25
+ ActiveRecord::Base.connection.execute('drop table tasque_tasks;')
26
+ end
27
+
28
+ before(:each) do
29
+ Insque.redis.flushall
30
+ Tasque::Task.delete_all
31
+ Tasque.configure do |config|
32
+ config.worker = 'myworker'
33
+ config.check_interval = 1 # seconds
34
+ config.progress_interval = 1 # seconds
35
+ config.minimum_priority = nil
36
+ config.notify = false
37
+ config.heartbeat = false
38
+ config.heartbeat_interval = 1
39
+ end
40
+ end
41
+
42
+ it 'creates a task' do
43
+ Tasque::Task.create! task: 'test', params: { text: 'This is the test!' }
44
+ expect(Tasque::Task.count).to eq(1)
45
+ end
46
+
47
+ it 'processes a task' do
48
+ task = Tasque::Task.create! task: 'test', params: { text: 'This is the test!' }
49
+ processor_thread = Thread.new do
50
+ processor = Tasque::Processor.new
51
+ processor.add_handler('test') do |t|
52
+ t.complete!
53
+ { log: 'completed task' }
54
+ end
55
+ processor.start
56
+ end
57
+ sleep 2
58
+ processor_thread.exit
59
+ task.reload
60
+ expect(task.status).to eq('complete')
61
+ expect(task.progress).to eq(100)
62
+ end
63
+
64
+ it 'uses minimum priority' do
65
+ Tasque.config.minimum_priority = 10
66
+ task1 = Tasque::Task.create! task: 'test', priority: 1, params: { text: 'This is low priority!' }
67
+ task2 = Tasque::Task.create! task: 'test', priority: 100, params: { text: 'This is high priority!' }
68
+ processor_thread = Thread.new do
69
+ processor = Tasque::Processor.new
70
+ processor.add_handler('test') do |t|
71
+ t.complete!
72
+ { log: 'completed task' }
73
+ end
74
+ processor.start
75
+ end
76
+ sleep 2
77
+ processor_thread.exit
78
+ task1.reload
79
+ task2.reload
80
+ expect(task1.status).to eq('new')
81
+ expect(task2.status).to eq('complete')
82
+ end
83
+
84
+ it 'reports progress' do
85
+ task = Tasque::Task.create! task: 'test', params: { text: 'This is the test!' }
86
+ processor_thread = Thread.new do
87
+ processor = Tasque::Processor.new
88
+ processor.add_handler('test') do |t|
89
+ t.progress! 50
90
+ sleep 2
91
+ t.complete!
92
+ { log: 'completed task' }
93
+ end
94
+ processor.start
95
+ end
96
+ sleep 2
97
+ task.reload
98
+ expect(task.status).to eq('processing')
99
+ expect(task.progress).to eq(50)
100
+ sleep 2
101
+ processor_thread.exit
102
+ task.reload
103
+ expect(task.status).to eq('complete')
104
+ expect(task.progress).to eq(100)
105
+ end
106
+
107
+ it 'reports errors' do
108
+ task = Tasque::Task.create! task: 'test', params: { text: 'This is the test!' }
109
+ processor_thread = Thread.new do
110
+ processor = Tasque::Processor.new
111
+ processor.add_handler('test') do |t|
112
+ raise 'Test Exception'
113
+ { log: 'completed task' }
114
+ end
115
+ processor.start
116
+ end
117
+ sleep 2
118
+ processor_thread.exit
119
+ task.reload
120
+ expect(task.status).to eq('error')
121
+ expect(task.result['error']['exception']).to eq('Test Exception')
122
+ end
123
+
124
+ it 'uses insque notifications' do
125
+ Tasque.config.notify = true
126
+ janitor = Thread.new { Insque.janitor }
127
+ sleep 1
128
+ Tasque::Task.create! task: 'test', params: { text: 'This is the test!' }
129
+ processor_thread = Thread.new do
130
+ processor = Tasque::Processor.new
131
+ processor.add_handler('test') do |t|
132
+ t.complete!
133
+ { log: 'completed task' }
134
+ end
135
+ processor.start
136
+ end
137
+ sleep 2
138
+ expect(Insque.redis.llen '{insque}inbox_myapp').to eq(3)
139
+ processor_thread.exit
140
+ janitor.exit
141
+ end
142
+
143
+ it 'uses heartbeat' do
144
+ Tasque.config.heartbeat = true
145
+ janitor = Thread.new { Insque.janitor }
146
+ sleep 1
147
+ processor_thread = Thread.new do
148
+ processor = Tasque::Processor.new
149
+ processor.start
150
+ end
151
+ sleep 4
152
+ expect(Insque.redis.llen '{insque}inbox_myapp').to eq(3)
153
+ processor_thread.exit
154
+ janitor.exit
155
+ end
156
+ end
@@ -21,4 +21,8 @@ Gem::Specification.new do |gem|
21
21
  gem.add_dependency("timers")
22
22
  gem.add_dependency("state_machine")
23
23
  gem.add_dependency("json")
24
+ gem.add_development_dependency('rspec')
25
+ gem.add_development_dependency('activesupport')
26
+ gem.add_development_dependency('sqlite3')
27
+ gem.add_development_dependency('insque')
24
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tasque
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuri Gomozov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-13 00:00:00.000000000 Z
11
+ date: 2018-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -66,6 +66,62 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: activesupport
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: sqlite3
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: insque
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
69
125
  description: 'Task processing queue with states, history and priorities. Works with
70
126
  your favorite database. '
71
127
  email:
@@ -76,8 +132,11 @@ extra_rdoc_files: []
76
132
  files:
77
133
  - ".gitignore"
78
134
  - Gemfile
135
+ - Gemfile.lock
79
136
  - LICENSE
80
137
  - README.md
138
+ - db/test.db
139
+ - insque.local.yml
81
140
  - lib/generators/tasque/install_generator.rb
82
141
  - lib/generators/tasque/templates/create_tasque_tasks.erb
83
142
  - lib/generators/tasque/templates/tasque.erb
@@ -87,6 +146,8 @@ files:
87
146
  - lib/tasque/task.rb
88
147
  - lib/tasque/task_error.rb
89
148
  - lib/tasque/version.rb
149
+ - spec/spec_helper.rb
150
+ - spec/tasque_spec.rb
90
151
  - tasque.gemspec
91
152
  homepage: https://github.com/Gropher/tasque
92
153
  licenses: []
@@ -107,8 +168,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
168
  version: '0'
108
169
  requirements: []
109
170
  rubyforge_project:
110
- rubygems_version: 2.5.1
171
+ rubygems_version: 2.7.7
111
172
  signing_key:
112
173
  specification_version: 4
113
174
  summary: ActiveRecord based task queue
114
- test_files: []
175
+ test_files:
176
+ - spec/spec_helper.rb
177
+ - spec/tasque_spec.rb