diff options
author | Martin Gütlein <martin.guetlein@gmail.com> | 2010-03-25 19:39:29 +0100 |
---|---|---|
committer | Martin Gütlein <martin.guetlein@gmail.com> | 2010-03-25 19:39:29 +0100 |
commit | 0230d687322bab8c0fd24cf41e33a28554a364db (patch) | |
tree | 9dba7f07db99cd96e220236dbf84989441ce5f44 /lib/task.rb | |
parent | 7c6b9a46e012a3e541f63d245c344e5876d7da5e (diff) |
wrapper adjustments for validation
Diffstat (limited to 'lib/task.rb')
-rw-r--r-- | lib/task.rb | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/lib/task.rb b/lib/task.rb index 5591a34..75cc2d2 100644 --- a/lib/task.rb +++ b/lib/task.rb @@ -90,7 +90,37 @@ module OpenTox until self.completed? or self.failed? sleep dur end - end + end + + def self.as_task + task = OpenTox::Task.create + LOGGER.debug "Starting task" + pid = Spork.spork(:logger => LOGGER) do + task.started + LOGGER.debug "Task #{task.uri} started #{Time.now}" + begin + result = yield + task.completed(result) + rescue => ex + raise ex + LOGGER.error ex.message + task.failed + end + raise "Invalid task state" unless task.completed? || task.failed? + end + LOGGER.debug "task PID: " + pid.to_s + task.pid = pid + task.uri + end + + def wait_for_resource + wait_for_completion + if failed? + LOGGER.error "task failed: "+uri.to_s + return nil + end + return resource + end end |