Parcourir la source

On lance bien le traitement une fois toutes les X secondes (même si plusieurs statuts à demander).
Version du bartender.php pour debugger.

njean42 il y a 7 ans
Parent
commit
c3ca237cac
2 fichiers modifiés avec 16 ajouts et 7 suppressions
  1. 4 4
      ajax/bartender.php
  2. 12 3
      js/bartender.js

+ 4 - 4
ajax/bartender.php

@@ -68,11 +68,11 @@ function shake() {
 	foreach (['projetPadPrincipal','projetPadGarde','dossier','projetId'] as $p)
 		$params[$p] = escapeshellarg($params[$p]);
 	
-	$nowait = '> /dev/null 2>&1 &';
-	$cmd = "$cocktailbin -d {$params['dossier']} -b {$params['projetPadPrincipal']} -g {$params['projetPadGarde']} -p {$params['projetId']} $nowait";
+//	$nowait = '> /dev/null 2>&1 &';
+	$cmd = "$cocktailbin -d {$params['dossier']} -b {$params['projetPadPrincipal']} -g {$params['projetPadGarde']} -p {$params['projetId']}";
 	
-	exec($cmd);
-	response([],$cmd);
+	exec($cmd,$output);
+	response([],array_merge(['Commande :','$cmd','Output:'],$output));
 }
 
 

+ 12 - 3
js/bartender.js

@@ -4,6 +4,7 @@ $(document).delegate( '.js-bartend', 'click', function () {
 	
 	$.ajax({
 		url: '/ajax/bartender.php',
+//		type: 'post',
 		data: {
 			action: 'shake',
 			dossier: $(this).data('dossier'),
@@ -27,10 +28,13 @@ $(document).delegate( '.js-bartend', 'click', function () {
 
 
 function status () {
+	var deferreds = [];
+	var need_refresh = 0;
+	
 	$('.js-status').each( function () {
 		var statusdiv = $(this);
 		
-		$.ajax({
+		deferreds.push($.ajax({
 			url: '/ajax/bartender.php',
 			data: {
 				action: 'status',
@@ -46,12 +50,17 @@ function status () {
 				statusdiv.find('.js-time-placeholder').text(data.time);
 				
 				if (data.status === 'IN_PROGRESS')  // on relance la vérif de statut dans 3s pour voir si la compil est terminée
-					setTimeout(status,3000);
+					need_refresh++;
 			},
 			error: function () {
 				alert("Je n'ai pas pu contacter le barman pour le statut de compilation...");
 			}
-		});
+		}));
+	});
+	
+	$.when.apply($,deferreds).done( function () {
+		if (need_refresh > 0)
+			setTimeout(status,3000);
 	});
 }
 $(document).ready( function () {