r90615 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r90614‎ | r90615 | r90616 >
Date:22:06, 22 June 2011
Author:dale
Status:deferred
Tags:
Comment:
* improved background task management with pcntl_fork ( improved upon bug 29184 )
* adds checks for valid transcode keys against enabled transcode keys
* moves getTimePassedMsg to core TMH utility as its used in multiple places now ( like api error for not enough time has passed between non-error transcode reset requests )
* adds $wgWaitTimeForTranscodeReset global to throttle reseting the transcode jobs
Modified paths:
  • /trunk/extensions/TimedMediaHandler/ApiTranscodeReset.php (modified) (history)
  • /trunk/extensions/TimedMediaHandler/MwEmbedModules/EmbedPlayer/EmbedPlayer.config.php (modified) (history)
  • /trunk/extensions/TimedMediaHandler/MwEmbedModules/EmbedPlayer/EmbedPlayer.loader.js (modified) (history)
  • /trunk/extensions/TimedMediaHandler/MwEmbedModules/EmbedPlayer/resources/mw.EmbedPlayer.js (modified) (history)
  • /trunk/extensions/TimedMediaHandler/TimedMediaHandler.php (modified) (history)
  • /trunk/extensions/TimedMediaHandler/TimedMediaHandler_body.php (modified) (history)
  • /trunk/extensions/TimedMediaHandler/TranscodeStatusTable.php (modified) (history)
  • /trunk/extensions/TimedMediaHandler/WebVideoTranscode/WebVideoTranscodeJob.php (modified) (history)

Diff [purge]

Index: trunk/extensions/TimedMediaHandler/TranscodeStatusTable.php
@@ -108,33 +108,15 @@
109109 } */
110110 // predicting percent done is not working well right now ( disabled for now )
111111 $doneMsg = '';
112 - return wfMsgHtml('timedmedia-started-transcode', self::getTimePassedMsg( $timePassed ), $doneMsg );
 112+ return wfMsgHtml('timedmedia-started-transcode', TimedMediaHandler::getTimePassedMsg( $timePassed ), $doneMsg );
113113 }
114114 // Check for job added ( but not started encoding )
115115 if( !is_null( $state['time_addjob'] ) ){
116116 $timePassed = wfTimestampNow() - $db->timestamp( $state['time_addjob'] ) ;
117 - return wfMsgHtml('timedmedia-in-job-queue', self::getTimePassedMsg( $timePassed ) );
 117+ return wfMsgHtml('timedmedia-in-job-queue', TimedMediaHandler::getTimePassedMsg( $timePassed ) );
118118 }
119119 // Return unknown status error:
120120 return wfMsgHtml('timedmedia-status-unknown');
121121 }
122 - public static function getTimePassedMsg( $timePassed ){
123 - $t['days'] = floor($timePassed/60/60/24);
124 - $t['hours'] = floor($timePassed/60/60)%24;
125 - $t['minutes'] = floor($timePassed/60)%60;
126 - $t['seconds'] = $timePassed%60;
127 -
128 - foreach( $t as $k => $v ){
129 - if($v == 0 ){
130 - unset( $t[$k] );
131 - }else{
132 - $t[$k] = wfMsg( 'timedmedia-' . $k, $v);
133 - }
134 - }
135 - if( count( $t ) == 0 ){
136 - $t = array( wfMsg( 'timedmedia-seconds', 0) ) ;
137 - }
138 - // Call to the correct set of significant measurements:
139 - return wfMsgHtml( 'timedmedia-time-' . count($t) . '-measurements', $t);
140 - }
 122+
141123 }
\ No newline at end of file
Index: trunk/extensions/TimedMediaHandler/TimedMediaHandler.php
@@ -34,6 +34,9 @@
3535 // Which users can restart failed or expired transcode jobs
3636 $wgGroupPermissions['sysop']['transcode-reset'] = true;
3737
 38+// How long you have to wait between transcode resets for non-error transcodes
 39+$wgWaitTimeForTranscodeReset = 3600;
 40+
3841 // The minimum size for an embed video player:
3942 $wgMinimumVideoPlayerSize = 200;
4043
@@ -171,5 +174,3 @@
172175 'version' => '0.2',
173176 );
174177
175 -
176 -
Index: trunk/extensions/TimedMediaHandler/TimedMediaHandler_body.php
@@ -143,6 +143,25 @@
144144 }
145145 return $time;
146146 }
 147+ public static function getTimePassedMsg( $timePassed ){
 148+ $t['days'] = floor($timePassed/60/60/24);
 149+ $t['hours'] = floor($timePassed/60/60)%24;
 150+ $t['minutes'] = floor($timePassed/60)%60;
 151+ $t['seconds'] = $timePassed%60;
 152+
 153+ foreach( $t as $k => $v ){
 154+ if($v == 0 ){
 155+ unset( $t[$k] );
 156+ }else{
 157+ $t[$k] = wfMsg( 'timedmedia-' . $k, $v);
 158+ }
 159+ }
 160+ if( count( $t ) == 0 ){
 161+ $t = array( wfMsg( 'timedmedia-seconds', 0) ) ;
 162+ }
 163+ // Call to the correct set of significant measurements:
 164+ return wfMsgHtml( 'timedmedia-time-' . count($t) . '-measurements', $t);
 165+ }
147166 /**
148167 * Converts seconds to Normal play time (NPT) time format:
149168 * consist of hh:mm:ss.ms
Index: trunk/extensions/TimedMediaHandler/ApiTranscodeReset.php
@@ -12,9 +12,8 @@
1313 * @ingroup API
1414 */
1515 class ApiTranscodeReset extends ApiBase {
16 -
1716 public function execute() {
18 - global $wgUser, $wgEnabledTranscodeSet, $wgEnableTranscode;
 17+ global $wgUser, $wgEnabledTranscodeSet, $wgEnableTranscode, $wgWaitTimeForTranscodeReset;
1918 // Check if transcoding is enabled on this wiki at all:
2019 if( !$wgEnableTranscode ){
2120 $this->dieUsage( 'Transcode is disabled on this wiki', 'disabledtranscode' );
@@ -35,11 +34,68 @@
3635 if( !TimedMediaHandlerHooks::isTranscodableTitle( $titleObj ) ){
3736 $this->dieUsage( array( 'invalidtranscodetitle', $params['title'] ) );
3837 }
39 - WebVideoTranscode::removeTranscodes( $titleObj, isset( $params['transcodekey'] )? $params['transcodekey']: false );
 38+ $transcodeKey = false;
 39+ // Make sure its a enabled transcode key we are trying to remove:
 40+ // ( if you update your transcode keys the api is not how you purge the database of expired keys )
 41+ if( isset( $params['transcodekey'] ) ){
 42+ global $wgEnabledTranscodeSet;
 43+ if( !in_array( $params['transcodekey'], $wgEnabledTranscodeSet ) ){
 44+ $this->dieUsage( 'Invalid or disabled transcode key: ' . htmlspecialchars( $params['transcodekey'] ) , 'badtranscodekey' );
 45+ } else {
 46+ $transcodeKey = $params['transcodekey'];
 47+ }
 48+ }
4049
 50+ // Don't reset if less than 1 hour has passed and we have no error )
 51+ $timeSinceLastReset = self::checkTimeSinceLastRest( $titleObj->getDBKey(), $transcodeKey );
 52+ if( $timeSinceLastReset < $wgWaitTimeForTranscodeReset){
 53+ $this->dieUsage( 'Not enough time has passed since the last reset of this transcode. ' .
 54+ TimedMediaHandler::getTimePassedMsg( $wgWaitTimeForTranscodeReset - $timeSinceLastReset ) .
 55+ ' until this transcode can be reset', 'notenoughtimereset');
 56+ }
 57+
 58+ // All good do the transcode removal:
 59+ WebVideoTranscode::removeTranscodes( $titleObj, $transcodeKey );
 60+
4161 $this->getResult()->addValue(null, 'success', 'removed transcode');
4262 }
43 -
 63+ static public function checkTimeSinceLastRest( $fileName, $transcodeKey ){
 64+ global $wgWaitTimeForTranscodeReset;
 65+ $transcodeStates = WebVideoTranscode::getTranscodeState( $fileName );
 66+ if( $transcodeKey ){
 67+ if( ! $transcodeStates[$transcodeKey] ){
 68+ // transcode key not found
 69+ return $wgWaitTimeForTranscodeReset + 1;
 70+ }
 71+ return self::getStateResetTime( $transcodeStates[$transcodeKey] );
 72+ }
 73+ // least wait is set to reset time:
 74+ $leastWait = $wgWaitTimeForTranscodeReset + 1;
 75+ // else check for lowest reset time
 76+ foreach($transcodeStates as $tk => $state ){
 77+ $ctime = self::getStateResetTime( $state );
 78+ if( $ctime < $leastWait){
 79+ $leastWait = $ctime;
 80+ }
 81+ }
 82+ return $leastWait;
 83+ }
 84+ static public function getStateResetTime( $state ){
 85+ global $wgWaitTimeForTranscodeReset;
 86+ $db = wfGetDB( DB_SLAVE );
 87+ // if an error return waitTime +1
 88+ if( !is_null( $state['time_error']) ){
 89+ return $wgWaitTimeForTranscodeReset + 1;
 90+ }
 91+ // return wait time from most recent event
 92+ foreach( array( 'time_success', 'time_startwork', 'time_addjob' ) as $timeField ){
 93+ if( !is_null( $state[ $timeField ] )){
 94+ return $db->timestamp() - $db->timestamp( $state[ $timeField ] );
 95+ }
 96+ }
 97+ // No time info, return resetWaitTime
 98+ return $wgWaitTimeForTranscodeReset + 1;
 99+ }
44100 public function mustBePosted() {
45101 return true;
46102 }
Index: trunk/extensions/TimedMediaHandler/WebVideoTranscode/WebVideoTranscodeJob.php
@@ -1,4 +1,4 @@
2 -<?php
 2+<?php
33 /**
44 * Job for transcode jobs
55 *
@@ -16,33 +16,6 @@
1717 * @ingroup JobQueue
1818 */
1919
20 -
21 -/**
22 - * Unless I am unaware of some command line trickery, we have to wrap the background
23 - * commands in a script to grab the background exit code ( echo $? )
24 - *
25 - * Ie in the bellow code "echo $?" gives us the status of "echo $1" not "nohub" call
26 - * a wait $pid & echo $? of course does not work since the background taks is not part
27 - * of a child shell call
28 - *
29 - * pseudo shell code for backgroundTask.sh
30 - *
31 -#/bin/bash
32 -
33 -# simple script to run a background and writing output and exit status to a file
34 -# returns its "pid" for proccess monitoring
35 -# Usage: backgroundTask.sh [command] [stdout target file] [pid target file] [exit status target file]
36 -
37 -# Run the command with output redirected to target file ( in the background )
38 -$1 > $2 &
39 -# Output the pid to target file:
40 -echo $! > $3
41 -# wait until task is done
42 -wait $!
43 -# output exit status:
44 -echo $? > $4
45 -
46 -*/
4720 class WebVideoTranscodeJob extends Job {
4821 var $targetEncodePath = null;
4922 var $sourceFilePath = null;
@@ -103,12 +76,12 @@
10477 );
10578 if( ! is_null( $dbStartTime ) ){
10679 $this->output( 'Error, running transcode job, for job that has already started' );
107 - // back out of this job. ( if there was a transcode error it should be restarted with api transcode-reset )
 80+ // back out of this job. ( if there was a transcode error it should be restarted with api transcode-reset )
10881 // not some strange out-of-order error.
10982 return false;
11083 }
11184
112 - // Update the transcode table letting it know we have "started work":
 85+ // Update the transcode table letting it know we have "started work":
11386 $jobStartTimeCache = $db->timestamp();
11487 $dbw->update(
11588 'transcode',
@@ -120,8 +93,8 @@
12194 __METHOD__,
12295 array( 'LIMIT' => 1 )
12396 );
124 -
125 -
 97+
 98+
12699 // Check the codec see which encode method to call;
127100 if( $options['videoCodec'] == 'theora' ){
128101 $status = $this->ffmpeg2TheoraEncode( $options );
@@ -159,17 +132,17 @@
160133 if( $status !== true ){
161134 return false;
162135 }
163 - // else just continue with db updates, and when the new job comes around it won't start because it will see
 136+ // else just continue with db updates, and when the new job comes around it won't start because it will see
164137 // that the job has already been started.
165138 }
166139
167 - // If status is oky move the file to its final destination. ( timedMediaHandler will look for it there )
168 - if( $status === true ){
 140+ // If status is oky and file exists and is larger than 0 bytes
 141+ if( $status === true && is_file( $this->getTargetEncodePath() ) && filesize( $this->getTargetEncodePath() ) > 0 ){
169142 $finalDerivativeFilePath = WebVideoTranscode::getDerivativeFilePath( $file, $transcodeKey);
170143 wfSuppressWarnings();
171 - $status = rename( $this->getTargetEncodePath(), $finalDerivativeFilePath );
 144+ $status = rename( $this->getTargetEncodePath(), $finalDerivativeFilePath );
 145+ $bitrate = round( intval( filesize( $finalDerivativeFilePath ) / $file->getLength() ) * 8 );
172146 wfRestoreWarnings();
173 - $bitrate = round( intval( filesize( $finalDerivativeFilePath ) / $file->getLength() ) * 8 );
174147 // Update the transcode table with success time:
175148 $dbw->update(
176149 'transcode',
@@ -186,7 +159,7 @@
187160 );
188161 WebVideoTranscode::invalidatePagesWithFile( $this->title );
189162 } else {
190 - // Update the transcode table with failure time and error
 163+ // Update the transcode table with failure time and error
191164 $dbw->update(
192165 'transcode',
193166 array(
@@ -200,11 +173,11 @@
201174 __METHOD__,
202175 array( 'LIMIT' => 1 )
203176 );
204 - // no need to invalidate all pages with video. Because all pages remain valid ( no $transcodeKey derivative )
 177+ // no need to invalidate all pages with video. Because all pages remain valid ( no $transcodeKey derivative )
205178 // just clear the file page ( so that the transcode table shows the error )
206179 $this->title->invalidateCache();
207180 }
208 - // Clear the webVideoTranscode cache ( so we don't keep out dated table cache around )
 181+ // Clear the webVideoTranscode cache ( so we don't keep out dated table cache around )
209182 webVideoTranscode::clearTranscodeCache( $this->title->getDBkey() );
210183
211184 // pass along result status:
@@ -280,7 +253,7 @@
281254 }
282255
283256 $this->output( "Running cmd: \n\n" .$cmd . "\n" );
284 -
 257+
285258 // Right before we output remove the old file
286259 wfProfileIn( 'ffmpeg_encode' );
287260 $retval = 0;
@@ -300,8 +273,8 @@
301274 $cmd ='';
302275 // Add the boiler plate vp8 ffmpeg command:
303276 $cmd.=" -y -skip_threshold 0 -rc_buf_aggressivity 0 -bufsize 6000k -rc_init_occupancy 4000 -threads 4";
304 -
305 - // Check for video quality:
 277+
 278+ // Check for video quality:
306279 if ( isset( $options['videoQuality'] ) && $options['videoQuality'] >= 0 ) {
307280 // Map 0-10 to 63-0, higher values worse quality
308281 $quality = 63 - intval( intval( $options['videoQuality'] )/10 * 63 );
@@ -309,7 +282,7 @@
310283 $cmd .= " -qmax " . wfEscapeShellArg( $quality );
311284 }
312285
313 - // Check for video bitrate:
 286+ // Check for video bitrate:
314287 if ( isset( $options['videoBitrate'] ) ) {
315288 $cmd.= " -qmin 1 -qmax 51";
316289 $cmd.= " -vb " . wfEscapeShellArg( $options['videoBitrate'] * 1000 );
@@ -317,7 +290,7 @@
318291 // Set the codec:
319292 $cmd.= " -vcodec libvpx";
320293
321 - // Check for aspect ratio ( we don't do anything with this right now)
 294+ // Check for aspect ratio ( we don't do anything with this right now)
322295 if ( isset( $options['aspect'] ) ) {
323296 $aspectRatio = $options['aspect'];
324297 } else {
@@ -331,14 +304,14 @@
332305 // Get size transform ( if maxSize is > file, file size is used:
333306 list( $width, $height ) = WebVideoTranscode::getMaxSizeTransform( $file, $options['maxSize'] );
334307 $cmd.= ' -s ' . intval( $width ) . 'x' . intval( $height );
335 - } elseif (
336 - (isset( $options['width'] ) && $options['width'] > 0 )
 308+ } elseif (
 309+ (isset( $options['width'] ) && $options['width'] > 0 )
337310 &&
338 - (isset( $options['height'] ) && $options['height'] > 0 )
 311+ (isset( $options['height'] ) && $options['height'] > 0 )
339312 ){
340313 $cmd.= ' -s ' . intval( $options['width'] ) . 'x' . intval( $options['height'] );
341314 }
342 -
 315+
343316 // Handle crop:
344317 $optionMap = array(
345318 'cropTop' => '-croptop',
@@ -423,9 +396,9 @@
424397
425398 // Add the output target:
426399 $cmd.= ' -o ' . wfEscapeShellArg ( $this->getTargetEncodePath() );
427 -
 400+
428401 $this->output( "Running cmd: \n\n" .$cmd . "\n" );
429 -
 402+
430403 wfProfileIn( 'ffmpeg2theora_encode' );
431404 $retval = 0;
432405 $shellOutput = $this->runShellExec( $cmd, $retval );
@@ -436,17 +409,15 @@
437410 return true;
438411 }
439412 /**
440 - * Runs the shell exec command.
 413+ * Runs the shell exec command.
441414 * if $wgEnableBackgroundTranscodeJobs is enabled will mannage a background transcode task
442 - * else it just directly passes off to wfShellExec
 415+ * else it just directly passes off to wfShellExec
443416 *
444417 * @param $cmd String Command to be run
445418 * @param $retval String, refrence variable to return the exit code
446419 */
447420 public function runShellExec( $cmd, &$retval){
448 - global $wgEnableNiceBackgroundTranscodeJobs, $wgTranscodeBackgroundPriority,
449 - $wgTranscodeBackgroundTimeLimit;
450 -
 421+ global $wgEnableNiceBackgroundTranscodeJobs, $wgTranscodeBackgroundPriority;
451422 // Check if background tasks are enabled
452423 if( $wgEnableNiceBackgroundTranscodeJobs === false ){
453424 // Dont display shell output
@@ -454,99 +425,150 @@
455426 // Directly execute the shell command:
456427 return wfShellExec( $cmd, $retval );
457428 }
458 - // Setup pointers for status and encoding log:
459 - $encodingLog = $this->getTargetEncodePath() . '.stdout.log';
460 - $exitStatusLog = $this->getTargetEncodePath() . '.exit.log';
461 -
462 - // Start background shell proc
463 - $pid = wfShellExec(
464 - "nohup nice -n $wgTranscodeBackgroundPriority $cmd > " . wfEscapeShellArg( $encodingLog ) . ' ' .
465 - // ideally we could store the exit status here ( but it causes & echo $! to give us a bad pid )
466 - // "& echo $? > " . wfEscapeShellArg( $exitStatusLog ) . ' ' .
467 - "& echo $!",
468 - $retval
469 - );
470 - $pid = trim( $pid );
471 - $errorMsg = '';
472 -
473 - if( $pid == '' || $retval != 0){
474 - $errorMsg = "Failed to start, check $wgMaxShellMemory settings";
475 - $this->output( $errorMsg);
 429+
 430+ $encodingLog = $this->getTargetEncodePath() . '.stdout.log';
 431+ $retvalLog = $this->getTargetEncodePath() . '.retval.log';
 432+ // Check that we can actually write to these files
 433+ //( no point in running the encode if we can't write )
 434+ wfSuppressWarnings();
 435+ if( ! touch( $encodingLog) || ! touch( $retvalLog ) ){
 436+ wfRestoreWarnings();
476437 $retval = 1;
477 - return $errorMsg;
 438+ return "Error could not write to target location";
478439 }
 440+ wfRestoreWarnings();
 441+
 442+ // Fork out a process for running the transcode
 443+ $pid = pcntl_fork();
 444+ if ($pid == -1) {
 445+ $errorMsg = '$wgEnableNiceBackgroundTranscodeJobs enabled but failed pcntl_fork';
 446+ $retval = 1;
 447+ $this->output( $errorMsg);
 448+ return $errorMsg;
 449+ } else if ( $pid == 0) {
 450+ // we are the child
 451+ $this->runChildCmd( $cmd, $retval, $encodingLog, $retvalLog);
 452+ // exit with the same code as the transcode:
 453+ exit( $retval );
 454+ } else {
 455+ // we are the parent monitor and return status
 456+ return $this->monitorTranscode($pid, $retval, $encodingLog, $retvalLog);
 457+ }
 458+ }
 459+ public function runChildCmd( $cmd, &$retval, $encodingLog, $retvalLog ){
 460+ global $wgTranscodeBackgroundPriority;
 461+ // In theory we should use pcntl_exec but not sure how to get the stdout, ensure
 462+ // we don't max php memory with the same protections provided by wfShellExec.
 463+
 464+ // pcntl_exec requires a direct path to the exe and arguments as an array:
 465+ //$cmd = explode(' ', $cmd );
 466+ //$baseCmd = array_shift( $cmd );
 467+ //print "run:" . $baseCmd . " args: " . print_r( $cmd, true );
 468+ //$status = pcntl_exec($baseCmd , $cmd );
 469+
 470+ // Directly execute the shell command:
 471+ //global $wgTranscodeBackgroundPriority;
 472+ //$status = wfShellExec( 'nice -n ' . $wgTranscodeBackgroundPriority . ' '. $cmd . ' 2>&1', $retval );
 473+ $status = wfShellExec( $cmd . ' 2>&1', $retval );
 474+
 475+ // Output the status:
 476+ wfSuppressWarnings();
 477+ file_put_contents( $encodingLog, $status );
 478+ // Output the retVal to the $retvalLog
 479+ file_put_contents( $retvalLog, $retval );
 480+ wfRestoreWarnings();
 481+ }
 482+
 483+ public function monitorTranscode( $pid, &$retval, $encodingLog, $retvalLog ){
 484+ global $wgTranscodeBackgroundTimeLimit, $wgLang;
 485+ $errorMsg = '';
479486 $loopCount = 0;
480487 $oldFileSize = 0;
481488 $startTime = time();
482489 $fileIsNotGrowing = false;
483 -
484 - while( true ){
485 -
486 - // Check if pid still runing
487 - if( ! self::isProcessRunning( $pid ) ){
488 - // see large note above about background tasks ( echo $? is probably not the exit status we want )
489 - $retval = wfShellExec( "echo $?");
490 - //$this->output( $pid . ' is done, $retval: ' .$retval );
491 - break;
492 - }
493 -
494 - // Check that the target file is growing ( every 5 seconds )
 490+
 491+ $this->output( "Encoding with pid: $pid \npcntl_waitpid: " . pcntl_waitpid( $pid, $status, WNOHANG OR WUNTRACED) .
 492+ "\nisProcessRunning: " . self::isProcessRunningKillZombie( $pid ) . "\n" );
 493+
 494+ // Check that the child process is still running ( note this does not work well with pcntl_waitpid
 495+ // for some reason :(
 496+ while( self::isProcessRunningKillZombie( $pid ) ) {
 497+ //$this->output( "$pid is running" );
 498+
 499+ // Check that the target file is growing ( every 5 seconds )
495500 if( $loopCount == 5 ){
496 - // only run check if we are outputing to target file
497 - // ( two pass encoding does not output to target on first pass )
 501+ // only run check if we are outputing to target file
 502+ // ( two pass encoding does not output to target on first pass )
498503 if( is_file( $this->getTargetEncodePath() ) ){
499504 clearstatcache();
500505 $newFileSize = filesize( $this->getTargetEncodePath() );
 506+ $this->output( $wgLang->formatSize( $newFileSize ). ' Total size, encoding ' .
 507+ $wgLang->formatSize( ( $newFileSize - $oldFileSize ) / 5 ) . ' per second' );
501508 if( $newFileSize == $oldFileSize ){
502509 if( $fileIsNotGrowing ){
503510 $errorMsg = "Target File is not increasing in size, kill process.";
504511 $this->output( $errorMsg );
505512 // file is not growing in size, kill proccess
506513 $retval = 1;
507 - self::killProcess( $pid );
 514+ posix_kill( $pid, 9);
508515 break;
509516 }
510 - // Wait an additional 5 seconds of the file not growing to confirm
511 - // the transcode is frozen.
 517+ // Wait an additional 5 seconds of the file not growing to confirm
 518+ // the transcode is frozen.
512519 $fileIsNotGrowing = true;
 520+ } else {
 521+ $fileIsNotGrowing = false;
513522 }
514523 $oldFileSize = $newFileSize;
515524 }
516525 // reset the loop counter
517526 $loopCount = 0;
518 - }
519 -
 527+ }
 528+
520529 // Check if we have global job run-time has been exceeded:
521530 if ( $wgTranscodeBackgroundTimeLimit && time() - $startTime > $wgTranscodeBackgroundTimeLimit ){
522531 $errorMsg = "Encoding exceeded max job run time ( " . TimedMediaHandler::seconds2npt( $maxTime ) . " ), kill process.";
523532 $this->output( $errorMsg );
524533 // File is not growing in size, kill proccess
525534 $retval = 1;
526 - self::killProcess( $pid );
 535+ posix_kill( $pid, 9);
527536 break;
528537 }
529 -
 538+
530539 // Sleep for one second before repeating loop
531540 $loopCount++;
532541 sleep( 1 );
533542 }
534 -
535 - // return the encoding log contents ( will be inserted into error table if an error )
 543+
 544+ $returnPcntl = pcntl_wexitstatus( $status );
 545+ // check status
 546+ wfSuppressWarnings();
 547+ $returnCodeFile = file_get_contents( $retvalLog );
 548+ wfRestoreWarnings();
 549+ //$this->output( "TranscodeJob:: Child pcntl return:". $returnPcntl . ' Log file exit code:' . $returnCodeFile . "\n" );
 550+
 551+ // File based exit code seems more reliable than pcntl_wexitstatus
 552+ $retval = $returnCodeFile;
 553+
 554+ // return the encoding log contents ( will be inserted into error table if an error )
536555 // ( will be ignored and removed if success )
537556 if( $errorMsg!= '' ){
538557 $errorMsg.="\n\n";
539558 }
540559 return $errorMsg . file_get_contents( $encodingLog );
541560 }
542 - public static function isProcessRunning( $pid ){
543 - exec( "ps $pid", $processState );
544 - return( count( $processState ) >= 2 );
 561+ // check if proccess is running and not a zombie
 562+ public static function isProcessRunningKillZombie( $pid ){
 563+ exec( "ps $pid", $processState );
 564+ if( !isset( $processState[1] ) ){
 565+ return false;
 566+ }
 567+ if( strpos( $processState[1], '<defunct>' ) !== false ){
 568+ posix_kill( $pid, 9);
 569+ return false;
 570+ }
 571+ return true;
545572 }
546 - public static function killProcess( $pid ){
547 - // we are killing a hung prcoces send -9 signal
548 - wfShellExec( "kill -9 $pid");
549 - }
550 -
551573 /**
552574 * Mapping between firefogg api and ffmpeg2theora command line
553575 *
@@ -591,5 +613,5 @@
592614 'license' => "--license",
593615 'contact' => "--contact"
594616 );
595 -
 617+
596618 }
Index: trunk/extensions/TimedMediaHandler/MwEmbedModules/EmbedPlayer/EmbedPlayer.config.php
@@ -23,7 +23,7 @@
2424
2525 // jQuery selector of tags to be re-written by embedPlayer
2626 // Set to empty string or null to avoid automatic video tag rewrites to embedPlayer
27 - "EmbedPlayer.RewriteTags" => "video,audio,playlist",
 27+ "EmbedPlayer.RewriteSelector" => "video,audio,playlist",
2828
2929 // Default video size ( if no size provided )
3030 "EmbedPlayer.DefaultSize" => "400x300",
Index: trunk/extensions/TimedMediaHandler/MwEmbedModules/EmbedPlayer/EmbedPlayer.loader.js
@@ -11,9 +11,9 @@
1212 */
1313 $( mw ).bind( 'SetupInterface', function( event, callback ){
1414 // Check if we have tags to rewrite:
15 - if( $( mw.getConfig( 'EmbedPlayer.RewriteTags' ) ).length ) {
16 - // Rewrite the embedPlayer EmbedPlayer.RewriteTags and run callback once ready:
17 - $( mw.getConfig( 'EmbedPlayer.RewriteTags' ) )
 15+ if( $( mw.getConfig( 'EmbedPlayer.RewriteSelector' ) ).length ) {
 16+ // Rewrite the embedPlayer EmbedPlayer.RewriteSelector and run callback once ready:
 17+ $( mw.getConfig( 'EmbedPlayer.RewriteSelector' ) )
1818 .embedPlayer( callback );
1919 }
2020 });
Index: trunk/extensions/TimedMediaHandler/MwEmbedModules/EmbedPlayer/resources/mw.EmbedPlayer.js
@@ -144,6 +144,7 @@
145145 callback();
146146 }
147147 }
 148+
148149 /**
149150 * Adds a player element for the embedPlayer to rewrite
150151 *

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r90068bug 29184 Adds background transcoding support. $wgEnableNiceBackgroundTransc...dale18:17, 14 June 2011

Status & tagging log