Results 1 to 4 of 4

Thread: USe SCHTASKS to run a task - holding others till this one is done

  1. #1

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    USe SCHTASKS to run a task - holding others till this one is done

    I want to run a series of .BAT files - but only have ONE RUNNING at a time. If I have two or three .BAT files I want them queued up so that only one runs - then the next - and so on.

    I could do this with other O/S task management tools.

    I was going to code my own methods - seeing if a .BAT was running - holding the others - etc. But the handshaking on this operation could be painful to test...

    I was hoping the SCHTASKS tool in windows would be my answer - but I'm not seeing options to do this.

    Anyone have any ideas??

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  2. #2

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: USe SCHTASKS to run a task - holding others till this one is done

    Well - here is my thoughts on home growing a solution - anyone willing to read through these steps and offer opinions or options - I would really appreciate it!

    ASP.Net web service process-----------------

    With application lock (in asp.net application lock makes sure only one web page is getting this "function" at a time)

    ...Insert into ReportProcess_T table with report request / username / desired visual output filename

    ...ReportCounter set to Identity Column value returned

    ...Check if STAGING folder contains Busy.txt
    ......If Not then create Busy.txt with contents of ReportCounter (and sets boolean to "run batch file")

    ...Create Report_{ReportCounter}.Bat

    ...If "run batch file" is true then Process.Start .Bat file

    End Lock


    ----------------------------------
    Batch file processing

    Batch file runs amcReport.exe and creates awcOutput.pdf (this could take from seconds to several minutes)
    ...when done it does a Process.Start on awcCleanup.exe

    awcCleanup.exe processing

    ...Renames awcOutput.pdf based on contents of Busy.txt (awcReport_{reportCounter}.pdf}
    ...and moves to STORAGE folder
    ...Deletes Report_{ReportCounter}.bat in parent folder

    ...If any other Report_*.bat files exist then it does a Process.Start on the next one in sequence

    ......otherwise

    ...Deletes Busy.txt

    ??Here is the problem - during the microseconds it takes to "check" and then "delete" (those last two steps)
    the ASP.Net web service could have seen the Busy.txt file and decided to NOT SUBMIT

    I'm thinking of adding pauses to "double-check" - but seems to be a hack!

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  3. #3
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: USe SCHTASKS to run a task - holding others till this one is done

    Why not run a batch file which executes the other batch files in sequence?

    Code:
    batch1.bat && batch2.bat && batch3.bat
    Or am I missing something?

  4. #4

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: USe SCHTASKS to run a task - holding others till this one is done

    I can only have one batch file running at a time - but the requests to run them are not necessarily consecutively happening.

    One might come in - run - finish - and that is it. When the next one comes in the web service can start it - because the queue is free.

    If ten come in all at once I have to somehow keep them from stepping on each others feet. Those ten requests are coming via a web service - so they "don't know about each other".

    Other mainframe batch queue systems I've worked with permitted all kinds of control such as "one a time"...

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width