root/websites/coderepos.org/scripts/commit-ping-worker.pl @ 11713

Revision 9905, 1.2 kB (checked in by yappo, 5 years ago)

え、っなに? Storable::thaw しなくていいの?

  • Property svn:executable set to *
Line 
1#!/usr/bin/env perl
2package CodeRepos::CommitPing::Worker;
3use strict;
4use warnings;
5use base 'TheSchwartz::Worker';
6
7use LWP::UserAgent;
8use LWP::Simple;
9use YAML;
10
11my @servers = ();
12my $last_update = 0;
13
14sub load_servers {
15    my $ua = LWP::UserAgent->new;
16    $ua->timeout(2);
17
18    my $res = $ua->get('http://coderepos.org/share/wiki/commit-ping/SITEINFO');
19    return unless $res->is_success;
20
21    @servers = ();
22    my $html = $res->content;
23    (undef, $html) = split m{<h2 id="CommitPingServers">Commit Ping Servers</h2>}, $html;
24    while ($html =~ m!<a class="ext-link" href="(.+?)">!g) {
25        push @servers, $1;
26    }
27}
28
29sub work {
30    my($class, $job) = @_;
31
32    load_servers if $last_update + 3600 < time;
33    my $yaml = Dump($job->arg);
34
35    my $ua = LWP::UserAgent->new;
36    $ua->timeout(2);
37    for my $url (@servers) {
38        $ua->post( $url, { yaml => $yaml } );
39    }
40
41    $job->completed;
42}
43
44
45package main;
46use strict;
47use warnings;
48
49use TheSchwartz;
50
51my $database = +{
52    dsn  => shift,
53    user => shift,
54    pass => shift,
55};
56
57my $client = TheSchwartz->new( databases => [ $database ] );
58$client->can_do( 'CodeRepos::CommitPing::Worker' );
59$client->work while 1;
Note: See TracBrowser for help on using the browser.