Jump to content

do something every 24 hours serverside


erich.wanker

Recommended Posts

Hi .. i must resync tables all 24 hours (with CSV files)

I dont know - but it works sometimes - and sometimes not ..

i use a UniThreadTimer (Interval 2000000) in Servermodule ( the servermodule has also a seperate ZConnection1 to the database to make the job)

if i start the procedure "alle_importieren" manualy - everything works fine.

procedure TUniServerModule.UniThreadTimer1Timer(Sender: TObject);
var
  dd, mm, yyyy: Word;
  dda, mma, yyyya: Word;
  zuletzt: TDatetime;
  h, m, s, ms: Word;
begin
  Importeinstellung.Refresh;
  if Importeinstellung.FieldByName('Aktiv').AsInteger = 1 then // Yes - do it
    begin
      zuletzt := Importeinstellung.FieldByName('lastSync').AsDateTime;
      decodedate(now, dda, mma, yyyya);
      decodedate(zuletzt, dd, mm, yyyy);
      if dda <> dd then
        begin
          DecodeTime(now, h, m, s, ms);
          if Importeinstellung.FieldByName('SyncTime').AsInteger = h then   / h is the hour  - in my case 18  ( 6 pm )   - the time of the server is set to 24 h
            begin

              alle_importieren;  / the main import procedure

              Importeinstellung.Edit;
              Importeinstellung.FieldByName('lastSync').AsDateTime := now;
              Importeinstellung.post;
              Logger.AddLog('lastSync:' + datetostr(now));
            end;
        end;

    end;

end;

 

ThanX for help :-)

nice greetings

erich

Link to comment
Share on other sites

14 hours ago, erich.wanker said:

Hi .. i must resync tables all 24 hours (with CSV files)

I dont know - but it works sometimes - and sometimes not ..

i use a UniThreadTimer (Interval 2000000) in Servermodule ( the servermodule has also a seperate ZConnection1 to the database to make the job)

if i start the procedure "alle_importieren" manualy - everything works fine.


procedure TUniServerModule.UniThreadTimer1Timer(Sender: TObject);
var
  dd, mm, yyyy: Word;
  dda, mma, yyyya: Word;
  zuletzt: TDatetime;
  h, m, s, ms: Word;
begin
  Importeinstellung.Refresh;
  if Importeinstellung.FieldByName('Aktiv').AsInteger = 1 then // Yes - do it
    begin
      zuletzt := Importeinstellung.FieldByName('lastSync').AsDateTime;
      decodedate(now, dda, mma, yyyya);
      decodedate(zuletzt, dd, mm, yyyy);
      if dda <> dd then
        begin
          DecodeTime(now, h, m, s, ms);
          if Importeinstellung.FieldByName('SyncTime').AsInteger = h then   / h is the hour  - in my case 18  ( 6 pm )   - the time of the server is set to 24 h
            begin

              alle_importieren;  / the main import procedure

              Importeinstellung.Edit;
              Importeinstellung.FieldByName('lastSync').AsDateTime := now;
              Importeinstellung.post;
              Logger.AddLog('lastSync:' + datetostr(now));
            end;
        end;

    end;

end;

 

ThanX for help :-)

nice greetings

erich

Hi Erich,

UniThreadTimer need to lock thread. Then you can insert your procedure inside the block.

See the MegaDemo.

i have worked with unithreadTimer on ServerModule to do automatic Backup everynight at 23:00, and that works fine. i will try to send you an example.

Link to comment
Share on other sites

Here we go :

 

 

procedure TUniServerModule.UniThreadTimer1Timer(Sender: TObject);
begin
  UniThreadTimer1.Lock;
  try
  //==============
    MyProcedure;
  //==============
  finally
    UniThreadTimer1.Release;
  end;

end;

 

To know :

1. We can not Use UniTimer in serverModule, use instead UniThreadTimer

2. We have to lock UniThreadTimer, execute a code then release it.

3. We can not use in MyProcedure something coded in  MainModule or Main, as MainModule and Main are  an Instance (Session Clientside)  !

->   Common error :   in myProcedure i want to use a SQL Query which is already coded in MainModule :  This raises an AV. The good way is to create a classical Delphi Unit (not an UniguiDataModule) and rewrite the SQL query there.

Regards.

 

 

Link to comment
Share on other sites

  • 5 weeks later...

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...