어떻게 든 File :: Queue에 대한 아이디어를 얻을 수 없었습니다. 비 차단 병렬 실행을 위해 TheSchwartz과 Parallel :: Prefork의 조합을 사용하여 마치 Foorum Catalyst App에 구현 된 것처럼 종료되었습니다. 기본적으로 5 가지 중요한 요소가 있습니다. 어쩌면이 요약은 다른 사람들에게 도움이 될 것입니다.실제 작업이 이루어집니다 TheSchwartz DB
package MyApp::TheSchwartz::Client;
use TheSchwartz;
sub theschwartz {
my $theschwartz = TheSchwartz->new(
databases => [ {
dsn => 'dbi:mysql:theschwartz',
user => 'user',
pass => 'pass',
} ],
verbose => 1,
);
return $theschwartz;
}
3) 작업 근로자 (대한
1) TheSchwartz DB
2) 클라이언트 (DB 핸들))
package MyApp::TheSchwartz::Worker::Test;
use base qw(TheSchwartz::Moosified::Worker);
use MyApp::Model::DB; # Catalyst DB connect_info
use MyApp::Schema; # Catalyst DB schema
sub work {
my $class = shift;
my $job = shift;
my ($args) = $job->arg;
my ($arg1, $arg2) = @$args;
# re-use Catalyst DB schema
my $connect_info = MyApp::Model::DB->config->{connect_info};
my $schema = MyApp::Schema->connect($connect_info);
# do the heavy lifting
$job->completed();
}
4) 테이블을 모니터링하는 작업자 프로세스 TheSchwartzWorker.pl
작업 논스톱
use MyApp::TheSchwartz::Client qw/theschwartz/; # db connection
use MyApp::TheSchwartz::Worker::Test;
use Parallel::Prefork;
my $client = theschwartz();
my $pm = Parallel::Prefork->new({
max_workers => 16,
trap_signals => {
TERM => 'TERM',
HUP => 'TERM',
USR1 => undef,
}
});
while ($pm->signal_received ne 'TERM') {
$pm->start and next;
$client->can_do('MyApp::TheSchwartz::Worker::Test');
my $delay = 10; # When no job is available, the working process will sleep for $delay seconds
$client->work($delay);
$pm->finish;
}
$pm->wait_all_children();
5)는 촉매 컨트롤러에서 : 테이블 작업에 새 작업을 삽입하고 모든 결과를 사용할 수있을 때까지 새로운 실행은 "아카이브"페이지에서 회색으로 표시됩니다
use MyApp::TheSchwartz::Client qw/theschwartz/;
sub start : Chained('base') PathPart('start') Args(0) {
my ($self, $c) = @_;
$client = theschwartz();
$client->insert(‘MyApp::TheSchwartz::Worker::Test’, [ $arg1, $arg2 ]);
$c->response->redirect(
$c->uri_for(
$self->action_for('archive'),
{mid => $c->set_status_msg("Run '$name' started")}
)
);
}
일부 인수를 전달합니다 데이터베이스에.
업로드를 비동기 요청으로 수행하는 것이 타당합니다. 작업 ID를 반환하고 작업이 완료되면 모델에 플래그를 설정하십시오. 그런 다음 페이지를 정기적으로 (10 초마다) 비동기 적으로 폴링하도록하고 _done_을 얻으면 페이지를 새로 고칩니다. 나는 조금 대답을 타이핑 할 것이다. – simbabque
귀하의 주최자 질문에 관해서는 실제로 유스 케이스에 달려 있습니다. Amazon 또는 기타 클라우드 서비스는 필요한 경우 확장이 용이하다는 이점이 있지만 다른 고려 사항 이외에 자체 서버를 보유하는 것보다 비용이 많이들 수 있습니다. 이 질문은 별개로 또는 다른 곳에 게시하는 것이 가장 바람직합니다. – bytepusher
@simbabque 시간이 있다면 유용한 도구/플러그인이나 몇 가지 예제 코드에 대한 힌트가 매우 유용 할 것입니다. bytepusher에게 감사드립니다. 앱을 제작할 때 고려해 볼 것입니다. –