Awight has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/343195 )

Change subject: "disabled" flag
......................................................................

"disabled" flag

Change-Id: I055c025544c8f194cd9cfe2d21d43efadb7b5c43
---
M README.md
M crontab.py
M job_wrapper.py
A tests/data/disabled.yaml
A tests/data/scheduled/disabled.yaml
M tests/test_crontab.py
6 files changed, 28 insertions(+), 4 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/process-control 
refs/changes/95/343195/1

diff --git a/README.md b/README.md
index 9fa2527..d1653ec 100644
--- a/README.md
+++ b/README.md
@@ -18,6 +18,14 @@
 
 command: /usr/local/bin/timecard --start 9:00 --end 5:30
 
+# Optional schedule, in Vixie cron format:
+# minute hour day-of-month month day-of-week
+schedule: */5 * * * *
+
+# Optional flag to prevent scheduled job execution.  The job
+# can still be run as a single-shot.
+disabled: true
+
 # Optional timeout in seconds, after which your job will be
 # aborted.  Defaults to 10 minutes, JobWrapper.DEFAULT_TIMEOUT
 timeout: 30
@@ -52,3 +60,5 @@
 * Script to kill jobs.
 * Script to run a job one-off.
 * Job group tags.
+* Slow-start and monitoring.
+* Optional backoff.
diff --git a/crontab.py b/crontab.py
index 0f1d399..90e8908 100644
--- a/crontab.py
+++ b/crontab.py
@@ -34,7 +34,7 @@
 class JobCrontab(object):
     def __init__(self, job=None):
         self.job = job
-        if "schedule" in job.config:
+        if "schedule" in job.config and job.enabled:
             self.enabled = True
         else:
             self.enabled = False
diff --git a/job_wrapper.py b/job_wrapper.py
index e07de16..4813b3a 100644
--- a/job_wrapper.py
+++ b/job_wrapper.py
@@ -27,9 +27,15 @@
         else:
             self.timeout = DEFAULT_TIMEOUT
 
-    def run(self):
-        # if "disabled" in self.config and self.config["disabled"] in ["1", 
"true"]:
+        if "disabled" in self.config and self.config["disabled"] is True:
+            self.enabled = False
+        else:
+            self.enabled = True
 
+        if "schedule" not in self.config:
+            self.enabled = False
+
+    def run(self):
         lock.begin(job_tag=self.name)
 
         command = shlex.split(self.config["command"])
diff --git a/tests/data/disabled.yaml b/tests/data/disabled.yaml
new file mode 100644
index 0000000..c9baf66
--- /dev/null
+++ b/tests/data/disabled.yaml
@@ -0,0 +1,3 @@
+name: Disabled job
+command: /bin/true
+disabled: true
diff --git a/tests/data/scheduled/disabled.yaml 
b/tests/data/scheduled/disabled.yaml
new file mode 100644
index 0000000..46de851
--- /dev/null
+++ b/tests/data/scheduled/disabled.yaml
@@ -0,0 +1,4 @@
+name: No cron
+command: /bin/true
+disabled: true
+schedule: "* * * * *"
diff --git a/tests/test_crontab.py b/tests/test_crontab.py
index a3178be..c0503ad 100644
--- a/tests/test_crontab.py
+++ b/tests/test_crontab.py
@@ -11,7 +11,8 @@
     tab = tab.replace(test_conf_dir, "X")
     tab = tab.replace(crontab.RUNNER_PATH, "Y")
 
-    expected = """# Generated from X/schedule_2.yaml
+    expected = """# Skipping disabled job X/disabled.yaml
+# Generated from X/schedule_2.yaml
 */10 * * * * jenkins Y X/schedule_2.yaml
 # Generated from X/schedule_good.yaml
 */5 * * * * jenkins Y X/schedule_good.yaml

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I055c025544c8f194cd9cfe2d21d43efadb7b5c43
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/process-control
Gerrit-Branch: master
Gerrit-Owner: Awight <[email protected]>

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

Reply via email to