Class: DubbletrackRemote::CLI
- Inherits:
-
Thor
- Object
- Thor
- DubbletrackRemote::CLI
- Includes:
- Thor::Actions, Thor::RakeCompat
- Defined in:
- lib/dubbletrack_remote/cli.rb
Instance Method Summary collapse
- #backfill(from_date = nil) ⇒ Object
- #config ⇒ Object
- #console ⇒ Object
- #import(*args) ⇒ Object
- #post(*args) ⇒ Object
- #read(*args) ⇒ Object
- #setup ⇒ Object
- #status ⇒ Object
- #update ⇒ Object
- #version ⇒ Object
- #watch ⇒ Object
Instance Method Details
#backfill(from_date = nil) ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/dubbletrack_remote/cli.rb', line 143 def backfill(from_date = nil) ensure_setup from_date = from_date ? Date.parse(from_date) : Date.today - 7.days paths = [] while from_date < Date.today paths << playlist_path_from_date(from_date) from_date += 1.day end paths.flatten! if paths.any? paths.each do |path| puts "importing #{path}" items = Reader.new(path, {cuts_path: local_cuts_file}).ingest items.each { |e| puts e.pretty_print } end else puts "could not find any files with args:" end end |
#config ⇒ Object
54 55 56 |
# File 'lib/dubbletrack_remote/cli.rb', line 54 def config system("open #{settings_path}") end |
#console ⇒ Object
177 178 179 180 181 182 183 184 |
# File 'lib/dubbletrack_remote/cli.rb', line 177 def console ensure_setup # turns on logging of SQL queries while in the task ActiveRecord::Base.logger = Logger.new(STDOUT) # starts a Ruby REPL session Pry.start end |
#import(*args) ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/dubbletrack_remote/cli.rb', line 128 def import(*args) ensure_setup paths = args_to_paths(args) if paths.any? paths.each do |path| puts "importing #{path}" items = Reader.new(path, {cuts_path: local_cuts_file}).ingest items.each { |e| puts e.pretty_print } end else puts "could not find any files with args:" end end |
#post(*args) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/dubbletrack_remote/cli.rb', line 76 def post(*args) ensure_setup paths = args_to_paths(args) if paths.any? items = paths.collect do |path| puts "reading #{path}" items = Reader.new(path, {cuts_path: local_cuts_file}).items end.flatten.sort_by(&:played_at) remaining = Item.where(id: items.pluck(:id)).remaining if remaining.count > 0 puts "sending #{remaining.size} from playlist #{file_path}" Item.where(id: remaining.pluck(:id)).remaining.find_each do |item| client.send(item) end end else puts "could not find any files with args: #{args}" end end |
#read(*args) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/dubbletrack_remote/cli.rb', line 109 def read(*args) ensure_setup paths = args_to_paths(args) if paths.any? items = paths.collect do |path| puts "reading #{path}" items = Reader.new(path, {cuts_path: local_cuts_file}).items end.flatten.sort_by(&:played_at) items.each do |e| puts e.pretty_print puts e.raw if [:raw] end else puts "could not find any files with args: #{args}" end end |
#setup ⇒ Object
59 60 61 62 |
# File 'lib/dubbletrack_remote/cli.rb', line 59 def setup create_settings_file ensure_setup end |
#status ⇒ Object
46 47 48 49 50 51 |
# File 'lib/dubbletrack_remote/cli.rb', line 46 def status ensure_setup puts "total remaining: #{Item.remaining.count}" puts "total transmitted: #{Item.successful.count}" puts "recent items needing transmission: #{Item.recent_remaining.count}" end |
#update ⇒ Object
65 66 67 68 69 70 71 72 73 |
# File 'lib/dubbletrack_remote/cli.rb', line 65 def update ensure_setup if todays_playlist_path [todays_playlist_path].flatten.each { |f| Reader.new(f, {cuts_path: local_cuts_file}).ingest } else puts "no file found matching pattern #{playlist_pattern}" end end |
#version ⇒ Object
187 188 189 190 191 |
# File 'lib/dubbletrack_remote/cli.rb', line 187 def version ensure_setup puts "version: #{DubbletrackRemote::VERSION}" end |
#watch ⇒ Object
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 41 42 |
# File 'lib/dubbletrack_remote/cli.rb', line 16 def watch ensure_setup Reader.watch(watch_path, pattern: watch_pattern) do |file| puts "detected change in #{file}" Reader.new(file, {cuts_path: local_cuts_file}).ingest end Thread.new do loop do Item.next(20).each do |item| client.send([item]) end update # this feels redundant with the watch above status rescue => e puts "errored, but will try to move on" puts e ensure sleep 10 end end backfill sleep end |