Class: JIJI::Service::OutputService

Inherits:
Object
  • Object
show all
Defined in:
lib/jiji/service/output_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#process_dirObject

Returns the value of attribute process_dir.



57
58
59
# File 'lib/jiji/service/output_service.rb', line 57

def process_dir
  @process_dir
end

#process_managerObject

Returns the value of attribute process_manager.



58
59
60
# File 'lib/jiji/service/output_service.rb', line 58

def process_manager
  @process_manager
end

Instance Method Details

#get_log(process_id) ⇒ Object

プロセスのログを取得する



47
48
49
50
51
52
53
54
55
# File 'lib/jiji/service/output_service.rb', line 47

def get_log( process_id )
  process_manager.get( process_id ) # プロセスの存在確認
  file = "#{@process_dir}/#{process_id}/log.txt" # TODO 古いものも連結するか? サイズが大きくなってしまうので微妙。
  if ( File.exist?( file ) ) 
    return IO.read( file )
  else
    return ""
  end
end

#list_datas(process_id, names, scale, start_time, end_time) ⇒ Object

指定範囲の出力データを取得する。



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/jiji/service/output_service.rb', line 6

def list_datas( process_id, names, scale, start_time, end_time )
  p = process_manager.get( process_id )
  list = {}
  names.each {|n|
   buff = []
    outputs = p.outputs[n[0]]
   next unless outputs
    outputs.get(n[1]).each( scale,
      Time.at(start_time), Time.at(end_time) ) {|data|
     buff << data
   }
    list[n[0]] = {} if !list[n[0]]
    list[n[0]][n[1]] = buff
  }
  return list
end

#list_outputs(process_id) ⇒ Object

プロセスの出力一覧を取得する



24
25
26
27
28
29
30
31
32
33
# File 'lib/jiji/service/output_service.rb', line 24

def list_outputs( process_id )
  p = process_manager.get( process_id )
  return p.outputs.inject({}) {|buff,item|
    buff[item[0]] = item[1].inject({}) {|r,v|
      r[v[0]] = v[1].options
      r
    }
    buff
  }
end

#set_properties(process_id, name, properties) ⇒ Object

アウトプットのプロパティを設定

Raises:



36
37
38
39
40
41
42
43
44
# File 'lib/jiji/service/output_service.rb', line 36

def set_properties( process_id, name, properties )
  p = process_manager.get( process_id )
  outputs = p.outputs[name[0]]
  raise UserError.new( JIJI::ERROR_NOT_FOUND, "output not found. name=#{name[0]}") unless outputs
  out = outputs.get(name[1])
  raise UserError.new( JIJI::ERROR_NOT_FOUND, "output not found. name=#{name[0]}:#{name[1]}") unless out
  out.set_properties( properties )
  return :success
end