Jump to content

Faster automatic reload after compilation


Ron

Recommended Posts

For development, I am using a special setup, trying to reduce time from compilation to browser refresh without any issues.

For this I have to use HyperServer, due to is ability to automatically reload a new application file, from the deploy folder.

So I run a webserver on my development PC, apache 2.2, and I have a post-compile event in Delphi which copies the EXE file
to the \deploy folder, renaming it to *.dep.

I have a timer in the mainForm which discovers that the HyperServer has loaded the new application file:

procedure TMainForm.reloadTimerTimer(Sender: TObject);
begin
  with uniMainModule do
    if newFileDate<>fileDate then
    begin
      reloadTimer.Enabled:=false;
      showToast('Reloading application...');
      uniSession.AddJS('document.location.reload();');
    end;
end;

This works fine, and it runs this newFileDate function in the MainModule:

function TUniMainModule.newFileDate:TDateTime;
var fileDateInt:Integer;
begin
  fileDateInt := fileAge('c:\antirust\timebok\timebok.exe');
  if fileDateInt > -1 then
    result:=fileDateToDateTime(fileDateInt);
end;

Of course this function is also run at MainModule startup:

procedure TUniMainModule.UniGUIMainModuleCreate(Sender: TObject);

begin
  fileDate:=newFileDate;
end;

The MainForm timer runs at 500ms intervals, so this all works fine, as you can see in the screenshot.

But - there is of course another timer running in the HyperServer, and I wonder how I can reduce its interval?

It seems like the HyperServer timer runs at 10 secs interval, and I would like to lower it to about 1 second.

Then I can reduce the time from compile to browser reload, to about 3 seconds - maybe.

 

 

 

reloading.png

  • Like 2
Link to comment
Share on other sites

 

I have found a compromise: if I reload the application about 3 seconds after the deploy file 
is swallowed up by the HyperServer, then I will catch the new version in most of the cases:

 

procedure TMainForm.checkTimerTimer(Sender: TObject);
begin
  if fileExists('c:\antirust\timebok\deploy\timebok.dep') then
  begin
    UniMainModule.log('Fast Reloading application after 3000ms delay...');
    sleep(3000);
    showToast('Fast Reloading application - time: '+TimeToStr(now));
    uniSession.AddJS('document.location.reload();');
  end;
end;

 

From the log:

3:00:20 PM Deploy file discovered
3:00:32 PM Deploy file moved after 11 secs. - reloading application
3:00:32 PM Application startup - version: 0.1.0.17
3:00:43 PM Deploy file discovered
3:00:54 PM Deploy file moved after 11 secs. - reloading application
3:00:55 PM Application startup - version: 0.1.0.18
3:01:02 PM Deploy file discovered
3:01:04 PM Deploy file moved after 2 secs. - reloading application
3:01:05 PM Application startup - version: 0.1.0.19
3:01:19 PM Deploy file discovered
3:01:29 PM Deploy file moved after 9 secs. - reloading application
3:01:29 PM Application startup - version: 0.1.0.20
3:01:50 PM Deploy file discovered
3:01:51 PM Deploy file moved after 0 secs. - reloading application
3:01:51 PM Application startup - version: 0.1.0.21
3:02:03 PM Deploy file discovered
3:02:13 PM Deploy file moved after 10 secs. - reloading application
3:02:14 PM Application startup - version: 0.1.0.22
3:02:32 PM Deploy file discovered
3:02:36 PM Deploy file moved after 3 secs. - reloading application
3:02:36 PM Application startup - version: 0.1.0.23
3:02:45 PM Deploy file discovered
3:02:46 PM Deploy file moved after 0 secs. - reloading application
3:02:46 PM Application startup - version: 0.1.0.24
3:02:54 PM Deploy file discovered
3:02:58 PM Deploy file moved after 3 secs. - reloading application
3:02:58 PM Application startup - version: 0.1.0.25
3:04:27 PM Deploy file discovered
3:04:32 PM Deploy file moved after 5 secs. - reloading application
3:09:06 PM Application startup - version: 0.1.0.26
...
3:17:35 PM Fast Reloading application after 1000ms delay...
3:17:37 PM Application startup - version: 0.1.0.50
3:17:58 PM Fast Reloading application after 2000ms delay...
3:18:01 PM Application startup - version: 0.1.0.51
3:18:18 PM Fast Reloading application after 2000ms delay...
3:18:20 PM Fast Reloading application after 2000ms delay...
3:18:21 PM Application startup - version: 0.1.0.51
3:18:36 PM Fast Reloading application after 2000ms delay...
3:18:38 PM Fast Reloading application after 2000ms delay...
3:18:39 PM Application startup - version: 0.1.0.52
3:18:40 PM Fast Reloading application after 2000ms delay...
3:18:40 PM Fast Reloading application after 3000ms delay...
3:18:44 PM Application startup - version: 0.1.0.53
3:19:13 PM Fast Reloading application after 3000ms delay...
3:19:17 PM Application startup - version: 0.1.0.54
3:19:33 PM Fast Reloading application after 3000ms delay...
3:19:36 PM Fast Reloading application after 3000ms delay...
3:19:40 PM Application startup - version: 0.1.0.55
3:19:40 PM Application startup - version: 0.1.0.55
3:19:47 PM Fast Reloading application after 3000ms delay...
3:19:51 PM Application startup - version: 0.1.0.56

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...