Updated

app/models / task.rb

C
50 lines of codes
5 methods
7.2 complexity/method
1 churn
35.82 complexity
26 duplications
class Task < ActiveRecord::Base
  1. Task has no descriptive comment
validates :name, presence: true, length: { maximum: 60 } class << self def run(name, period = 12.hours, &block) task_for(name).send(:run, period, &block) end private def task_for(name) begin find_or_create_by!(name: name) rescue ActiveRecord::RecordNotUnique => e
  1. Task#task_for has the variable name 'e'
retry end end end private def run(period = 12.hours, &block) retry_lock do if pending?(period) block.call touch end end end def pending?(period) created_at == updated_at || updated_at < period.ago end def retry_lock
  1. Identical code found in 2 nodes Locations: 0 1
  2. Task#retry_lock has approx 8 statements
retried = false begin with_lock { yield } rescue PG::InFailedSqlTransaction => e
  1. Task#retry_lock has the variable name 'e'
if retried raise e else retried = true self.class.connection.clear_cache! retry end end end end