sunlifePunit has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I have 3 perl jobs which I configured in a batch file of windows. When my task scheduler of windows starts this batch file all of my 3 jobs starts working. But I am facing an issue that after 3-4 days these perl jobs stopped. I want to run then 24X7. How should I configure all 3 perl scripts in windows scheduler ? In case of any faliure these jobs should restart so windows task scheduler would be able to do it? Please advise. Thanks Punit Goyal

Replies are listed 'Best First'.
Re: Run perl job 24 by 7
by pryrt (Abbot) on Feb 26, 2018 at 14:28 UTC

    I agree with ++1nickt's post, that you need to find the root cause of the crash. While describing my first potential work-around (next paragraph), I also found a likely candidate for the root cause for you (which follows in this paragraph). When you create a new task in the task manager, there are lots of default settings you might not even notice. On the task's properties, there is a Settings tab. On that tab, there is a checkbox that says "☑ Stop the task if it runs longer than: 3 days". I would make sure that box is not checked, otherwise Windows will stop the task after 3 days. Then go to the Triggers tab, and for every trigger you have defined, check the Advanced section and make sure "☐ Stop the task if it runs longer than: 3 days" is unchecked as well (though there it appears to be unchecked by default). I don't know why they have that in two separate spots, but there you are.

    As my first idea for a workaround, after making sure the 3 days is disabled on both tabs, I would go to that Settings tab for each of your three jobs, and make sure it's set at "If the task is already running, then the following rule applies: Do not start a new instance": this will mean that how ever often you trigger the job, it will only run one instance. I would then go to the Triggers tab, and set it up to run On a schedule, "☑ Daily", Advanced = "☑ Repeat task every: N minutes for a duration of 1 day", where you choose the number of minutes or hours that would be reasonable for your task. If the world will end, or you'll lose your job, if the job isn't running for an entire hour, I might set it to 30 minutes, just to give yourself some margin. If the bomb will go off if your task stops running for more than 5 minutes, you should set it for 5 minutes or less, and might want to pick a different line of work figure out some other backup strategy, just in case.

    Alternately, you could make one "launcher" script, which runs quickly every 5 minutes, but doesn't stay running. Each of your jobs could have some sort of "I'm alive" indicator (like touching a temporary indicator-file (different file each job) once every couple of minutes while they're running, or similar), which your "launcher" script could check for; if that indicator file for one or more of your jobs gets too old, then the "launcher" should run a new instance of that job in the background. Or, instead of an indicator-file, you could have the launcher script use the Win32 API to search for a windows task that matches each of your jobs, and launch a new instance if it cannot find it.

    That's personally the order I would try things, if I were in this situation. But I really think that one or both of the "☐ Stop the task if it runs longer than: 3 days" checkboxes would be the likely first candidates.

Re: Run perl job 24 by 7
by 1nickt (Canon) on Feb 26, 2018 at 13:11 UTC

    Why did the jobs stop? If you don't know, find out, maybe by adding more logging output so you can see what happened. You first must determine whether your Perl programs are crashing, or whether it is an OS problem.


    The way forward always starts with a minimal test.
Re: Run perl job 24 by 7
by mh88 (Novice) on Feb 28, 2018 at 21:09 UTC
    Hello,

    could you provide example code?

    maybe you want to insert some debugging code, something like write a line into a file every hour or so ...?

    iirc tasks are configured to stop after 72hours if not adjusted otherwise
    Maybe you want to search for "windows task scheduler configuration"
    after the few informations we got so far i would assume
    -> this is probably no perl problem.
    To verify this you could just:
    copy the "Perl Task" and do some simple thing in a new "batch only task" if this stops after the same time its no perl problem ;-).


    hth
    mh88