line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::bif::pull::hub; |
2
|
1
|
|
|
1
|
|
4266
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
4
|
1
|
|
|
1
|
|
1454
|
use AnyEvent; |
|
1
|
|
|
|
|
5778
|
|
|
1
|
|
|
|
|
35
|
|
5
|
1
|
|
|
1
|
|
538
|
use Bif::Sync::Client; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use Bif::Mo; |
7
|
|
|
|
|
|
|
use Coro; |
8
|
|
|
|
|
|
|
use DBIx::ThinSQL qw/qv/; |
9
|
|
|
|
|
|
|
use Log::Any '$log'; |
10
|
|
|
|
|
|
|
use Path::Tiny; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.1.5_7'; |
13
|
|
|
|
|
|
|
extends 'App::bif'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub run { |
16
|
|
|
|
|
|
|
my $self = shift; |
17
|
|
|
|
|
|
|
my $opts = $self->opts; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# Do this early so that we complain about missing repo before we |
20
|
|
|
|
|
|
|
# complain about a missing hub |
21
|
|
|
|
|
|
|
my $dbw = $self->dbw; # Consider upping PRAGMA cache_size? |
22
|
|
|
|
|
|
|
#Or handle that in Bif::Role::Sync? |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
if ( $opts->{location} =~ m!^(ssh://)?(.*)@(.*)! ) { |
25
|
|
|
|
|
|
|
$opts->{name} = $2; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
elsif ( -d $opts->{location} ) { |
28
|
|
|
|
|
|
|
$opts->{location} = path( $opts->{location} )->realpath; |
29
|
|
|
|
|
|
|
$opts->{name} = $opts->{location}->basename; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
else { |
32
|
|
|
|
|
|
|
return $self->err( 'HubNotFound', 'hub not found: %s', |
33
|
|
|
|
|
|
|
$opts->{location} ); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
$log->debug("pull hub: $opts->{location}"); |
37
|
|
|
|
|
|
|
if ( my $hub = $self->dbw->get_hub( $self->uuid2id( $opts->{location} ) ) ) |
38
|
|
|
|
|
|
|
{ |
39
|
|
|
|
|
|
|
warn "warning: hub already exists: $hub->{name}\n"; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
$|++; # no buffering |
43
|
|
|
|
|
|
|
my $error; |
44
|
|
|
|
|
|
|
my $cv = AE::cv; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
my $client = Bif::Sync::Client->new( |
47
|
|
|
|
|
|
|
name => $opts->{name}, |
48
|
|
|
|
|
|
|
db => $dbw, |
49
|
|
|
|
|
|
|
location => $opts->{location}, |
50
|
|
|
|
|
|
|
debug => $opts->{debug}, |
51
|
|
|
|
|
|
|
debug_bifsync => $opts->{debug_bifsync}, |
52
|
|
|
|
|
|
|
on_update => sub { |
53
|
|
|
|
|
|
|
my $client = shift; |
54
|
|
|
|
|
|
|
$self->lprint( $client->name . ': ' . $_[0] ); |
55
|
|
|
|
|
|
|
}, |
56
|
|
|
|
|
|
|
on_error => sub { |
57
|
|
|
|
|
|
|
$error = shift; |
58
|
|
|
|
|
|
|
$cv->send; |
59
|
|
|
|
|
|
|
}, |
60
|
|
|
|
|
|
|
); |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
my $fh = select; |
63
|
|
|
|
|
|
|
my $coro = async { |
64
|
|
|
|
|
|
|
select $fh; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
eval { |
67
|
|
|
|
|
|
|
$dbw->txn( |
68
|
|
|
|
|
|
|
sub { |
69
|
|
|
|
|
|
|
my ( $status, $ref ) = $client->pull_hub; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
print "\n"; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
$client->disconnect; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
if ( $status ne 'RepoImported' ) { |
76
|
|
|
|
|
|
|
$error = $status; |
77
|
|
|
|
|
|
|
$dbw->rollback; |
78
|
|
|
|
|
|
|
return $status; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
$dbw->xdo( |
82
|
|
|
|
|
|
|
insert_or_replace_into => |
83
|
|
|
|
|
|
|
[ 'bifkv', qw/key change_id change_id2/ ], |
84
|
|
|
|
|
|
|
select => |
85
|
|
|
|
|
|
|
[ qv('last_sync'), 'MAX(c.id)', 'MAX(c.id)', ], |
86
|
|
|
|
|
|
|
from => 'changes c', |
87
|
|
|
|
|
|
|
); |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
return $status; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
); |
92
|
|
|
|
|
|
|
}; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
if ($@) { |
95
|
|
|
|
|
|
|
$error = $@; |
96
|
|
|
|
|
|
|
print "\n"; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
return $cv->send; |
100
|
|
|
|
|
|
|
}; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
$cv->recv; |
103
|
|
|
|
|
|
|
$client->disconnect; |
104
|
|
|
|
|
|
|
return $self->err( 'Unknown', $error ) if $error; |
105
|
|
|
|
|
|
|
return $self->ok('PullHub'); |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
1; |
110
|
|
|
|
|
|
|
__END__ |