Class: SleepRoom::Record::Tasks
- Inherits:
-
Object
- Object
- SleepRoom::Record::Tasks
- Defined in:
- lib/sleeproom/record/tasks.rb
Class Method Summary collapse
Class Method Details
.add(room, group) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/sleeproom/record/tasks.rb', line 88 def self.add(room, group) Async do group = "default" if group.empty? old_record = SleepRoom.load_config(:record) name = API::RoomAPI.new(room).room_name input_record = {"room" => room, "name" => name} if !old_record[group].nil? && new_record = old_record[group].find{|h| h = input_record if h["room"] == room} SleepRoom.error("Room #{room} already exists.") else old_record[group] = [] if old_record[group].nil? old_record[group].push(input_record) new_record = old_record SleepRoom.write_config_file(:record, new_record) SleepRoom.info("Added success.") end end end |
.remove(room) ⇒ Object
106 107 108 109 110 111 |
# File 'lib/sleeproom/record/tasks.rb', line 106 def self.remove(room) old_record = SleepRoom.load_config(:record) new_record = old_record.each {|k, v| v.delete_if { |h| h["room"] == room }} SleepRoom.write_config_file(:record, new_record) SleepRoom.info("Remove success.") end |
.start ⇒ void
This method returns an undefined value.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/sleeproom/record/tasks.rb', line 8 def self.start Async do |_task| count = 0 write_status = WriteStatus.new SleepRoom.reload_config if SleepRoom.running? SleepRoom.error("PID #{SleepRoom.load_pid} Process is already running.") exit else SleepRoom.write_config_file(:status, []) end SleepRoom.create_pid(Process.pid) lists = SleepRoom.load_config(:record) lists.each do |group, list| SleepRoom.info("Empty list.") if list.empty? list.each do |room| record = SleepRoom::Record::Showroom.new(room: room["room"], group: group, queue: write_status) record.record count += 1 end rescue SleepRoom.error("Cannot parse Recording list.") end write_status.run SleepRoom.info("共启动 #{count} 个任务.") wait rescue => e puts e. end rescue Exception SleepRoom.create_pid(nil) unless SleepRoom.running? puts "Exit..." end |
.status ⇒ void
This method returns an undefined value.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/sleeproom/record/tasks.rb', line 49 def self.status Async do SleepRoom.reload_config status = SleepRoom.load_status pid = SleepRoom.load_config(:pid) if !SleepRoom.running?(pid) || status.empty? || pid.nil? lists = SleepRoom.load_config(:record) SleepRoom.info("No tasks running.") lists.each do |group, list| next if list.empty? rows = [] title = group headings = list[0].keys list.each do |hash| rows.push(hash.values) end puts Terminal::Table.new(title: "[Recording list] Group: #{title}",:rows => rows, headings: headings) end else rows = [] headings = status[0].keys status.each do |hash| rows.push( hash.values.map do |s| if s.is_a?(Hash) "#{(s[:last_ack].is_a?(Time) ? "[ACK]" + s[:last_ack].strftime("%H:%M:%S").to_s : "nil")}" elsif s.is_a?(Time) s.strftime("%H:%M:%S") else s.to_s end end ) end puts Terminal::Table.new(title: "Status [PID #{pid}] (#{status.count})",:rows => rows, headings: headings) end end end |
.stop ⇒ void
This method returns an undefined value.
43 44 45 46 |
# File 'lib/sleeproom/record/tasks.rb', line 43 def self.stop SleepRoom.reload_config raise "未实现" end |