Class: Marty::PromiseJob

Inherits:
Struct
  • Object
show all
Defined in:
lib/marty/promise_job.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#attrsObject

Returns the value of attribute attrs

Returns:

  • (Object)

    the current value of attrs



92
93
94
# File 'lib/marty/promise_job.rb', line 92

def attrs
  @attrs
end

#hookObject

Returns the value of attribute hook

Returns:

  • (Object)

    the current value of hook



92
93
94
# File 'lib/marty/promise_job.rb', line 92

def hook
  @hook
end

#nodeObject

Returns the value of attribute node

Returns:

  • (Object)

    the current value of node



92
93
94
# File 'lib/marty/promise_job.rb', line 92

def node
  @node
end

#paramsObject

Returns the value of attribute params

Returns:

  • (Object)

    the current value of params



92
93
94
# File 'lib/marty/promise_job.rb', line 92

def params
  @params
end

#promiseObject

Returns the value of attribute promise

Returns:

  • (Object)

    the current value of promise



92
93
94
# File 'lib/marty/promise_job.rb', line 92

def promise
  @promise
end

#snameObject

Returns the value of attribute sname

Returns:

  • (Object)

    the current value of sname



92
93
94
# File 'lib/marty/promise_job.rb', line 92

def sname
  @sname
end

#tagObject

Returns the value of attribute tag

Returns:

  • (Object)

    the current value of tag



92
93
94
# File 'lib/marty/promise_job.rb', line 92

def tag
  @tag
end

#titleObject

Returns the value of attribute title

Returns:

  • (Object)

    the current value of title



92
93
94
# File 'lib/marty/promise_job.rb', line 92

def title
  @title
end

Instance Method Details

#max_attemptsObject



135
136
137
# File 'lib/marty/promise_job.rb', line 135

def max_attempts
  1
end

#performObject

def log(msg)

open('/tmp/dj.out', 'a') { |f| f.puts msg }

end



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/marty/promise_job.rb', line 105

def perform
  # log "PERF #{Process.pid} #{title}"

  promise.set_start

  begin
    # in case the job writes to the the database
    Mcfly.whodunnit = promise.user

    engine = Marty::ScriptSet.new(tag).get_engine(sname)

    attrs_eval = engine.evaluate(node, attrs, params)
    res = attrs.zip(attrs_eval).each_with_object({}) do |(attr, val), h|
      h[attr] = val
    end

    # log "DONE #{Process.pid} #{promise.id} #{Time.now.to_f} #{res}"
  rescue => exc
    res = Delorean::Engine.grok_runtime_exception(exc)
    # log "ERR- #{Process.pid} #{promise.id} #{Time.now.to_f} #{exc}"
  end
  promise.set_result(res)

  begin
    hook.run(res) if hook
  rescue => exc
    Marty::Util.logger.error "promise hook failed: #{exc}"
  end
end