> > I have a CF template that updates a database of music file info from 
> disk directory info. I
> > can say more about the template, but the problem seems to be 
> somewhat unrelated.
> >
> > On my development machine, the template runs perfectly.  It takes 
> about 12 minutes to
> > do all of the disk read, comparisons to existing data and insertion 
> of new records.  The
> > start and finish are recorded in a log file along with notations of 
> changes made.
> >
> > When I transfer the info to the production machine, it "works" fine 
> in that the beginning
> > and ending times and changes are recorded in the log file and it 
> takes about the same 12
> > minutes.  The problem is that when running on the production machine, 
> the template never
> > completes (i.e. Browser reports "done").  Instead, it appears to 
> continue processing for
> > another 12-15 minutes and then two things happen.  First the browser 
> opens a download
> > window and attempts to download the template that it is running.  
> Second, it starts
> > opening multiple tabs, rapidly.  Left to its own devices, this 
> ultimately chokes the client
> > system.
> >
> > I have diligently compared the setup on both machines (dev and 
> production) and they are
> >  identical: Windows XP (SP3), Firefox 3.0.5, CF 8 (8.0.1.195765), 
> java 1.6.0_11, Apache
> > 2.2.  The settings in the CF administrator are identical because I 
> packaged up the settings
> > from the production machine and installed them on the dev machine to 
> ensure sameness.
> >
> > I've also tried commenting out sections of the code to see if that 
> were the cause, but since
> > the code completes and writes the final log entry in both cases I'm 
> hard pressed to see
> > why the code is the problem.
> 
> Unless this also happens with all your other CF files, the code has
> something to do with the problem. So, I suggest you provide the code,
> and URLs where we can see the code running, etc.
> 
> Dave Watts, CTO, Fig Leaf Software
> http://www.figleaf.com/
> 
> Fig Leaf Software provides the highest caliber vendor-authorized
> instruction at our training centers in Washington DC, Atlanta,
> Chicago, Baltimore, Northern Virginia, or on-site at your location.
> Visit http://training.figleaf.com/ for more 
information!

Dave,
Thanks for the reply!  I see your point re: the code being involved, except for 
the fact that it gets to the end and writes the final log entry just fine (even 
on production).  This is the only template that this happens to.
I'm posting the code here.  Here's hoping you see something!!

<!--- ITUNES DATABASE UPDATE - Scheduled Task --->

<!--- initialize variables --->

<cfscript>
  starttime = now();
        writeoutput("start: " & timeformat(startTime,'HH:mm:ss') & "<br />");
  newMusic = arraynew(1);
  newMusicCount = 0;
  //itunesRootDir defined in application.cfc
  logFilePath = application.XferFile ;
        // check if log file exists, write initial string to log file 
        // log start of process
        startCopyPhrase = "#chr(13)##chr(10)#***  #dateformat(startTime,'ddd 
mm/dd/yy')# #timeformat(startTime,'HH:MM:ss')# - start refresh of iTunes Master 
Index. - ***#chr(13)##chr(10)#";
        // fileTest = fileExists(logFilePath);
        if (fileExists(logFilePath)) {
                existingFile = fileopen(logFilePath, "append");
                filewrite(existingFile, startCopyPhrase);
                }
        else {
                filewrite(logFilePath, startCopyPhrase);
                existingFile = fileopen(logFilePath, "append");
                }
</cfscript>     
<cfscript>
        // process directories
  FilePath = "#application.itunesRootDir#" ;
        ArtistDirs = 
createObject("java","java.io.File").init(Trim(FilePath)).list();
        aArtists = arraynew(1);
        
        // the following block gets the top level directories
        for (i=1;i lte arraylen(ArtistDirs); i=i+1){
                 a_name = ArtistDirs[i];
                 path=Filepath & '\' & a_name;
                
                 if(directoryexists(path) and not(findnocase("Album 
Artwork",path))) {
                                arrayAppend(aArtists,a_name);   
                 }
                
        }

        //following block gets album names (level 2 directory) then song names
        AAS=arraynew(1); // Artist/Album/Song = AAS
        for (x=1;x lte arraylen(aArtists); x=x+1) {
                oneAlbum = structnew();
                oneAlbum.artist = aArtists[x];
                artistpath=Filepath & aArtists[x] &  '\';
                oneAlbum.album = 
createObject("java","java.io.File").init(Trim(artistPath)).list();
                for (y=1; y lte arraylen(oneAlbum.album); y=y+1) {
                        albumPath = artistpath & oneAlbum.album[y] & '\';
                        oneAlbum.songs[y] = 
createObject("java","java.io.File").init(Trim(AlbumPath)).list();
                        oneAlbum.albumCount = arraylen(oneAlbum.album);
                        AAS[x] = oneAlbum;
                }
        }
        writeoutput("<br>arraylen of AAS: " & arraylen(AAS) & "<br>");
</cfscript>

<!--- check for existence of itunesMasterIndex data --->
<cftry>
  <cfquery datasource="#application.dsn_10#" name="StoredMasterList">
    SELECT fullPath, Artist,Type,Album,Song,Sortname
    FROM itunesMasterIndex
    ORDER BY artist, album, Sortname
  </cfquery>
  <cfcatch>
    <cfif cfcatch.type eq "Database">
      A new table needs to be created...<br>
      <cftry>
        <cfquery datasource="#application.dsn_10#">
          CREATE TABLE itunesMasterIndex 
            (FileID Int identity (1,1) not null, FileDate DATE, addedDate DATE,
            FileSize INT, artist VARCHAR(50), album VARCHAR(50), trackNo 
VARCHAR(4), 
            song VARCHAR(100),type VARCHAR(9), fullPath VARCHAR(150), 
            sortName VARCHAR(100), CONSTRAINT FileID PRIMARY KEY (FileID))
        </cfquery>
        <cfquery datasource="#application.dsn_10#" name="StoredMasterList" >
          SELECT *
          FROM itunesMasterIndex
        </cfquery>
        <cfcatch type="any">
          <cfoutput>#cfcatch.type#</cfoutput>
          table exists, but couldn't be read?
          <cfabort>
        </cfcatch>
      </cftry>
    <cfelse>
      TABLE ALREADY EXISTS! (or there's a different kind of error)<br>
    </cfif>
  </cfcatch>
</cftry>

<!---table now tested and/or created --->
<cfloop index="artistCount" from="1" to="#arraylen(AAS)#"> 
  <cfloop index="albumIndex" from="1" to="#AAS[artistCount].albumCount#">
                <cfscript>
                        songStatus = "OK";
                        try {
                                nOfSongs = 
#arraylen(AAS[artistcount].songs[albumIndex])#;
                        }
                        catch (any excpt) {
                                songStatus = "NO SONG STRUCTURE";
                                //writeoutput(excpt);
                        }
                        if (songStatus eq "OK" and nOFSongs eq 0)
                                songStatus = "EMPTY ARRAY";
                        artist2Find = AAS[artistCount].artist;
                        album2Find = AAS[artistCount].album[albumIndex];
    </cfscript>
    <cfif songStatus eq "OK">
        <cfloop index="songCount" from="1" 
to="#arraylen(AAS[artistCount].songs[albumIndex])#">
                        <cfset song2Find = 
AAS[artistCount].songs[albumIndex][songCount]>
          <cftry>
                <cflock name="itunesSearchResult" type="readonly" 
throwontimeout="yes" timeout="10">
              <cfquery datasource="#application.dsn_10#" name="searchResult" >
                SELECT *
                FROM itunesMasterIndex
                WHERE artist = '#artist2Find#'
                  AND album = '#album2Find#'
                  AND Song = '#song2Find#'
              </cfquery>
            </cflock>
            <cfcatch>
                <cfoutput>Database Error: #cfcatch.Detail#</cfoutput>
            </cfcatch>
          </cftry>
        
        
                                        <cfif searchResult.recordcount eq 0>
              <!--- no match --->
              <cfscript>
                addedDate = dateformat(now(), 'yyyy-mm-dd') & " " & 
timeformat(now(),'HH:mm:ss');
                if (song2find neq "" and isnumeric(left(song2find,2))) {
                  trackNo = left(song2find,2);
                  sortName = mid(song2find,4,len(song2find)-7);
                  }
                  else {
                    //see if disk numbers 1 or 2 are at beginning of name
                    if (isnumeric(left(song2find,1)) and 
isnumeric(mid(song2find,3,2))) {
                      trackNo = left(song2find,4);
                      sortName = mid(song2find,6,len(song2find) - 9);
                    }
                    else {
                    trackNo = "";
                    sortName = left(song2find,len(song2find) - 4);
                    }
                  }
                
                logMsg = "NEW: ARTIST: " & artist2Find & " | ALBUM: " & 
album2Find & " | SONG: "  & song2Find & " | TRACK: " & trackno & 
"#chr(13)##chr(10)#";
                
                path2Song = application.itunesrootDir & artist2Find & "\" & 
album2Find ;
              </cfscript>
              <cfdirectory name="fileInfo" type="file" listinfo="all" 
action="list" 
                directory="#path2song#" filter="#song2find#" recurse="no">
              <cfscript>
                filedatelastmodified = 
dateformat(fileinfo.datelastmodified,'yyyy-mm-dd') & " " & 
timeformat(fileinfo.datelastmodified,'HH:mm:ss');
                nuFileSize = fileinfo.size;
                song2write = preservesinglequotes(song2find);
              </cfscript>
                            
              <cftry>
                <cflock name="itunesInsertLock" timeout="10" type="exclusive" 
throwontimeout="yes">
                  <cfquery datasource="#application.dsn_10#">
                    INSERT INTO itunesMasterIndex 
(addedDate,Artist,Album,Song,TrackNo,Type,fileSize,
                      fileDate,fullPath,sortName)
                    VALUES 
('#addedDate#','#artist2Find#','#album2Find#','#song2write#',
                      
'#TrackNo#','File',#nuFilesize#,'#filedatelastmodified#','#path2song#',
                      '#sortName#')
                  </cfquery>
                </cflock>
                <cfcatch>
                  <cfscript>
                    logMsg = "Database error while writing: #chr(13)##chr(10)#";
                    logMsg = logMsg + "<cfoutput><br />output for db entry:<br 
/>
                    
#addedDate#<br>#artist2Find#<br>#album2Find#<br>#song2Find#<br />
                      #TrackNo#<br>File<br />#nuFilesize#<br 
/>#filedatelastmodified#<br>#path2Song#<br />
                      #sortName#<br />END OUTPUT<br /></cfoutput>";
                    filewrite(existingFile,logMsg);
                  </cfscript>
                </cfcatch>
              </cftry>
              <cfscript>
                newSong = structnew();
                newMusicCount = newMusicCount + 1;
                newSong.addedDate = addedDate;
                newSong.artist = artist2Find;
                newSong.album = album2Find;
                newSong.Song = song2Find;
                newMusic[newMusicCount] = newSong;
              </cfscript> 
          </cfif>
       </cfloop>
     <cfelse>
        <br />&nbsp;&nbsp;&nbsp;&nbsp;***SKIPPED:  songs could not be counted 
in directory<cfoutput> [#artist2find# | #album2find#]</cfoutput><br />
    </cfif>
  </cfloop>
</cfloop>

<!--- final log entries and closure --->
<cfscript>
        logMsg = "Number of new songs: " & newMusicCount & "#chr(13)##chr(10)#";
  filewrite(existingFile,logMsg);
        endtime = now();
        duration = datediff("n",starttime,endTime);
        logMsg = "***itunes update endtime is: " & 
dateformat(endtime,'YYYY-MM-DD') & " " &
                timeformat(endtime,'HH:mm:ss') & " duration is: " & duration & 
" minutes *** #chr(13)##chr(10)#";
  filewrite(existingFile,logMsg);
  fileclose(existingFile);
</cfscript>
<cfabort> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to 
date
Get the Free Trial
http://ad.doubleclick.net/clk;207172674;29440083;f

Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:317185
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4

Reply via email to