8 Replies Latest reply on Oct 8, 2010 12:09 PM by jay_2014

    jsx as a windows service

    jay_2014 Level 1

      I wrote socket listener class in javascript/photoshopscript.

      I basically need this to be running at all times.

       

      Here is a dumbed down code example that basically returns what is sent to it.

       

      Is there anyway to get this to run as a windows service?

      Currently I start it up from extendscript

       

      #target photoshop

      function Server( _port ){

          this.port = _port;

          this.tcp = new Socket( )

          this.connection;

          this.start = function( callBackFunc ){

              if( this.tcp.listen( this.port ) ){

                  for(;;){

                      this.connection = this.tcp.poll()

                      if( this.connection != null ){

                          var tmp = this.connection.readln()

                          callBackFunc( tmp )

                      }

                  }

              }

          },

          this.response = function( val ){

              this.connection.writeln( val )

          }

      }

       

      function callBackFunction( data ){

          server.response( data )

      }

       

      var server = new Server( 12345 );

      server.start( callBackFunction )

        • 1. Re: jsx as a windows service
          xbytor2 Level 4
          Is there anyway to get this to run as a windows service?

           

          Nope.

           

          I basically need this to be running at all times.

           

          I think you would be better off running this in Bridge and 'addTask' to run it in it's own thread. When you've received a request, pass it on to Photoshop.

          • 2. Re: jsx as a windows service
            jay_2014 Level 1

            Thanks xbytor2, but I have two questions for you.

            1) What is your reasoning behind porting it to bridge?

             

            2)How do I addTask in bridge. Sorry I am just not familiar with bridge at all. Could you point me to some docs that explain it. My google skills failed on this. My searchs turn up with running all scripts from the estk

            • 3. Re: jsx as a windows service
              xbytor2 Level 4
              1) What is your reasoning behind porting it to bridge?

               

              You can run your socket code in a background thread (via addTask) which lets you continue to use Bridge since it's not blocked.I'll see if I have any sample code laying around that I can post.

               

               

              2)How do I addTask in bridge. Sorry I am just not familiar with bridge at all.

               

              The addTask functions are described in the Bridge Scripting Programmers Guide (or whatever it's called). If it's not in a folder in your Bridge app installaton, it sthould be under http://www.adobe.com/devnet.html somewhere.

              • 4. Re: jsx as a windows service
                mselbach2

                I also would recommend you to use Bridges app.scheduleTask Function, because Bridge can supervise if Photoshop is currently processing a job and can collect the incoming jobs in a pipeline. The jobs are passed to photoshop one by one. In my implementation, that I am successfully using for 5 years now I have a folder where all the jobfiles come in. Photoshop is configured that it processes all files in this folder and after this just quits. Bridge is running all the time and is also supervising this folder. If new files are added Bridge just starts photoshop. This is a very easy and robust way to do it, because by quitting photoshop after a series of tasks you avoid memory leaks.

                 

                Regards, markus

                • 5. Re: jsx as a windows service
                  xbytor2 Level 4

                  "scheduleTask" is what I meant to say; not "addTask" .

                   

                  One thing you may alsol want to do is have a palette or panel in Bridge show the current queue of jobs being processed. This is nice to have especially when the jobs take several minutes to run.

                  • 6. Re: jsx as a windows service
                    jay_2014 Level 1

                    xbytor2 wrote:

                    I think you would be better off running this in Bridge and 'addTask' to run it in it's own thread. When you've received a request, pass it on to Photoshop.

                     

                    I looked at  App.scheduleTask();

                    This function reminds me of the old setTimeOut actionscript function.

                    How can this be thread safe?

                     

                    It also dawned on me that if i dump the "for(;;)" Loop and just use the scheduleTask() to call a script that polls the socket I could achieve the same effect.

                    But I fail to see the benefits of doing it this way.

                     

                    This code will be running on a dedicated machine for this job.

                    with 12 core, 20something GiG ram, raided The machine specs might be overkill for it but it was a hand me down from another job.

                    So I am not worried about having access to photoshop while the script is running.

                     

                     

                    All in all this script takes incoming images and standardizes them for the retouchers height,width,res adds 1 inch border canvas for additional image space.

                    When the retouchers are done with an image the script will then crop the image to baseball card size(using position data from a flex app) create CMYK, silo plates, white plates, etch plates and whatever else the composition team needs to create the proof pdfs.

                    This is all run off a PHP/MySQL queue database to work around the lack of multi-threading support.

                    It processes images fast and lays domant quiet a bit so I do not have to worry about multi-threading it.

                    Not yet atleast.

                    Version 2 lol

                     

                    All of this is about 99% done it has been up and running for a few months now.

                    If there is an error I get emails too

                     

                    Back to the matter at hand.

                    I looked and looked and still do not see a way to run scripts in CS4 bridge-3.0

                    Or am I just misunderstanding and scripts can only be run from ESTK/Photo Shop?

                    • 7. Re: jsx as a windows service
                      xbytor2 Level 4

                      I looked at  App.scheduleTask();

                      This function reminds me of the old setTimeOut actionscript function.

                      How can this be thread safe?

                      It also dawned on me that if i dump the "for(;;)" Loop and just use the scheduleTask() to call a script that polls the socket I could achieve the same effect.

                      But I fail to see the benefits of doing it this way.

                       

                       

                      One approach is

                       

                      1. When you script starts, open a UI script  to start, stop and monitor the script via a log window (in addition to a log file)
                      2. Use scheduleTask to start your polling loop.This prevents the UI from locking up.
                      3. When a request comes in to the polling loop, use scheduleTask to hand add the request
                      4. In that thread, see if a job processing thread if exists. If not start it and add the new request/task to the queue. This thread then dies.
                      5. In the job processing thread, see if there are any jobs to process. If not, have it wait for another X number of seconds before starting again. If there are request to process, check to see if PS is busy. If it isn't, send the request and wait for a response. Log all of this to file and to the UI. When the request has finished, move on to any outstanding requests.

                       

                      This code will be running on a dedicated machine for this job.

                      with 12 core, 20something GiG ram, raided The machine specs might be overkill for it but it was a hand me down from another job.

                      So I am not worried about having access to photoshop while the script is running.

                       

                      But having a UI to monitor what's going on will make your life a lot easier, especially if there are any problems. It also give you the ability to automatically restart PS periodically if it locks up and stops satisfying requests.

                       

                      All of this is about 99% done it has been up and running for a few months now.

                      If there is an error I get emails too

                       

                      You can run external scripts for doing email with app.system() in Bridge.

                       

                      I looked and looked and still do not see a way to run scripts in CS4 bridge-3.0

                      Or am I just misunderstanding and scripts can only be run from ESTK/Photo Shop?

                       

                      You add code to add the script to a Bridge menu. Put the script in the magic startup folder and it gets run whenever Bridge starts up.

                      During development and debugging, you probably just want to launch it from ESTK.

                      Alternatively, you and have a script that you launch via the File>Scripts menu (or recorded as an Action step) that sends a message to Bridge to launch the script.

                       

                      I know can sound a bit complicated, but if you need a script that runs continuously for days at a time, never fails, and keeps you updated on its progress (and failures), it does take a bit of work.

                       

                      I've used variants of these techniques in different scripts over the years, so I know they can work. I hope you find some of these ideas helpful.

                      • 8. Re: jsx as a windows service
                        jay_2014 Level 1

                        xbytor2 wrote:

                         

                        One approach is

                         

                        1. When you script starts, open a UI script  to start, stop and monitor the script via a log window (in addition to a log file)
                        2. Use scheduleTask to start your polling loop.This prevents the UI from locking up.
                        3. When a request comes in to the polling loop, use scheduleTask to hand add the request
                        4. In that thread, see if a job processing thread if exists. If not start it and add the new request/task to the queue. This thread then dies.
                        5. In the job processing thread, see if there are any jobs to process. If not, have it wait for another X number of seconds before starting again. If there are request to process, check to see if PS is busy. If it isn't, send the request and wait for a response. Log all of this to file and to the UI. When the request has finished, move on to any outstanding requests.

                         

                        </smack forehead>I see what you are getting at. Great idea.

                        I don't think this will be hard at all to implement. Just need to make a scheduling class and integrate it into the server class.

                         

                         

                         

                        xbytor2 wrote:

                         

                        You add code to add the script to a Bridge menu. Put the script in the magic startup folder and it gets run whenever Bridge starts up.

                        During development and debugging, you probably just want to launch it from ESTK.

                        Alternatively, you and have a script that you launch via the File>Scripts menu (or recorded as an Action step) that sends a message to Bridge to launch the script.

                         

                        Bridge starts on log in. Script starts when Bridge starts.

                        Got it

                         

                        Thanks Professor X and mselbach2 you guys have given me a few things to think about.