Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl -w
- use strict;
- use warnings;
- use FindBin;
- use lib $FindBin::Bin;
- use Lib;
- use const ':constants';
- open(STDERR, '+>>', CHILD_LOG_FILE, );
- open(STDOUT, '+>>', CHILD_LOG_FILE, );
- my ($dbname,$dbuser,$dbpass, $dbhost, $dbport) = (DB_NAME, DB_LOGIN, DB_PASSWORD, DB_HOST, DB_PORT);
- my $dbh = DBI->connect("dbi:Pg:dbname=$dbname;host=$dbhost;port=$dbport", $dbuser, $dbpass,
- { RaiseError => 0,
- AutoCommit => 1,
- PrintError => 0})
- or &debug(4, $$, "Cannot connect to main DB at line ".__LINE__." in file ".__FILE__."\n");
- my ($db_ag_name,$db_ag_user,$db_ag_pass, $db_ag_host, $db_ag_port) = (DB_AGENT_NAME, DB_AGENT_LOGIN, DB_AGENT_PASSWORD, DB_AGENT_HOST, DB_AGENT_PORT);
- my $dbh_ag = DBI->connect("dbi:Pg:dbname=$db_ag_name;host=$db_ag_host;port=$db_ag_port", $db_ag_user, $db_ag_pass,
- { RaiseError => 0,
- AutoCommit => 1,
- PrintError => 0,})
- or &debug(4, $$, "Cannot connect to agents DB at line ".__LINE__." in file ".__FILE__."\n");
- my $p_pid=$ARGV[0];
- my $interval = REMOTE_OUT_DELAY;
- my $send_mail_error_count = REMOTE_SEND_MAIL_ERROR_COUNT;
- my $status = DB_USERS_REMOTE_STATUS_PROCESSING;
- my (@array, @is_ok, @params, $user_id, $user_remote_id, $is_delete, $error_count, $is_first, $server, $port, $login, $password, $is_ssl, $no_error, $error_text, $pid, $date, $date_up, $exists, $q, $sth, $rv);
- $| = 1;
- while (1) {
- $pid = $$;
- $date = &now;
- $date_up = &now_up($interval);
- $exists = kill 0, $p_pid or &debug(4, $pid, "Cannot check parent process $!\n") and exit;
- &debug(4, $pid, "Parent is not running, i die\n") and exit if !$exists;
- ## select
- if ($rv ne "0E0") {
- while(@array = $sth->fetchrow_array()) {
- $user_remote_id = $array[0];
- $user_id = $array[1];
- $error_count = $array[9];
- $is_delete = $array[20];
- $is_first = $array[22];
- $server = $array[2];
- $port = $array[3] ? $array[3] : 143;
- $login = $array[4];
- $password = decode_base64($array[5]);
- $is_ssl = $array[12];
- }
- &debug(1, $pid, "=================== START DEBUGING ===================\n");
- @is_ok = &get_remote_email($dbh, $dbh_ag, $user_id, $user_remote_id, $is_first, $is_delete, $server, $port, $login, $password, $is_ssl, $pid);
- $no_error = $is_ok[0];
- $error_text = $is_ok[1];
- @params;
- $params[1] = $error_text;
- $params[2] = DB_USERS_REMOTE_STATUS_NEW;
- $params[3] = REMOTE_MAX_ERROR_COUNT;
- if ($no_error) {
- ## update1
- } else {
- # &debug(3, $pid, $error_text);
- $error_count = 1 + $error_count;
- if ($error_count >= $params[3]) {
- ## update2
- } else {
- ## update3
- }
- }
- &debug(1, $pid, "=================== END DEBUGING =====================\n");
- }
- (@array, @is_ok, @params, $user_id, $user_remote_id, $is_delete, $error_count, $is_first, $server, $port, $login, $password, $is_ssl, $no_error, $error_text, $pid, $date, $date_up, $exists, $q, $sth, $rv) = undef;
- usleep(DAEMON_CHILD_DELAY);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement