Top Level Namespace

Class Method Summary collapse

Class Method Details

.playlist(playlistID, tokenID) ⇒ Object

playlistID = ARGV tokenID = “your token id” $add_variable = Hash.new



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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
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
134
135
136
137
138
139
140
# File 'lib/qacloud.rb', line 14

def self.playlist(playlistID,tokenID)
$add_variable = Hash.new
		taskhash = Qacloud.GetFirstTask(playlistID,tokenID)
			if taskhash.code == 500 then 
				#puts "Getting Task ID:"
				taskhash = Qacloud.GetTaskid(playlistID,tokenID)
				playlistID = taskhash["body"]["_id"]
				taskhash = Qacloud.GetFirstTask(playlistID,tokenID)
			end 

# collecting useful variables and values from taskhash:

			$workflow_name =  taskhash["body"]["workflow_name"]
			$workflow_id =  taskhash["body"]["workflow_id"]
			$task_name =  taskhash["body"]["task_name"]
			task_id =  taskhash["body"]["task_id"]
			$var = taskhash["body"]["task_variables"]
			$env = taskhash["body"]["environment"]
			puts "Workflow: #{$workflow_name}"
			$workflow_status = taskhash["body"]["test"]
			puts "Now Starting Task: #{$task_name}"

	begin

		 	if $var.has_key?("path") == true then
		 	  if $var["path"].empty? == false then	
				path = $var["path"]
			  end
			else 
				path = $env["path"]
			end
			require_relative "#{path}"
			dur1 = Time.now
			send($task_name)

	rescue Exception => e

		puts "Exception occured, Checkpoint should have more info."
		@erro_line = e.backtrace[0].split(":")
		@error_line = @erro_line[1]
		@error_message = "#{$!}"
		@error_line = Integer(@error_line) rescue "ErrorImage"
		dur2 = Time.now
		status = "fail"
		result = "Exception occured, Checkpoint should have more info."
		if ($checkpoint.nil?) == true then
		checkpoint = "Error Message: #{@error_message} , Script Line Number: #{@error_line}"
		else
		checkpoint = $checkpoint
		end	
		$checkpoint = nil
		duration = dur2 - dur1
		# taskhash = Qacloud.GetNextTask(task_id,tokenID,status,result,checkpoint,duration)
		# $workflow_status = "finished"
		# Take error image:
		# $browser.screenshot.save "#{dirname}/#{@error_line}.png"	
	else
			dur2 = Time.now
			status = $status
			result = $result
			checkpoint = $checkpoint
			$checkpoint = nil
			duration = dur2 - dur1	

	end

	while $workflow_status !=  "finished"
		    taskhash = Qacloud.GetNextTask(playlistID,tokenID,status,result,checkpoint,duration)
			$workflow_name =  taskhash["body"]["workflow_name"]
			$workflow_id =  taskhash["body"]["workflow_id"]
			$task_name =  taskhash["body"]["task_name"]
			task_id =  taskhash["body"]["task_id"]
			$var = taskhash["body"]["task_variables"]
			$env = taskhash["body"]["environment"]
			$workflow_status = taskhash["body"]["test"]

	break if $workflow_status == "finished"
				# if $add_variable.empty? == true then
				# else
				# $get_variable.merge!($add_variable)
				# end	
				puts "Workflow: #{$workflow_name}"
				puts "Now Starting Task: #{$task_name}"
	begin
		 	if $var.has_key?("path") == true then
		 	  if $var["path"].empty? == false then	
				path = $var["path"]
			  end
			else 
				path = $env["path"]
			end
				require_relative "#{path}"
				dur1 = Time.now
				send($task_name)
				
	rescue Exception => e
			puts "Exception occured, Checkpoint should have more info."
			@erro_line = e.backtrace[0].split(":")
			@error_line = @erro_line[1]
			@error_message = "#{$!}"
			@error_line = Integer(@error_line) rescue "ErrorImage"
			dur2 = Time.now
			status = "fail"
			result = "Exception occured, Checkpoint should have more info."
			if ($checkpoint.nil?) == true then
			checkpoint = "Error Message: #{@error_message} , Script Line Number: #{@error_line}"
			else
			checkpoint = $checkpoint
			end	
			$checkpoint = nil 
			duration = dur2 - dur1
			# taskhash = Qacloud.GetNextTask(task_id,tokenID,status,result,checkpoint,duration)
			# $workflow_status = "finished"
			# Take error image:
			# $browser.screenshot.save "#{dirname}/#{@error_line}.png"		

		else
			dur2 = Time.now
			status = $status
			result = $result
			checkpoint = $checkpoint
			$checkpoint = nil
			duration = dur2 - dur1

		end	
	end
end