Hi,

I need a perl daemon to look into a MySQL table and grab all the jobs which need to be executed. New jobs can be added into this table at anytime, so i need the daemon to be constantly checking the table.

Once it has found the jobs, it needs to run another perl script to run with the $jobID found from the table. The child script has a sleep() function where the value comes from user input in the MySQL table.

This is what I got currently, but the problem is only one job can be executed at once and has to wait until the sleep() has finished, where then the next job can be executed.

Code Snippet

# Enter loop to do work for (;;) { my $sth = $sql_query{"sel_ext_master_jobs"}->execute() or die "can't + execute the query"; my $results = $sql_query{"sel_ext_master_jobs"}->fetchall_hashref('j +ob_id') or die $sth->err; foreach my $job_id (keys %$results) { #print "JobID $job_id is available to be executed... +\n"; system("perl -w script.pl $job_id"); } } startDaemon(); sub startDaemon { # Daemonize eval { Proc::Daemon::Init(); }; if ($@) { print "Unable to start daemon: $@"; } # If already running, then exit if (Proc::PID::File->running()) { dienice("Already running!"); exit(0); } }

Is there a way I can make this script run sub_scripts simultaneously, without having to wait for the sleep() to finish in the sub_scripts

I'm using Proc::Daemon

TIA


In reply to Perl Daemon by perlrush2011

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.