#!/usr/bin/perl

use strict;
use warnings;
$| = 1;

use Proc::Daemon;
use File::Basename;
use Date::Calc;

use lib qw(./libs);

our $Config;
BEGIN {
    use API::Config;
    $Config = $API::Config::Config;
}
use lib ($Config->{'Website_libs'});

use ECS::Config;
use ECS::DB;
use ECS::dbConfig;
use ECS::WarehouseOS::PickSequence;

print "Started ".fileparse(__FILE__)." \n";

while (1) {
    my $p = init();
    ECS::WarehouseOS::PickSequence::checkSequenceLog($p);
    if (! $p->{uploadSequence}) {
		sleep 120;
		next;
	}
    ECS::WarehouseOS::PickSequence::setWOSPickSequence($p);
}

sub init {
    my $p = {};

    $p->{'dbh'}  = ECS::DB->connect({'config' => $ECS::dbConfig::db{'mysql'}});
    $p->{'dbhr'} = ECS::DB->connect({'config' => $ECS::dbConfig::db{'mysqlSlave'}, readonly => 1});
    $p->{'DBH'}  = $p->{'dbh'};
    $p->{'DBHr'} = $p->{'dbhr'};

    return $p;
}
