Module: RRRSpec::Server::JSONConstructor::TasksetJSONConstructor

Extended by:
ActiveSupport::Concern
Includes:
ActiveModel::Serializers::JSON
Included in:
Persistence::Taskset
Defined in:
lib/rrrspec/server/json_constructor.rb

Instance Method Summary collapse

Instance Method Details

#as_full_jsonObject



20
21
22
23
24
25
26
# File 'lib/rrrspec/server/json_constructor.rb', line 20

def as_full_json
  h = as_json(except: :id, methods: :log)
  h['slaves'] = slaves.map(&:as_full_json)
  h['tasks'] = tasks.map(&:as_full_json)
  h['worker_logs'] = worker_logs.map(&:as_full_json)
  h
end

#as_json_for_indexObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/rrrspec/server/json_constructor.rb', line 28

def as_json_for_index
  {
    'id' => id,
    'key' => key,
    'rsync_name' => rsync_name,
    'setup_command' => setup_command,
    'slave_command' => slave_command,
    'worker_type' => worker_type,
    'max_workers' => max_workers,
    'max_trials' => max_trials,
    'taskset_class' => taskset_class,
    'created_at' => created_at,
    'status' => status,
    'finished_at' => finished_at,
  }
end

#as_json_for_result_pageObject



45
46
47
48
49
# File 'lib/rrrspec/server/json_constructor.rb', line 45

def as_json_for_result_page
  as_json_for_index.merge(
    'tasks' => tasks.map(&:as_json_for_result_page),
  )
end

#as_nodetail_jsonObject



8
9
10
# File 'lib/rrrspec/server/json_constructor.rb', line 8

def as_nodetail_json
  as_json(except: :id, methods: :log)
end

#as_short_jsonObject



12
13
14
15
16
17
18
# File 'lib/rrrspec/server/json_constructor.rb', line 12

def as_short_json
  h = as_json(except: :id, methods: :log)
  h['slaves'] = slaves.map { |slave| slave.as_json(only: :key) }
  h['tasks'] = tasks.map { |task| task.as_json(only: :key) }
  h['worker_logs'] = worker_logs.map { |worker_log| worker_log.as_json(only: :key) }
  h
end

#as_summary_jsonObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/rrrspec/server/json_constructor.rb', line 51

def as_summary_json
  statuses = tasks.pluck(:status)
  groups = statuses.group_by { |status| status }
  groups.default = []

  {
    'id' => id,
    'key' => key,
    'status' => status,
    'created_at' => created_at,
    'finished_at' => finished_at,
    'task_count' => statuses.count,
    'passed_count' => groups['passed'].size,
    'pending_count' => groups['pending'].size,
    'failed_count' => groups['failed'].size,
  }
end