-
Notifications
You must be signed in to change notification settings - Fork 9
/
run-drush-sync.php
executable file
·51 lines (42 loc) · 1.3 KB
/
run-drush-sync.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
$drush = empty($argv[1]) ? 'drush' : $argv[1];
$proc_count = empty($argv[2]) ? 8 : (int) $argv[2];
$raw_dirs = glob('/var/git/repositories/project/*.git');
$dirs = preg_replace('#^/var/git/repositories/project/(.*)\.git$#', '\1', $raw_dirs);
// Pull out the biggest ones to run in just one process, keep things more even
$biggies = array('drupal');
$dirs = array_diff($dirs, $biggies);
$dirs_num = count($dirs);
$chunks = array_chunk($dirs, $dirs_num / ($proc_count - 1));
array_unshift($chunks, $biggies);
// Run forked subprocesses
$success = TRUE;
$forks = 0;
for ($i = 0; $i < $proc_count; ++$i) {
$pid = pcntl_fork();
if ($pid == -1) {
die("oh noes! no fork!");
}
elseif ($pid) {
// Parent; increment the fork counter.
$forks++;
}
else {
// Child
$child_list = $chunks[$i];
$chunk_count = (int) (count($child_list) / 3);
$child_chunks = empty($chunk_count) ? array($child_list) : array_chunk($child_list, $chunk_count);
foreach ($child_chunks as $chunk) {
$repos = implode(',', $chunk);
passthru(escapeshellcmd($drush . ' vcapi-parse-logs ' . escapeshellarg($repos)));
}
exit;
}
}
// Make sure all process finish, then exit.
while ($forks) {
$pid = pcntl_wait($status);
$success &= pcntl_wifstopped($status);
$forks--;
}
exit(!$success);