summaryrefslogtreecommitdiff
path: root/util/multi.pl
blob: 022160eef64f135bbb514fec555e88ae5d1a7758 (plain)
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/perl

# This is just a small script to test and play around with a
# processing queue for actions on VNDB that do not have a
# strict time limit. i.e. resizing and optimizing cover images
# and (re)generating the relation graphs. Because I'm using
# the POE framework, it will also be possible to integrate
# Multi the IRC bot in the same process.
#
# The queue is an array of commands, and should be executed
# in chronological order. Commands are in the form of
#  [cmd] [arguments]
# where [cmd] is an internal command, and [arguments] a
# whitespace seperated list of arguments.
#
# Commands can be added from the web interface using shared
# memory, or from IRC if Multi is going to integrated in here.


# Usage:
#  ./multi.pl [-c] [-s] [cmd1] [cmd2] ..
#    -c  Do not daemonize, just execute the commands specified
#        on the command line and exit.
#    -s  Same as -c, but also execute commands in the shared
#        memory processing queue.
#    -a  Don't do anything, just add the commands specified on
#        the command line to the shared memory processing queue.

#
#  Multi  -  core namespace for initialisation and global variables
#

package Multi;

use strict;
use warnings;
use Tie::ShareLite ':lock';
use Time::HiRes;
use POE;
use DBI;

use lib '/www/vndb/lib';
use Multi::Core;
use Multi::RG;
use Multi::Image;
use Multi::Sitemap;
use Multi::Maintenance;
use Multi::IRC;

BEGIN { require 'global.pl' }


    $ENV{PATH} = '/usr/bin';
our $LOGDIR = '/www/vndb/data/log';
our $LOGLVL = 3; # 3:DEBUG, 2:ACTIONS, 1:WARN
our $STOP = 0;
our $DAEMONIZE = (grep /^-c$/, @ARGV) ? 1 : (grep /^-s$/, @ARGV) ? 2 : 0;
our %MODULES = ();


if(grep /^-a$/, @ARGV) {
  my $s = tie my %s, 'Tie::ShareLite', @VNDB::SHMOPTS;
  $s->lock(LOCK_EX);
  my @q = ( ($s{queue} ? @{$s{queue}} : ()), (grep !/^-/, @ARGV) );
  $s{queue} = \@q;
  $s->unlock();
  exit;
}


# one shared pgsql connection for all sessions
our $SQL = DBI->connect(@VNDB::DBLOGIN,
  { PrintError => 1, RaiseError => 0, AutoCommit => 1, pg_enable_utf8 => 1 });


Multi::Core->spawn();
Multi::RG->spawn();
Multi::Image->spawn();
Multi::Sitemap->spawn();
Multi::Maintenance->spawn();
Multi::IRC->spawn() if !$VNDB::DEBUG;


$SIG{__WARN__} = sub {(local$_=shift)=~s/\r?\n//;$poe_kernel->call(core=>log=>1,'__WARN__: '.$_)};

$poe_kernel->run();
exec $0, grep /^-/, @ARGV if $STOP == 2;