MCPcopy Create free account
hub / github.com/apache/cloudstack / __poll

Method __poll

tools/marvin/marvin/cloudstackConnection.py:78–123  ·  view source on GitHub ↗

@Name : __poll @Desc: polls for the completion of a given jobid @Input 1. jobid: Monitor the Jobid for CS 2. response_cmd:response command for request cmd @return: FAILED if jobid is cancelled,failed Else return async_response

(self, jobid, response_cmd)

Source from the content-addressed store, hash-verified

76 self.path)
77
78 def __poll(self, jobid, response_cmd):
79 '''
80 @Name : __poll
81 @Desc: polls for the completion of a given jobid
82 @Input 1. jobid: Monitor the Jobid for CS
83 2. response_cmd:response command for request cmd
84 @return: FAILED if jobid is cancelled,failed
85 Else return async_response
86 '''
87 try:
88 cmd = queryAsyncJobResult.queryAsyncJobResultCmd()
89 cmd.jobid = jobid
90 timeout = self.asyncTimeout
91 start_time = time.time()
92 end_time = time.time()
93 async_response = FAILED
94 self.logger.debug("=== Jobid: %s Started ===" % (str(jobid)))
95 while timeout > 0:
96 async_response = self.\
97 marvinRequest(cmd, response_type=response_cmd)
98 if async_response != FAILED:
99 job_status = async_response.jobstatus
100 if job_status in [JOB_CANCELLED,
101 JOB_SUCCEEDED]:
102 break
103 elif job_status == JOB_FAILED:
104 raise Exception("Job failed: %s"\
105 % async_response)
106 time.sleep(1)
107 timeout -= 1
108 self.logger.debug("=== JobId:%s is Still Processing, "
109 "Will TimeOut in:%s ====" % (str(jobid),
110 str(timeout)))
111 end_time = time.time()
112 tot_time = int(start_time - end_time)
113 self.logger.debug(
114 "===Jobid:%s ; StartTime:%s ; EndTime:%s ; "
115 "TotalTime:%s===" %
116 (str(jobid), str(time.ctime(start_time)),
117 str(time.ctime(end_time)), str(tot_time)))
118 return async_response
119 except Exception as e:
120 self.__lastError = e
121 self.logger.exception("==== __poll: Exception Occurred :%s ====" %
122 str(self.__lastError))
123 return FAILED
124
125 def getLastError(self):
126 '''

Callers 1

__parseAndGetResponseMethod · 0.95

Calls 4

marvinRequestMethod · 0.95
intFunction · 0.85
debugMethod · 0.80
sleepMethod · 0.45

Tested by

no test coverage detected