[Branch,~linaro-validation/lava-scheduler/trunk] Rev 250: Add job status

Message ID 20130706094521.32153.79590.launchpad@ackee.canonical.com
State Accepted
Headers show

Commit Message

Tyler Baker July 6, 2013, 9:45 a.m.
Merge authors:
  Arthur She (arthur-she)
Related merge proposals:
  https://code.launchpad.net/~arthur-she/lava-scheduler/add-job_status/+merge/172775
  proposed by: Arthur She (arthur-she)
  review: Approve - Senthil Kumaran S (stylesen)
------------------------------------------------------------
revno: 250 [merge]
committer: Tyler Baker <tyler.baker@linaro.org>
branch nick: lava-scheduler
timestamp: Sat 2013-07-06 10:44:05 +0100
message:
  Add job status
modified:
  lava_scheduler_app/api.py


--
lp:lava-scheduler
https://code.launchpad.net/~linaro-validation/lava-scheduler/trunk

You are subscribed to branch lp:lava-scheduler.
To unsubscribe from this branch go to https://code.launchpad.net/~linaro-validation/lava-scheduler/trunk/+edit-subscription

Patch

=== modified file 'lava_scheduler_app/api.py'
--- lava_scheduler_app/api.py	2013-05-02 07:35:44 +0000
+++ lava_scheduler_app/api.py	2013-07-03 09:30:33 +0000
@@ -232,3 +232,56 @@ 
             raise xmlrpclib.Fault(404, "Specified job not found.")
 
         return job
+
+    def job_status(self, job_id):
+        """
+        Name
+        ----
+        `job_status` (`job_id`)
+
+        Description
+        -----------
+        Get the status of given job id.
+
+        Arguments
+        ---------
+        `job_id`: string
+            Job id for which the output is required.
+
+        Return value
+        ------------
+        This function returns an XML-RPC structures of job status with the follwing fields.
+        The user is authenticated with an username and token.
+ 
+        `job_status`: string
+                    ['Submitted'|'Running'|'Complete'|'Incomplete'|'Canceled'|'Canceling']
+
+        `bundle_sha1`: string
+                     The sha1 hash code of the bundle, if it existed. Otherwise it will be an empty string.
+        """
+
+        if not self.user:
+            raise xmlrpclib.Fault(
+                401, "Authentication with user and token required for this "
+                "API.")
+
+        try:
+            job = TestJob.objects.accessible_by_principal(self.user).get(
+                pk=job_id)
+        except TestJob.DoesNotExist:
+            raise xmlrpclib.Fault(404, "Specified job not found.")
+
+
+        bundle_sha1 = ""
+        try:
+            bundle_sha1 = job.results_link.split('/')[-2]
+        except:
+            pass
+
+        job_status = {
+                      'job_status': job.get_status_display(),
+                      'bundle_sha1': bundle_sha1
+                     }
+
+        return job_status
+