lib/gooddata/models/execution.rb in gooddata-0.6.16 vs lib/gooddata/models/execution.rb in gooddata-0.6.17
- old
+ new
@@ -34,11 +34,11 @@
status == :error
end
# Timestamp when execution was finished
def finished
- Time.parse(json['execution']['endTime'])
+ json['execution']['endTime'] && Time.parse(json['execution']['endTime'])
end
# Log for execution
def log
@client.get(json['execution']['log'])
@@ -47,10 +47,30 @@
# Is execution ok?
def ok?
status == :ok
end
+ # Returns schedule URL
+ #
+ # @return [String] Schedule URL
+ def schedule_uri
+ uri = @json['execution']['links']['self'] if @json && @json['execution'] && @json['execution']['links']
+ uri.split('/')[0..-3].join('/')
+ end
+
+ # Is execution running?
+ def running?
+ status == :running
+ end
+
+ # Returns schedule
+ #
+ # @return [String] Schedule URL
+ def schedule
+ schedule_uri && project.schedules(schedule_uri)
+ end
+
# Timestamp when execution was started
def started
Time.parse(json['execution']['startTime'])
end
@@ -73,9 +93,17 @@
res = client.poll_on_response(uri) do |body|
body['execution'] && (body['execution']['status'] == 'RUNNING' || body['execution']['status'] == 'SCHEDULED')
end
@json = res
self
+ end
+
+ def duration
+ if running?
+ Time.now - started
+ else
+ finished && finished - started
+ end
end
# Compares two executions - based on their URI
def ==(other)
other.respond_to?(:uri) && other.uri == uri && other.respond_to?(:to_hash) && other.to_hash == to_hash