Class: Lazylead::ORM::Task

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Lazylead::ORM
Defined in:
lib/lazylead/model.rb

Overview

General lazylead task.

Instance Method Summary collapse

Methods included from Lazylead::ORM

#env, #inspect, #to_h?, #to_hash, #to_s

Instance Method Details

#detect_cc(sys) ⇒ Object



130
131
132
133
134
135
# File 'lib/lazylead/model.rb', line 130

def detect_cc(sys)
  opts = props
  opts["cc"] = CC.new.detect(opts["cc"], sys)
  return opts.except "cc" if opts["cc"].is_a? EmptyCC
  opts
end

#execObject

Execute task



103
104
105
106
107
108
109
# File 'lib/lazylead/model.rb', line 103

def exec
  sys = system.connect
  opts = props
  opts = detect_cc(sys) if opts.key? "cc"
  opts["system"] = second_sys if opts.numeric? "system"
  action.constantize.new.run(sys, postman, opts)
end

#postmanObject



145
146
147
148
149
150
151
# File 'lib/lazylead/model.rb', line 145

def postman
  if props.key? "postman"
    props["postman"].constantize.new
  else
    Postman.new
  end
end

#propsObject



137
138
139
140
141
142
143
# File 'lib/lazylead/model.rb', line 137

def props
  @props ||= if team.nil?
               Opts.new(env(to_hash))
             else
               Opts.new(env(team.to_hash.merge(to_hash)))
             end
end

#second_sysObject



153
154
155
156
157
# File 'lib/lazylead/model.rb', line 153

def second_sys
  sys = System.find(props["system"])
  raise "ll-014: No ticketing system found for #{self}" if sys.nil?
  sys.connect
end

#typeObject

Scheduling type. Current implementation is based on ‘rufus-scheduler’ gem and supports

the following types: 'cron', 'interval', 'in', 'at', 'every'


114
115
116
# File 'lib/lazylead/model.rb', line 114

def type
  trigger.first
end

#unitObject

Scheduling unit. Current implementation is based on ‘rufus-scheduler’ gem thus each scheduling type has own arguments:

1. Scheduling type 'cron' has 'unit' = '00 09 * * *'
2. Scheduling type 'interval' has 'unit' = '2h'
3. Scheduling type 'every' has 'unit' = '3h'
4. Scheduling type 'in' has 'unit' = '10d'
5. Scheduling type 'at' has 'unit' = '2014/12/24 2000'


126
127
128
# File 'lib/lazylead/model.rb', line 126

def unit
  trigger.last
end