Ori.livneh has submitted this change and it was merged.

Change subject: Allow 0 runner loops and added some sanity checks
......................................................................


Allow 0 runner loops and added some sanity checks

Change-Id: I5124d875ede20efadf36acb37744ed7196928321
---
M redisJobRunnerService
1 file changed, 10 insertions(+), 2 deletions(-)

Approvals:
  Ori.livneh: Verified; Looks good to me, approved



diff --git a/redisJobRunnerService b/redisJobRunnerService
index 065a8ac..f0b51eb 100755
--- a/redisJobRunnerService
+++ b/redisJobRunnerService
@@ -170,8 +170,10 @@
 
                foreach ( explode( '|', $config['runners'] ) as $loop ) {
                        list( $runners, $types ) = explode( ':', trim( $loop ) 
);
-                       if ( !ctype_digit( $runners ) || $runners < 1 ) {
+                       if ( !preg_match( '/^\d+$/', $runners ) ) {
                                throw new Exception( "Invalid number of job 
runners '$runners'." );
+                       } elseif ( $runners == 0 ) {
+                               continue; // loop disabled
                        }
                        $types = explode( ',', $types );
                        foreach ( $types as $type ) {
@@ -180,7 +182,7 @@
                                        throw new Exception( "Invalid job type 
'$type'." );
                                }
                        }
-                       $this->loopMap[] = array( 'types' => $types, 'runners' 
=> $runners );
+                       $this->loopMap[] = array( 'types' => $types, 'runners' 
=> (int)$runners );
                }
 
                if ( isset( $config['timeout'] ) ) {
@@ -200,6 +202,9 @@
                        $tuples = explode( ',', $config['claimTTL'] );
                        foreach ( $tuples as $tuple ) {
                                list( $type, $value ) = explode( ':', trim( 
$tuple ) );
+                               if ( $value < 30 ) {
+                                       throw new Exception( "Invalid claim TTL 
'$value'." );
+                               }
                                $this->claimTTLMap[$type] = (int)$value;
                        }
                }
@@ -208,6 +213,9 @@
                        $tuples = explode( ',', $config['attempts'] );
                        foreach ( $tuples as $tuple ) {
                                list( $type, $value ) = explode( ':', trim( 
$tuple ) );
+                               if ( $value < 1 ) {
+                                       throw new Exception( "Invalid max 
attempts '$value'." );
+                               }
                                $this->attemptsMap[$type] = (int)$value;
                        }
                }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I5124d875ede20efadf36acb37744ed7196928321
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/jobrunner
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Ori.livneh <[email protected]>

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

Reply via email to