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



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

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



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

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

#postmanObject



148
149
150
151
152
153
154
# File 'lib/lazylead/model.rb', line 148

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

#propsObject



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

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

#typeObject

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

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


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

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'


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

def unit
  trigger.last
end