Class: GoodData::Execution

Inherits:
Rest::Resource show all
Defined in:
lib/gooddata/models/execution.rb

Instance Attribute Summary collapse

Attributes inherited from Rest::Object

#client, #project

Instance Method Summary collapse

Methods included from Mixin::ObjId

#obj_id

Methods inherited from Rest::Object

client, default_client, #saved?

Methods included from Mixin::DataPropertyReader

#data_property_reader

Methods included from Mixin::DataPropertyWriter

#data_property_writer

Methods included from Mixin::MetaPropertyReader

#metadata_property_reader

Methods included from Mixin::MetaPropertyWriter

#metadata_property_writer

Methods included from Mixin::MetaGetter

#meta

Methods included from Mixin::RootKeyGetter

#root_key

Methods included from Mixin::ContentGetter

#content

Constructor Details

#initialize(json) ⇒ Execution

Initializes object instance from raw wire JSON

Parameters:

  • json

    Json used for initialization



18
19
20
21
# File 'lib/gooddata/models/execution.rb', line 18

def initialize(json)
  super
  @json = json
end

Instance Attribute Details

#dirtyObject (readonly)

Returns the value of attribute dirty.



11
12
13
# File 'lib/gooddata/models/execution.rb', line 11

def dirty
  @dirty
end

#jsonObject (readonly) Also known as: data

Returns the value of attribute json.



11
12
13
# File 'lib/gooddata/models/execution.rb', line 11

def json
  @json
end

Instance Method Details

#==(other) ⇒ Object

Compares two executions - based on their URI



115
116
117
# File 'lib/gooddata/models/execution.rb', line 115

def ==(other)
  other.respond_to?(:uri) && other.uri == uri && other.respond_to?(:to_hash) && other.to_hash == to_hash
end

#createdObject

Timestamp when execution was created



24
25
26
# File 'lib/gooddata/models/execution.rb', line 24

def created
  Time.parse(json['execution']['createdTime'])
end

#durationObject



106
107
108
109
110
111
112
# File 'lib/gooddata/models/execution.rb', line 106

def duration
  if running?
    Time.now - started
  else
    finished && finished - started
  end
end

#error?Boolean

Has execution failed?

Returns:

  • (Boolean)


34
35
36
# File 'lib/gooddata/models/execution.rb', line 34

def error?
  status == :error
end

#finishedObject

Timestamp when execution was finished



39
40
41
# File 'lib/gooddata/models/execution.rb', line 39

def finished
  json['execution']['endTime'] && Time.parse(json['execution']['endTime'])
end

#logObject

Log for execution



44
45
46
# File 'lib/gooddata/models/execution.rb', line 44

def log
  @client.get(json['execution']['log'])
end

#ok?Boolean

Is execution ok?

Returns:

  • (Boolean)


49
50
51
# File 'lib/gooddata/models/execution.rb', line 49

def ok?
  status == :ok
end

#running?Boolean

Is execution running?

Returns:

  • (Boolean)


62
63
64
# File 'lib/gooddata/models/execution.rb', line 62

def running?
  status == :running
end

#scheduleString

Returns schedule

Returns:

  • (String)

    Schedule URL



69
70
71
# File 'lib/gooddata/models/execution.rb', line 69

def schedule
  schedule_uri && project.schedules(schedule_uri)
end

#schedule_uriString

Returns schedule URL

Returns:

  • (String)

    Schedule URL



56
57
58
59
# File 'lib/gooddata/models/execution.rb', line 56

def schedule_uri
  uri = @json['execution']['links']['self'] if @json && @json['execution'] && @json['execution']['links']
  uri.split('/')[0..-3].join('/')
end

#startedObject

Timestamp when execution was started



74
75
76
# File 'lib/gooddata/models/execution.rb', line 74

def started
  Time.parse(json['execution']['startTime'])
end

#statusObject

Status of execution



79
80
81
# File 'lib/gooddata/models/execution.rb', line 79

def status
  json['execution']['status'].downcase.to_sym
end

#uriString

Returns URL

Returns:

  • (String)

    Schedule URL



86
87
88
# File 'lib/gooddata/models/execution.rb', line 86

def uri
  @json['execution']['links']['self'] if @json && @json['execution'] && @json['execution']['links']
end

#wait_for_result(options = {}) ⇒ GoodData::Execution

Wait for execution result, status different than RUNNING or SCHEDULED

Returns:



93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/gooddata/models/execution.rb', line 93

def wait_for_result(options = {})
  start_time = Time.now
  timeout = options[:timeout]
  res = client.poll_on_response(uri, options) do |body|
    timeout_exceeded = timeout && (start_time + timeout) < Time.now
    fail 'Waiting for schedule execution timed out.' if timeout_exceeded

    body['execution'] && (body['execution']['status'] == 'RUNNING' || body['execution']['status'] == 'SCHEDULED')
  end
  @json = res
  self
end