[ljcom] r9661: LJSUP-6727: RSS for Yandex - atom stream...
Committer: ssafronova
LJSUP-6727: RSS for Yandex - atom stream modified and doubled (clone have coded IP)U trunk/bin/worker/atomstream-inject U trunk/cgi-bin/ljcom.pl
Modified: trunk/bin/worker/atomstream-inject
===================================================================
--- trunk/bin/worker/atomstream-inject 2010-10-29 08:30:09 UTC (rev 9660)
+++ trunk/bin/worker/atomstream-inject 2010-10-29 09:51:02 UTC (rev 9661)
@@ -31,7 +31,8 @@
my $jid = $a->{journalid};
my $jitemid = $a->{jitemid};
- my $server = $a->{server};
+ my $servers = $a->{server} ? [ $a->{server} ] : [ @LJ::ATOMSTREAM ];
+ my $remote_ip = $a->{ip};
my $ju = LJ::load_userid($jid)
or die "No user able to be loaded\n";
my $entry = LJ::Entry->new($ju, jitemid => $jitemid);
@@ -109,22 +110,54 @@
$atom .= "<lj:coords>" . LJ::exml($entry->{props}->{current_coords}) . "</lj:coords>\n" if $entry->{props}->{current_coords};
$atom .= "<lj:adult>" . LJ::exml($entry->adult_content) . "</lj:adult>\n" if $entry->adult_content;
+ my $atom_with_ip = $atom;
+
+ # close entry in usual atom
$atom .= "</entry>\n</feed>\n";
- my $req = HTTP::Request->new(PUT => "$server");
- $req->header("Content-Type" => "text/xml");
- $req->content($atom);
+ # prepare special data
+ my $date = int(time / 24 / 60 / 60); # daily unique
+ my $coded_ip = Digest::MD5::md5_base64($remote_ip, $date, $LJ::YANDEX_ATOM_SECRET);
- if ($LJ::IS_DEV_SERVER) {
- warn "Putting Atom: [$atom]\n";
+ $atom_with_ip .= "<ui>$coded_ip</ui></entry>\n</feed>\n";
+
+ # result of servers interaction
+ my $success = 0;
+ my @status_lines;
+
+ # prepare data for all servers
+ my @data = ($atom) x scalar @$servers; # identical
+
+ # special data for special stream
+ push @data, $atom_with_ip;
+ push @$servers, $LJ::YANDEX_ATOM_STREAM;
+
+ # put data to every server
+ for (my $i = 0; $i < scalar @$servers; $i++) {
+ my $server = $servers->[$i];
+
+ my $req = HTTP::Request->new(PUT => "$server");
+ $req->header("Content-Type" => "text/xml");
+ $req->content($data[$i]);
+
+ if ($LJ::IS_DEV_SERVER) {
+ warn "Putting Atom: [$data[$i]] to $server\n";
+ }
+
+ my $res = $ua->request($req) or die "No response object($server).\n";
+ $status_lines[$i] = $res->status_line;
+ if ($res->is_success) {
+ $success++;
+ } else {
+ warn "Failed to inject($server): " . $res->status_line if $LJ::IS_DEV_SERVER;
+ }
}
- my $res = $ua->request($req) or die "No response object($server).\n";
- if ($res->is_success) {
+ if ($success) { # at least one is ok, we do not require to success all of them
$job->completed;
return;
} else {
- die "Failed to inject($server): " . $res->status_line . "\n";
+ die "Failed to inject(" . join(', ', @$servers) . "): " . join(', ', @status_lines);
}
}
Modified: trunk/cgi-bin/ljcom.pl
===================================================================
--- trunk/cgi-bin/ljcom.pl 2010-10-29 08:30:09 UTC (rev 9660)
+++ trunk/cgi-bin/ljcom.pl 2010-10-29 09:51:02 UTC (rev 9661)
@@ -1044,13 +1044,11 @@
});
if ($security eq "public") {
- foreach my $server (@LJ::ATOMSTREAM) {
- push @$joblist, TheSchwartz::Job->new_from_array("LJ::Worker::AtomStreamInject", {
- 'journalid' => $uo->{'userid'},
- 'jitemid' => $arg->{'itemid'},
- 'server' => $server,
- });
- }
+ push @$joblist, TheSchwartz::Job->new_from_array("LJ::Worker::AtomStreamInject", {
+ 'journalid' => $uo->{'userid'},
+ 'jitemid' => $arg->{'itemid'},
+ 'ip' => LJ::get_remote_ip(),
+ });
# Test a sample of posts
my $rand = int(rand(100)) + 1;
