Index: trunk/extensions/TimedMediaHandler/maintenance/WebVideoJobRunner.php |
— | — | @@ -0,0 +1,114 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Simple job runner demon suitable to be run from the can be run from the command line with a |
| 5 | + * virtual session using a unix utility such as screen. |
| 6 | + * |
| 7 | + * This could be replaced by a cron job shell script that did something similar. |
| 8 | + */ |
| 9 | + |
| 10 | +// Check if the script is already running |
| 11 | +// threads ( number of simultaneous jobs to run ) |
| 12 | +// wait 5 seconds and confirm job is running. |
| 13 | +$wgMaintenancePath = dirname( __FILE__ ) . '/../../../maintenance'; |
| 14 | +require_once( "$wgMaintenancePath/Maintenance.php" ); |
| 15 | + |
| 16 | +class WebVideoJobRunner extends Maintenance { |
| 17 | + // Default number of simultaneous transcoding threads |
| 18 | + var $threads = 2; |
| 19 | + |
| 20 | + // Default time for a transcode to time out: 4 hours, |
| 21 | + // ( should be increased if we add long form content to wikimedia ) |
| 22 | + var $transcodeTimeout = 14400; |
| 23 | + |
| 24 | + // How often the script checks for $threads transcode jobs to be active. |
| 25 | + var $checkJobsFrequency = 5; |
| 26 | + |
| 27 | + public function __construct() { |
| 28 | + parent::__construct(); |
| 29 | + $this->addOption( "threads", "The number of simultaneous transcode threads to run", false, true ); |
| 30 | + $this->addOption( "checkJobsFrequency", "How often the script checks for job threads to be active", false, true ); |
| 31 | + $this->mDescription = "Transcode job running demon, continuously runs transcode jobs"; |
| 32 | + } |
| 33 | + public function execute() { |
| 34 | + if ( $this->hasOption( "threads" ) ) { |
| 35 | + $this->threads = $this->getOption( 'threads' ) ; |
| 36 | + } |
| 37 | + |
| 38 | + // Check if WebVideoJobRuner is already running: |
| 39 | + foreach( $this->getProcessList() as $pid => $proc ){ |
| 40 | + if( strpos( $proc['args'], 'WebVideoJobRunner.php' ) !== false ){ |
| 41 | + $this->error( "WebVideoJobRunner.php is already running on this box with pid $pid" ); |
| 42 | + } |
| 43 | + } |
| 44 | + |
| 45 | + // Main runCheckJobThreadsLoop |
| 46 | + while( true ){ |
| 47 | + $this->runCheckJobThreadsLoop(); |
| 48 | + // Check again in $checkJobsFrequency seconds: |
| 49 | + sleep( $this->checkJobsFrequency ); |
| 50 | + } |
| 51 | + } |
| 52 | + function runCheckJobThreadsLoop(){ |
| 53 | + global $wgMaintenancePath; |
| 54 | + // Check if we have $threads number of webTranscode jobs running else sleep |
| 55 | + $runingJobsCount = 0; |
| 56 | + foreach( $this->getProcessList() as $pid => $proc ){ |
| 57 | + // Check that the process is a "runJobs.php" action with type webVideoTranscode argument |
| 58 | + if( strpos( $proc['args'], 'runJobs.php' ) !== false && |
| 59 | + strpos( $proc['args'], '--type webVideoTranscode' ) !== false |
| 60 | + ){ |
| 61 | + if( TimedMediaHandler::parseTimeString( $proc['time'] ) > $this->transcodeTimeout ){ |
| 62 | + |
| 63 | + } else { |
| 64 | + // Job is oky add to count: |
| 65 | + $runingJobsCount++; |
| 66 | + } |
| 67 | + } |
| 68 | + } |
| 69 | + if( $runingJobsCount < $this->threads ){ |
| 70 | + // Add one process: |
| 71 | + $cmd = "php $wgMaintenancePath/runJobs.php --type webVideoTranscode --maxjobs 1 --maxtime {$this->transcodeTimeout}"; |
| 72 | + $status = $this->runBackgroundProc( $cmd ); |
| 73 | + $this->output( "$runingJobsCount existing job runners, Starting new transcode job runner \n\n $status " ); |
| 74 | + } else { |
| 75 | + // Just output a "tick" |
| 76 | + $this->output( "$runingJobsCount transcode jobs active" ); |
| 77 | + } |
| 78 | + } |
| 79 | + |
| 80 | + function runBackgroundProc($command, $priority = 19 ){ |
| 81 | + $out = wfShellExec("nohup nice -n $priority $command > /dev/null & echo $!"); |
| 82 | + return trim( $out ); |
| 83 | + } |
| 84 | + |
| 85 | + /** |
| 86 | + * Gets a list of php process |
| 87 | + */ |
| 88 | + function getProcessList(){ |
| 89 | + // Get all the php process except for |
| 90 | + $pList = wfShellExec( 'ps axo pid,etime,args | grep php | grep -v grep' ); |
| 91 | + $pList = explode("\n", $pList ); |
| 92 | + $namedProccessList = array(); |
| 93 | + foreach( $pList as $key => $val ){ |
| 94 | + if( trim( $val) == '' ) |
| 95 | + continue; |
| 96 | + |
| 97 | + // Split the process id |
| 98 | + //$matchStatus = preg_match('/\s([0-9]+)\s+([0-9]+:?[0-9]+:[0-9]+)+\s+([^\s]+)\s(.*)/', $val, $matches); |
| 99 | + $matchStatus = preg_match('/\s*([0-9]+)\s+([0-9]+:?[0-9]+:[0-9]+)+\s+([^\s]+)\s(.*)/', $val, $matches); |
| 100 | + if( !$matchStatus ){ |
| 101 | + continue; |
| 102 | + } |
| 103 | + $namedProccessList[ $matches[1] ] = array( |
| 104 | + 'pid' => $matches[1], |
| 105 | + 'time' => $matches[2], |
| 106 | + 'args' => $matches[4], |
| 107 | + ); |
| 108 | + } |
| 109 | + return $namedProccessList; |
| 110 | + } |
| 111 | +} |
| 112 | + |
| 113 | +$maintClass = "WebVideoJobRunner"; |
| 114 | +require_once( RUN_MAINTENANCE_IF_MAIN ); |
| 115 | + |
Index: trunk/extensions/TimedMediaHandler/maintenance/cat.php |
— | — | @@ -0,0 +1,6 @@ |
| 2 | +<?php |
| 3 | +sleep(20000); |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | + |
Index: trunk/extensions/TimedMediaHandler/resources/mw.PopUpMediaTransform.js |
— | — | @@ -1,29 +0,0 @@ |
2 | | -/** |
3 | | -* Simple script to add pop-up video dialog link support for video thumbnails |
4 | | -*/ |
5 | | -( function( mw, $ ) { |
6 | | - |
7 | | - $(document).ready(function(){ |
8 | | - $('.PopUpMediaTransform').each(function(){ |
9 | | - var _parent = this; |
10 | | - $( this ).find('a').click( function(){ |
11 | | - var $video = $( unescape( $(_parent).attr('data-videopayload') ) ); |
12 | | - mw.addDialog( { |
13 | | - 'width' : parseInt( $video.css('width') ) + 20, |
14 | | - 'height' : parseInt( $video.css('height') ) + 45, |
15 | | - 'title' : $video.attr('data-mwtitle'), |
16 | | - 'content' : $video, |
17 | | - 'close' : function(){ |
18 | | - // pause the video on close ( so that playback does not continue ) |
19 | | - $(this).find('video,audio').get(0).pause(); |
20 | | - } |
21 | | - } ) |
22 | | - .css('overflow', 'hidden') |
23 | | - .find('video,audio').embedPlayer(); |
24 | | - // don't follow file link |
25 | | - return false; |
26 | | - }); |
27 | | - }); |
28 | | - }); |
29 | | - |
30 | | -} )( mediaWiki, jQuery ); |
\ No newline at end of file |
Index: trunk/extensions/TimedMediaHandler/resources/mw.PopUpThumbVideo.js |
— | — | @@ -0,0 +1,29 @@ |
| 2 | +/** |
| 3 | +* Simple script to add pop-up video dialog link support for video thumbnails |
| 4 | +*/ |
| 5 | +( function( mw, $ ) { |
| 6 | + |
| 7 | + $(document).ready(function(){ |
| 8 | + $('.PopUpMediaTransform').each(function(){ |
| 9 | + var _parent = this; |
| 10 | + $( this ).find('a').click( function(){ |
| 11 | + var $video = $( unescape( $(_parent).attr('data-videopayload') ) ); |
| 12 | + mw.addDialog( { |
| 13 | + 'width' : parseInt( $video.css('width') ) + 20, |
| 14 | + 'height' : parseInt( $video.css('height') ) + 45, |
| 15 | + 'title' : $video.attr('data-mwtitle'), |
| 16 | + 'content' : $video, |
| 17 | + 'close' : function(){ |
| 18 | + // pause the video on close ( so that playback does not continue ) |
| 19 | + $(this).find('video,audio').get(0).pause(); |
| 20 | + } |
| 21 | + } ) |
| 22 | + .css('overflow', 'hidden') |
| 23 | + .find('video,audio').embedPlayer(); |
| 24 | + // don't follow file link |
| 25 | + return false; |
| 26 | + }); |
| 27 | + }); |
| 28 | + }); |
| 29 | + |
| 30 | +} )( mediaWiki, jQuery ); |
\ No newline at end of file |
Property changes on: trunk/extensions/TimedMediaHandler/resources/mw.PopUpThumbVideo.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 31 | + native |