Class: WhoIsSlacking::DataTools
- Inherits:
-
Object
- Object
- WhoIsSlacking::DataTools
- Defined in:
- lib/whois_slacking.rb
Instance Attribute Summary collapse
-
#apikey ⇒ Object
Returns the value of attribute apikey.
-
#data_format ⇒ Object
Returns the value of attribute data_format.
Class Method Summary collapse
- .save_task(project, task_id, task, user, current_state, accepted_at, url, options = {}) ⇒ Object
- .whois_key(project, task, user) ⇒ Object
- .whois_store(store_type = nil) ⇒ Object
Instance Attribute Details
#apikey ⇒ Object
Returns the value of attribute apikey.
112 113 114 |
# File 'lib/whois_slacking.rb', line 112 def apikey @apikey end |
#data_format ⇒ Object
Returns the value of attribute data_format.
111 112 113 |
# File 'lib/whois_slacking.rb', line 111 def data_format @data_format end |
Class Method Details
.save_task(project, task_id, task, user, current_state, accepted_at, url, options = {}) ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/whois_slacking.rb', line 127 def self.save_task(project, task_id, task, user, current_state, accepted_at, url, ={}) # dont use accepted_at accepted_at = accepted_at url = url created_dt = DateTime.now.to_s start_dt = DateTime.now.to_s updated_dt = created_dt current_state = current_state active = true = nil task_entity = {project: project, task_id: task_id, task: task, user: user, current_state: current_state, url: url, active: active, start_dt: start_dt, created_dt: created_dt, accepted_at: accepted_at, updated_dt: updated_dt} # initialize datastore type store = whois_store mutex = Moneta::Mutex.new(store, 'moneta') mutex.synchronize do mkey = self.whois_key(project, task_id, user) entity_exists = store[mkey] if entity_exists && entity_exists[:current_state] != 'finished' && entity_exists[:current_state] != 'delivered' && entity_exists[:current_state] != 'accepted' # -- if task/username combo exists and is not delivered/finished in db # -- calculate how long (realtime) the task has been worked on in days (.5, 1.5 etc) # -- update time on task # -- save who started task # -- publish message task/user/how long to slack # -- "Johnny has spent 2 days working on 'As a user I should be able to log in'" # keep created at date start_dt = entity_exists[:start_dt].to_datetime puts "start_dt in db was #{start_dt}" days_worked = TimeDifference.between(DateTime.now, start_dt).in_days if days_worked >= 1.0 = "*#{user}* has spent *#{days_worked.to_i} days* working on <#{url}|#{task}>" else # show hours instead # hours_worked = TimeDifference.between(DateTime.now, start_dt).in_hours # message = "*#{user} has spent #{hours_worked.to_i} hours working on #{task}*" = "*#{user}* has spent *less than a day* working on <#{url}|#{task}>" end # keep the created dt and start_dt created_dt = entity_exists[:created_dt] start_dt = entity_exists[:start_dt].to_datetime task_entity[:created_dt] = created_dt task_entity[:start_dt] = start_dt.to_s puts "start_dt in db will be #{start_dt}" store[mkey] = task_entity elsif entity_exists && entity_exists[:current_state] == 'delivered' && current_state == 'delivered' start_dt = entity_exists[:start_dt].to_datetime puts "start_dt in db for delivered state was #{start_dt}" days_worked = TimeDifference.between(DateTime.now, start_dt).in_days if days_worked >= 1.0 = "Task <#{url}|#{task}> has been in a *delivered state for #{days_worked.to_i} days*" else = "Task <#{url}|#{task}> has been in a *delivered state for less than a day*" end elsif entity_exists && entity_exists[:current_state] == 'finished' # don't do anything if entity already exists as delivered else # -- if task/username combo does not exist in db # -- save project/task/user # -- save when task was started # -- save who started task store[mkey] = task_entity if current_state != "finished" && current_state != "delivered" # -- if task is not-completed in pivotal and is not in db # -- save status as status not-completed # -- publish message task/user started today # -- "Today Johnny started 'As a user I should be able to log in'" = "Now tracking *#{user}* as doing <#{url}|#{task}>" elsif current_state == "finished" # -- if task is completed in pivotal and is not in db # -- save status as status completed # -- publish message task/user started today # -- "Today Johnny completed 'As a user I should be able to log in'" = "Today *#{user} finished* <#{url}|#{task}> and it is *waiting to be delivered*" elsif current_state == "delivered" # -- if task is completed in pivotal # -- save status as status completed # -- publish message task/user started today # -- "Today Johnny completed 'As a user I should be able to log in'" = "Today *#{user} delivered* <#{url}|#{task}> and it is *waiting to be accepted*" end end end WhoIsSlacking::SlackWrapper.post_to_slack() if end |
.whois_key(project, task, user) ⇒ Object
217 218 219 |
# File 'lib/whois_slacking.rb', line 217 def self.whois_key(project, task, user) "#{project}-#{task}-#{user}" end |
.whois_store(store_type = nil) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/whois_slacking.rb', line 114 def self.whois_store(store_type=nil) t = store_type.nil? ? ENV["WHOIS_DATA_STORE"] : store_type.to_s case t when "redis" url = ENV["REDISTOGO_URL"] || "redis://127.0.0.1:6379/" uri = URI.parse url store = Moneta.new(:Redis, host: uri.host, port: uri.port, password: uri.password) else # also for "file" store = Moneta.new(:File, :dir => 'moneta') end end |