summaryrefslogtreecommitdiff
path: root/lib/task.rb
blob: 079d3876f0167a7d17c4aeaa697461a792a15bcc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
module OpenTox

	class Task #< OpenTox

		def initialize(uri)
			super(uri)
		end

		#def self.create(uri)
		def self.create
			puts @@config[:services]["opentox-task"]
			uri = RestClient.post @@config[:services]["opentox-task"], ''#, :dataset_uri => uri
			Task.new(uri)
		end

		def self.find(params)
			Task.new(params[:uri])
		end

		def self.base_uri
			@@config[:services]["opentox-task"]
		end

		def start
			RestClient.put @uri, :status => 'started'
		end

		def stop
			RestClient.put @uri, :status => 'stopped'
		end

		def completed
			RestClient.put @uri, :status => 'completed'
		end
		 
		def status
			RestClient.get File.join(@uri, 'status')
		end

		def completed?
			self.status == 'completed'
		end

		def resource
			RestClient.get @uri
		end

		def wait_for_completion
			until self.completed?
				sleep 1
			end
		end

	end

end