cellect-server 1.2.0 → 1.3.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 +4 -4
- data/lib/cellect/node_set.rb +2 -4
- data/lib/cellect/server/adapters/default.rb +5 -0
- data/lib/cellect/server/adapters/postgres.rb +6 -0
- data/lib/cellect/server/api.rb +7 -1
- data/lib/cellect/server/workflow.rb +8 -2
- data/lib/cellect/version.rb +1 -1
- data/spec/server/api/add_seen_spec.rb +1 -1
- data/spec/server/api/add_spec.rb +1 -1
- data/spec/server/api/remove_spec.rb +1 -1
- data/spec/server/api/sample_spec.rb +1 -1
- data/spec/server/api/user_load_spec.rb +1 -1
- data/spec/server/grouped_workflow_spec.rb +1 -1
- data/spec/server/server_spec.rb +50 -0
- data/spec/server/workflow_spec.rb +1 -1
- data/spec/support/cellect_helper.rb +10 -1
- data/spec/support/shared_examples_for_node_set.rb +3 -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: 74908885c875bf40e8557678c00d26c9cc53d8a2
|
4
|
+
data.tar.gz: 6710bfad63345a08390a2a98a5ea2a84d5ce9966
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ebe51236bc8f2077127a20265ed0aba6dbbb980ea37b72cf0e82a1653caefa4f7477596319eb187a08ad78be6b48f3612dd5f11665db6313b2745f61eadf1f1f
|
7
|
+
data.tar.gz: 86ad844b31e3c21d45d4c9881499bdaf53db5c7452f2abde3f721bfbf7380b073d003a0e160ba6d8ca989ece79a07609c34a06f6d12678971795ab92da798802
|
data/lib/cellect/node_set.rb
CHANGED
@@ -16,10 +16,8 @@ module Cellect
|
|
16
16
|
|
17
17
|
# Connect to ZooKeeper, setup this node, and change state
|
18
18
|
def initialize_zk
|
19
|
-
|
20
|
-
|
21
|
-
self.zk = ZK.new zk_url, chroot: '/cellect'
|
22
|
-
end
|
19
|
+
Timeout::timeout(timeout_duration) do
|
20
|
+
self.zk = ZK.new zk_url, chroot: '/cellect'
|
23
21
|
end
|
24
22
|
setup
|
25
23
|
self.state = :ready
|
data/lib/cellect/server/api.rb
CHANGED
@@ -13,13 +13,19 @@ module Cellect
|
|
13
13
|
#
|
14
14
|
# Provides system load information
|
15
15
|
get :stats do
|
16
|
+
node_set = Cellect::Server.node_set.actors.first
|
16
17
|
usage = ->(keyword) do
|
17
18
|
`ps axo #{ keyword }`.chomp.split("\n")[1..-1].collect(&:to_f).inject :+
|
18
19
|
end
|
19
20
|
|
20
21
|
{
|
21
22
|
memory: usage.call('%mem'),
|
22
|
-
cpu: usage.call('%cpu')
|
23
|
+
cpu: usage.call('%cpu'),
|
24
|
+
node_set: { id: node_set.id, ready: node_set.ready? },
|
25
|
+
status: Cellect::Server.adapter.status.merge({
|
26
|
+
workflows_ready: Cellect::Server.ready?,
|
27
|
+
workflows: Workflow.all.map(&:status)
|
28
|
+
})
|
23
29
|
}
|
24
30
|
end
|
25
31
|
|
@@ -3,6 +3,11 @@ module Cellect
|
|
3
3
|
class Workflow
|
4
4
|
include Celluloid
|
5
5
|
|
6
|
+
class << self
|
7
|
+
attr_accessor :workflow_names
|
8
|
+
end
|
9
|
+
self.workflow_names = { }
|
10
|
+
|
6
11
|
attr_accessor :name, :users, :subjects, :state
|
7
12
|
attr_accessor :pairwise, :prioritized
|
8
13
|
|
@@ -14,14 +19,14 @@ module Cellect
|
|
14
19
|
|
15
20
|
# Load a workflow
|
16
21
|
def self.[]=(name, opts)
|
22
|
+
Workflow.workflow_names[name] = true
|
17
23
|
Actor[name] = supervise name, pairwise: opts['pairwise'], prioritized: opts['prioritized']
|
18
24
|
end
|
19
25
|
|
20
26
|
# The names of all workflows currently loaded
|
21
27
|
def self.names
|
22
28
|
actor_names = Celluloid.actor_system.registry.names.collect &:to_s
|
23
|
-
|
24
|
-
workflow_actors.collect{ |name| name.sub(/^workflow_/, '').to_sym }
|
29
|
+
actor_names.select{ |key| workflow_names[key] }
|
25
30
|
end
|
26
31
|
|
27
32
|
# All currently loaded workflows
|
@@ -146,6 +151,7 @@ module Cellect
|
|
146
151
|
# General information about this workflow
|
147
152
|
def status
|
148
153
|
{
|
154
|
+
name: name,
|
149
155
|
state: state,
|
150
156
|
grouped: false,
|
151
157
|
prioritized: prioritized,
|
data/lib/cellect/version.rb
CHANGED
@@ -10,7 +10,7 @@ module Cellect::Server
|
|
10
10
|
let(:workflow_type){ [grouping, set_type].compact.join '_' }
|
11
11
|
let(:workflow){ Workflow[workflow_type] }
|
12
12
|
let(:user){ workflow.user 123 }
|
13
|
-
before(:each){
|
13
|
+
before(:each){ pass_until_state_of workflow, is: :ready }
|
14
14
|
|
15
15
|
it 'should add seen subjects' do
|
16
16
|
async_workflow = double
|
data/spec/server/api/add_spec.rb
CHANGED
@@ -10,7 +10,7 @@ module Cellect::Server
|
|
10
10
|
let(:workflow_type){ [grouping, set_type].compact.join '_' }
|
11
11
|
let(:workflow){ Workflow[workflow_type] }
|
12
12
|
let(:user){ workflow.user 123 }
|
13
|
-
before(:each){
|
13
|
+
before(:each){ pass_until_state_of workflow, is: :ready }
|
14
14
|
|
15
15
|
let(:opts) do
|
16
16
|
{ subject_id: 123 }.tap do |h|
|
@@ -10,7 +10,7 @@ module Cellect::Server
|
|
10
10
|
let(:workflow_type){ [grouping, set_type].compact.join '_' }
|
11
11
|
let(:workflow){ Workflow[workflow_type] }
|
12
12
|
let(:user){ workflow.user 123 }
|
13
|
-
before(:each){
|
13
|
+
before(:each){ pass_until_state_of workflow, is: :ready }
|
14
14
|
|
15
15
|
let(:opts) do
|
16
16
|
{ subject_id: 123 }.tap do |h|
|
@@ -10,7 +10,7 @@ module Cellect::Server
|
|
10
10
|
let(:workflow_type){ [grouping, set_type].compact.join '_' }
|
11
11
|
let(:workflow){ Workflow[workflow_type] }
|
12
12
|
let(:user){ workflow.user 123 }
|
13
|
-
before(:each){
|
13
|
+
before(:each){ pass_until_state_of workflow, is: :ready }
|
14
14
|
|
15
15
|
it 'should sample without a user, limit, or group' do
|
16
16
|
expect(workflow).to receive(:sample).with(limit: 5, user_id: nil, group_id: nil).and_call_original
|
@@ -9,7 +9,7 @@ module Cellect::Server
|
|
9
9
|
context "#{ grouping_type } #{ set_type }" do
|
10
10
|
let(:workflow_type){ [grouping, set_type].compact.join '_' }
|
11
11
|
let(:workflow){ Workflow[workflow_type] }
|
12
|
-
before(:each){
|
12
|
+
before(:each){ pass_until_state_of workflow, is: :ready }
|
13
13
|
|
14
14
|
it 'should load users' do
|
15
15
|
async_workflow = double
|
@@ -8,7 +8,7 @@ module Cellect::Server
|
|
8
8
|
let(:workflow){ GroupedWorkflow[workflow_type] }
|
9
9
|
let(:user){ workflow.user 123 }
|
10
10
|
let(:set_klass){ workflow.prioritized? ? DiffSet::PrioritySet : DiffSet::RandomSet }
|
11
|
-
before(:each){
|
11
|
+
before(:each){ pass_until_state_of workflow, is: :ready }
|
12
12
|
|
13
13
|
it 'should provide unseen from a random group for users' do
|
14
14
|
workflow.groups = { }
|
data/spec/server/server_spec.rb
CHANGED
@@ -20,5 +20,55 @@ module Cellect::Server
|
|
20
20
|
expect(default.workflow_for('name' => 'e', 'pairwise' => true, 'prioritized' => true)).to be_prioritized
|
21
21
|
end
|
22
22
|
end
|
23
|
+
|
24
|
+
describe '/stats' do
|
25
|
+
include_context 'API'
|
26
|
+
|
27
|
+
let(:response){ JSON.parse last_response.body }
|
28
|
+
let(:all_workflows) do
|
29
|
+
[].tap do |list|
|
30
|
+
{ 'Ungrouped' => nil, 'Grouped' => 'grouped' }.each_pair do |grouping_type, grouping|
|
31
|
+
SET_TYPES.each do |set_type|
|
32
|
+
workflow_type = [grouping, set_type].compact.join '_'
|
33
|
+
list << Workflow[workflow_type]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
before(:each) do
|
40
|
+
pass_until{ all_workflows.all? &:ready? }
|
41
|
+
get :stats
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should include information' do
|
45
|
+
expect(response.keys).to match_array %w(memory cpu node_set status)
|
46
|
+
end
|
47
|
+
|
48
|
+
context 'node_set' do
|
49
|
+
let(:node_set){ response['node_set'] }
|
50
|
+
|
51
|
+
it 'should include information' do
|
52
|
+
expect(node_set['id']).to eql 'node0000000000'
|
53
|
+
expect(node_set['ready']).to eql true
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'status' do
|
58
|
+
let(:status){ response['status'] }
|
59
|
+
|
60
|
+
it 'should include the aggregate workflow status' do
|
61
|
+
expect(status['workflows_ready']).to eql true
|
62
|
+
end
|
63
|
+
|
64
|
+
context 'workflows' do
|
65
|
+
let(:workflows){ status['workflows'] }
|
66
|
+
|
67
|
+
it 'should include all workflow statuses' do
|
68
|
+
expect(workflows.length).to eql all_workflows.length
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
23
73
|
end
|
24
74
|
end
|
@@ -12,7 +12,7 @@ module Cellect::Server
|
|
12
12
|
it_behaves_like 'workflow', :workflow
|
13
13
|
let(:workflow){ Workflow[workflow_type] }
|
14
14
|
let(:user){ workflow.user 123 }
|
15
|
-
before(:each){
|
15
|
+
before(:each){ pass_until_state_of workflow, is: :ready }
|
16
16
|
|
17
17
|
it 'should provide unseen for users' do
|
18
18
|
expect(workflow.subjects).to receive(:subtract).with user.seen, 3
|
@@ -1,7 +1,16 @@
|
|
1
1
|
require 'timeout'
|
2
2
|
|
3
3
|
module CellectHelper
|
4
|
-
def pass_until(
|
4
|
+
def pass_until(&block)
|
5
|
+
Timeout::timeout(1) do
|
6
|
+
Thread.pass until block.call
|
7
|
+
end
|
8
|
+
rescue => e
|
9
|
+
puts "Timeout waiting for condition #{ block.inspect }"
|
10
|
+
raise e
|
11
|
+
end
|
12
|
+
|
13
|
+
def pass_until_state_of(obj, is:)
|
5
14
|
Timeout::timeout(1) do
|
6
15
|
Thread.pass until obj.state == is
|
7
16
|
end
|
@@ -3,20 +3,20 @@ shared_examples_for 'node set' do
|
|
3
3
|
|
4
4
|
it 'should connect to zoo keeper' do
|
5
5
|
expect(node_set.zk).to be_nil
|
6
|
-
|
6
|
+
pass_until_state_of node_set, is: :ready
|
7
7
|
expect(node_set.zk).to be_connected
|
8
8
|
end
|
9
9
|
|
10
10
|
it 'should know the connection state' do
|
11
11
|
expect(node_set.state).to be :initializing
|
12
|
-
|
12
|
+
pass_until_state_of node_set, is: :ready
|
13
13
|
expect(node_set).to be_ready
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'should accept a connection string' do
|
17
17
|
url_before = ENV['ZK_URL']
|
18
18
|
begin
|
19
|
-
|
19
|
+
pass_until_state_of node_set, is: :ready
|
20
20
|
ENV['ZK_URL'] = 'foobar'
|
21
21
|
expect(node_set.send(:zk_url)).to eq 'foobar'
|
22
22
|
ENV.delete 'ZK_URL'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cellect-server
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Parrish
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|