jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/381278 )

Change subject: Process-control code cleanup
......................................................................


Process-control code cleanup

Tabs -> spaces, delete unused imports, define fields in init

Change-Id: Ia45b180b5dc96a5dd9cad09a0a11b326649842de
---
M bin/check-jobs-icinga
M bin/cron-generate
M bin/run-job
M processcontrol/runner.py
4 files changed, 89 insertions(+), 89 deletions(-)

Approvals:
  XenoRyet: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/bin/check-jobs-icinga b/bin/check-jobs-icinga
index d2a3618..9126e76 100755
--- a/bin/check-jobs-icinga
+++ b/bin/check-jobs-icinga
@@ -11,43 +11,43 @@
 
 
 def report_statuses():
-       """Build response string and exit code from statuses."""
-       statuses = load_statuses()
-       bad_jobs = []
-       for job, status in statuses.items():
-               # Be conservative about what is failure, for now.  Eventually, 
we
-               # should warn about invalid and unknown.
-               if status == "failure":
-                       bad_jobs.append(job)
+    """Build response string and exit code from statuses."""
+    statuses = load_statuses()
+    bad_jobs = []
+    for job, status in statuses.items():
+        # Be conservative about what is failure, for now.  Eventually, we
+        # should warn about invalid and unknown.
+        if status == "failure":
+            bad_jobs.append(job)
 
-       if len(bad_jobs) == 0:
-               print("JOBS OK")
-               sys.exit(0)
-       else:
-               bad_jobs_message = ", ".join(bad_jobs)
-               print("FAILING JOBS: {jobs}".format(jobs=bad_jobs_message))
-               sys.exit(2)
+    if len(bad_jobs) == 0:
+        print("JOBS OK")
+        sys.exit(0)
+    else:
+        bad_jobs_message = ", ".join(bad_jobs)
+        print("FAILING JOBS: {jobs}".format(jobs=bad_jobs_message))
+        sys.exit(2)
 
 
 def load_statuses():
-       """Fetch statuses from history files."""
-       statuses = {}
-       jobs = job_spec.list()
-       for job in jobs:
-               try:
-                       state = job_state.load_state(job)
-               except:
-                       statuses[job] = "invalid"
-               if state.last_completion_status is None:
-                       statuses[job] = "unknown"
-               else:
-                       statuses[job] = state.last_completion_status
+    """Fetch statuses from history files."""
+    statuses = {}
+    jobs = job_spec.list()
+    for job in jobs:
+        try:
+            state = job_state.load_state(job)
+        except:
+            statuses[job] = "invalid"
+        if state.last_completion_status is None:
+            statuses[job] = "unknown"
+        else:
+            statuses[job] = state.last_completion_status
 
-       return statuses
+    return statuses
 
 
 if __name__ == "__main__":
-       parser = argparse.ArgumentParser(description="Report the status of all 
`process-control` jobs in a format that can be consumed by Icinga.")
-       args = parser.parse_args()
+    parser = argparse.ArgumentParser(description="Report the status of all 
`process-control` jobs in a format that can be consumed by Icinga.")
+    args = parser.parse_args()
 
-       report_statuses()
+    report_statuses()
diff --git a/bin/cron-generate b/bin/cron-generate
index 92b6ab1..a657404 100755
--- a/bin/cron-generate
+++ b/bin/cron-generate
@@ -1,7 +1,5 @@
 #!/usr/bin/python3
 
-import sys
-
 from processcontrol import crontab
 
 
diff --git a/bin/run-job b/bin/run-job
index d2edf5e..eaea0c7 100755
--- a/bin/run-job
+++ b/bin/run-job
@@ -1,7 +1,6 @@
 #!/usr/bin/python3
 
 import argparse
-import sys
 import yaml
 
 from processcontrol import runner
@@ -10,69 +9,69 @@
 
 
 def list_jobs(verbose):
-       for job_slug in job_spec.list():
-               try:
-                       if verbose:
-                               # FIXME: Nicer if this inner loop moved to Job 
rather than having
-                               # status come from an ephemeral runner.
-                               job = job_spec.load(job_slug)
-                               message = "{job} - {name}".format(job=job_slug, 
name=job.name)
-                               status = runner.JobRunner(job).status()
-                               if status is not None:
-                                       message += "    " + 
yaml.dump(status).strip()
+    for job_slug in job_spec.list():
+        try:
+            if verbose:
+                # FIXME: Nicer if this inner loop moved to Job rather than 
having
+                # status come from an ephemeral runner.
+                job = job_spec.load(job_slug)
+                message = "{job} - {name}".format(job=job_slug, name=job.name)
+                status = runner.JobRunner(job).status()
+                if status is not None:
+                    message += "\t" + yaml.dump(status).strip()
 
-                               # TODO: command-line flag to verbose or not.
-                               if job.description is not None:
-                                       message += "\n  " + job.description
+                # TODO: command-line flag to verbose or not.
+                if job.description is not None:
+                    message += "\n\t" + job.description
 
-                               if len(job.tags) > 0:
-                                       message += "\n  tags: " + ", 
".join(job.tags)
+                if len(job.tags) > 0:
+                    message += "\n\ttags: " + ", ".join(job.tags)
 
-                               stored_state = job_state.load_state(job_slug)
-                               message += "\n  last status: " + 
stored_state.last_completion_status
-                       else:
-                               message = job_slug
+                stored_state = job_state.load_state(job_slug)
+                message += "\n\tlast status: " + 
stored_state.last_completion_status
+            else:
+                message = job_slug
 
-               except AssertionError:
-                       if verbose:
-                               message = "{job} ***Invalid 
configuration***".format(job=job_slug)
-                       else:
-                               break
+        except AssertionError:
+            if verbose:
+                message = "{job} ***Invalid 
configuration***".format(job=job_slug)
+            else:
+                break
 
-               print(message)
+        print(message)
 
 
 if __name__ == "__main__":
-       # TODO: Change the function name or move responsibilities beyond "run" 
to a
-       # new script.
-       parser = argparse.ArgumentParser(description="Run or query 
`process-control` jobs.")
-       job_group = parser.add_mutually_exclusive_group()
-       job_group.add_argument("job", nargs="?", help="Run a given job.", 
type=str)
-       job_group.add_argument("-j", "--job", dest="job_name", help="Run a 
given job.", type=str)
-       parser.add_argument("-l", "--list-jobs", help="Print a list of 
available jobs.", action='store_true')
-       parser.add_argument("-s", "--status", help="Print status of all jobs.", 
action='store_true')
-       parser.add_argument(
-               "-w",
-               "--slow-start",
-               dest="slow_start",
-               help="Slow start a job, if a slow-start configuration has been 
supplied.",
-               action="store_true"
-       )
-       # TODO: --kill-job, --disable-group, --enable-group
-       args = parser.parse_args()
+    # TODO: Change the function name or move responsibilities beyond "run" to a
+    # new script.
+    parser = argparse.ArgumentParser(description="Run or query 
`process-control` jobs.")
+    job_group = parser.add_mutually_exclusive_group()
+    job_group.add_argument("job", nargs="?", help="Run a given job.", type=str)
+    job_group.add_argument("-j", "--job", dest="job_name", help="Run a given 
job.", type=str)
+    parser.add_argument("-l", "--list-jobs", help="Print a list of available 
jobs.", action='store_true')
+    parser.add_argument("-s", "--status", help="Print status of all jobs", 
action='store_true')
+    parser.add_argument(
+        "-w",
+        "--slow-start",
+        dest="slow_start",
+        help="Slow start a job, if a slow-start configuration has been 
supplied.",
+        action="store_true"
+    )
+    # TODO: --kill-job, --disable-group, --enable-group
+    args = parser.parse_args()
 
-       job_name = None
-       if args.job_name is not None:
-               job_name = args.job_name
-       if args.job is not None:
-               job_name = args.job
-       if job_name is not None:
-               job = job_spec.load(job_name)
-               runner = runner.JobRunner(job)
-               runner.run(**vars(args))
+    job_name = None
+    if args.job_name is not None:
+        job_name = args.job_name
+    if args.job is not None:
+        job_name = args.job
+    if job_name is not None:
+        job = job_spec.load(job_name)
+        runner = runner.JobRunner(job)
+        runner.run(**vars(args))
 
-       if args.list_jobs:
-               list_jobs(False)
+    if args.list_jobs:
+        list_jobs(False)
 
-       if args.status:
-               list_jobs(True)
+    if args.status:
+        list_jobs(True)
diff --git a/processcontrol/runner.py b/processcontrol/runner.py
index ed7ec93..32a3e08 100644
--- a/processcontrol/runner.py
+++ b/processcontrol/runner.py
@@ -13,11 +13,14 @@
 
 
 class JobRunner(object):
+
     def __init__(self, job):
         self.global_config = config.GlobalConfiguration()
         self.job = job
         self.mailer = mailer.Mailer(self.job)
         self.logfile = None
+        self.process = None
+        self.start_time = None
 
         self.killer_was_me = False
         self.failure_reason = None

-- 
To view, visit https://gerrit.wikimedia.org/r/381278
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ia45b180b5dc96a5dd9cad09a0a11b326649842de
Gerrit-PatchSet: 3
Gerrit-Project: wikimedia/fundraising/process-control
Gerrit-Branch: master
Gerrit-Owner: Ejegg <[email protected]>
Gerrit-Reviewer: AndyRussG <[email protected]>
Gerrit-Reviewer: Cdentinger <[email protected]>
Gerrit-Reviewer: Eileen <[email protected]>
Gerrit-Reviewer: Katie Horn <[email protected]>
Gerrit-Reviewer: Mepps <[email protected]>
Gerrit-Reviewer: XenoRyet <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to