EMDIS-ECS

 view release on metacpan or  search on metacpan

script/ecs_scan_mail  view on Meta::CPAN

            }

            # process message
            my $filename = $msgpart->{$seq_part_num};
            print "$DEBUG_LABEL processing \"store\" file: $filename\n"
                if $ECS_CFG->{ECS_DEBUG} > 0;
            my $msg = EMDIS::ECS::Message::read_from_file($filename);
            if(not ref $msg)
            {
                log_error("process_store(): unable to read message " .
                               "from file $filename: $msg");
                last NODE_MSG_PART;
            }
            $processed_seq_num = $seq_num;
            $err = process_message($msg, $filename, 1, \@msg_part_filenames);
            if($err)
            {
                if($err =~ /unable to decrypt message/)
                {
                    log_error("process_store(): unable to decrypt message " .
                              "from file $filename (kept in store): $err");
                    # (don't) attempt to process message as clear-text
                    # $err = process_message($msg, $filename, 0);
                    last NODE_MSG_PART;
                }
                elsif( $err =~ /received (early|duplicate) message/ ) {
                    log_info("process_store(): unable to process message " .
                             "from file $filename: $err");
                    next NODE_MSG_PART;
                }
                else {
                    log_error("process_store(): unable to process message " .
                              "from file $filename: $err");
                    last NODE_MSG_PART;
                }
            }
            foreach my $mpfn (@msg_part_filenames)
            {
                unlink $mpfn;
            }

            last NODE_MSG_PART if $processing_cutoff_time <= time();
            last NODE if $interrupted;
        }

        # check whether processing time limit has been exceeded
        if(time() >= $processing_cutoff_time) {
            log_info("process_store(): exiting early due to processing " .
                "time limit (after $node_id msg)");
            last NODE;
        }
    }

    @nodelist = ();
    $nodes = {};
    update_statistics(\@nodelist, $nodes);
}

# ----------------------------------------------------------------------
# Inspect "store" folder and compute message statistics
sub update_statistics
{
    my $nodelist = shift;
    my $nodes = shift;

    # get sorted list of files in directory
    if(not opendir(STORE, $ECS_CFG->ECS_MBX_STORE_DIR))
    {
        log_error("update_statistics(): unable to open \"store\" " .
                       "directory: " . $ECS_CFG->ECS_MBX_STORE_DIR);
        return;
    }
    my $file;
    my @filelist = ();
    while(defined($file = readdir(STORE)))
    {
        push(@filelist, $file);
    }
    closedir(STORE);
    @filelist = sort @filelist;

    # initialize $nodes hash reference
    if($ECS_NODE_TBL->lock())
    {
        my @keys = sort $ECS_NODE_TBL->keys();
        for my $node_id (@keys)
        {
            if($node_id ne $ECS_CFG->THIS_NODE)
            {
                $nodes->{$node_id} = {};
                $nodes->{$node_id}->{msgpart} = {};
                $nodes->{$node_id}->{numparts} = {};
                $nodes->{$node_id}->{docmsgpart} = {};
                $nodes->{$node_id}->{docnumparts} = {};

                # read each node's in_seq and doc_in_seq from node_tbl, for use below
                my $node = $ECS_NODE_TBL->read($node_id);
                $err = $ECS_NODE_TBL->ERROR;
                if($err)
                {
                    log_error("update_statistics(): unable to read node_tbl " .
                              "($node_id): $err\n");
                    $ECS_NODE_TBL->unlock();  # unlock node_tbl
                    return;
                }
                else
                {
                    $nodes->{$node_id}->{in_seq} = (exists $node->{in_seq} ?
                        $node->{in_seq} : 0);
                    $nodes->{$node_id}->{doc_in_seq} = (exists $node->{doc_in_seq} ?
                        $node->{doc_in_seq} : 0);
                }
            }
        }
        $ECS_NODE_TBL->unlock();  # unlock node_tbl
    }
    else
    {
        log_error("update_statistics(): unable to lock node_tbl: " .
            $ECS_NODE_TBL->ERROR . "\n");
        return;



( run in 0.351 second using v1.01-cache-2.11-cpan-d7f47b0818f )