Quantcast

automatic execution of methods on server

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

automatic execution of methods on server

Herman Van Doorslaer
Hi all,

i'm trying to have the 4D server execute methods on specific times.
eg: at 03:00 AM, check all outstanding orders by suppliers and send them a mail requesting an update.

Anybody got a clue how to best go about this?

thx
Herman Van Doorslaer

Van Doorslaer BVBA
Puursesteenweg 374
2880 BORNEM

url: www.vandoorslaer.be



**********************************************************************
The New 4D Partner Program - All the tools you need to be a successful 4D Developer.
Sign up Now:  http://www.4d.com/community/partner/registration.html


4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: automatic execution of methods on server

Peter Schumacher-2
Hello Herman,

since years I am using a 2-process-approach for it:

1. Dispatch process,started in ON SERVER STARTUP

$StartTime:=?03:00:00?
repeat
  if($StartTime=current time)
    $process:=new process("DoSomething";(1024*512);"WorkingProcess";*)
  else
    delay process(current process;(60*60*10))`sleep for 10 seconds - don't do this while driving!
  end if
until (process aborted)

2. Working process
...do something


Am 15.03.2010 um 13:48 schrieb Herman Van Doorslaer:

> Hi all,
>
> i'm trying to have the 4D server execute methods on specific times.
> eg: at 03:00 AM, check all outstanding orders by suppliers and send them a mail requesting an update.
>
> Anybody got a clue how to best go about this?
>
> thx
> Herman Van Doorslaer
>
> Van Doorslaer BVBA
> Puursesteenweg 374
> 2880 BORNEM
>
> url: www.vandoorslaer.be
>

Greetings,
[4D-Consulting.com]eK, Edmonton (Alberta)
Peter Schumacher
--------------------------------------------------------
Web: http://www.4D-Consulting.com/
Tel.:      +49-611-9406.850 - Fax: +49-611-9406.744
4D-Consulting.com eK - Scharnhorststr. 36 - 65195 Wiesbaden
Member of the German Developer Network  http://www.die4dwerkstatt.de





**********************************************************************
The New 4D Partner Program - All the tools you need to be a successful 4D Developer.
Sign up Now:  http://www.4d.com/community/partner/registration.html


4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: automatic execution of methods on server

Chip Scheide
In reply to this post by Herman Van Doorslaer
generically

a preference setting for time (my choice, so you can change it 'on the
fly')

then a "deamon" - code that runs on server start up, then waits for an
activating event (in this case a specific time)

pseudo code :

do method setup stuff

repeat
 
 if (it is the correct time)
   execute code - send emails
 else
   go back to sleep (calculate delay)*
 end if
until (Flag_that_4D_Is_Quiting)


calculating the delay -- I havent revisited this issue with v11, v2003
had a limit of MAX INT (32727 ticks) for delay process, any value
larger was ignored.  32727 ticks = 9.09 minutes so a process that was
delayed would not stay delayed more then about 9 minutes. So you need
to calculate the delay of the deamon process.  If it is more than 9.09
minutes until you want the process to run, delay for maxint ticks, else
calculate difference between current time and desired time and delay
the deamon for that amount of time.  I built in a buffer because there
may be a few ticks/seconds delay as the process gets up and running (at
the desired time), allowing the deamon to perform it's tasks within a
few minutes of the desired time.minutes

Code that I use for kicking users off of the server so that backups can
occur, this incorporates the same ideas as above

$Allowed_Difference:=20*60  `allowed "fudge factor" so that if this
process wakes up with-in this time period of a back up users can be
booted

Repeat
        dialog_Get_Preference_Record `this method gets the systemwide
preference record which where the backup time is set/saved
        $Current_Time:=Current time(*)*1  `current time as a long int
        $Backup_Time:=[aPreferences]Backup_Time*1  `time the backup is to
occur as long int
       
        If ($Current_Time>=($Backup_Time-$Allowed_Difference)) &
($Current_Time<=$Backup_Time)  `process woke up inside allowed time
period pre backup
                GET REGISTERED CLIENTS($Clients;$Methods)  `get list of all clients
currently attached to the server
               
                For ($i;1;Size of array($Clients))  `for each client
                        EXECUTE ON CLIENT($Clients{$i};"menuf_Quit_4D")  `force the
execution of the quit routine
                End for
                ARRAY TEXT($Clients;0)  `cleanup
                ARRAY LONGINT($Methods;0)
                $Time_Till_Backup:=MAXINT
               
        Else   `else woke up outisde of allowed time period before a backup
                $Time_Till_Backup:=$Backup_Time-$Current_Time  `determine how long
until the next backup
               
                If ($Time_Till_Backup>MAXINT )  `if backup is to occur in more then
about 9 minutes
                        $Time_Till_Backup:=MAXINT
                Else   `delay until just backup time
                        $Time_Till_Backup:=Abs($Time_Till_Backup-Int($Allowed_Difference/2))
                End if
        End if
       
        utl_Clear_All_Except `clears all table's selections
        DELAY PROCESS(Current process;$Time_Till_Backup)  `put this method
back to sleep `maxint = about 9 minutes
Until (◊f_Quit)


On Mon, 15 Mar 2010 20:48:23 +0100, Herman Van Doorslaer wrote:

> Hi all,
>
> i'm trying to have the 4D server execute methods on specific times.
> eg: at 03:00 AM, check all outstanding orders by suppliers and send
> them a mail requesting an update.
>
> Anybody got a clue how to best go about this?
>
> thx
> Herman Van Doorslaer
>
> Van Doorslaer BVBA
> Puursesteenweg 374
> 2880 BORNEM
>
> url: www.vandoorslaer.be
>
>
>
> **********************************************************************
> The New 4D Partner Program - All the tools you need to be a
> successful 4D Developer.  
> Sign up Now:  http://www.4d.com/community/partner/registration.html
>    
>
> 4D Internet Users Group (4D iNUG)
> FAQ:  http://lists.4d.com/faqnug.html
> Archive:  http://lists.4d.com/archives.html
> Options: https://lists.4d.com/mailman/options/4d_tech
> Unsub:  mailto:[hidden email]
> **********************************************************************
>
------------------------------
...let both sides join in creating a new a endeavour,
not in a new balance of power, but in a new world of law.
Where the strong are just, the weak secure, and the peace observed...
  -- John F.Kennedy Inagural Address
**********************************************************************
The New 4D Partner Program - All the tools you need to be a successful 4D Developer.  
Sign up Now:  http://www.4d.com/community/partner/registration.html
   

4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: automatic execution of methods on server

Doug Cottrill
In reply to this post by Herman Van Doorslaer
We generally have a background task manager process to do this.
It looks something like this:

WHILE(<>NotQuitting)

IF(current time=?3:00:00?)  `if it is 3 AM
     New Process("MyEmailProcess") `run your emailing process in a new
process and let this process continue
END IF

IF(current time=?3:05:00?)  `if it is 3:05 AM
     New Process("MyOtherProcess")
END IF

`etc.

DELAY PROCESS(3600) `wait one minute

END WHILE

This method is then called in a new process on server startup.  This
is really basic pseudo code- you'll need to flesh it out, error check,
etc.  But this is the basic idea.

DKC

>Hi all,
>
>i'm trying to have the 4D server execute methods on specific times.
>eg: at 03:00 AM, check all outstanding orders by suppliers and send
>them a mail requesting an update.
>
>Anybody got a clue how to best go about this?
>
>thx
>Herman Van Doorslaer
>
>Van Doorslaer BVBA
>Puursesteenweg 374
>2880 BORNEM
>
>url: www.vandoorslaer.be
>
>
>
>**********************************************************************
>The New 4D Partner Program - All the tools you need to be a
>successful 4D Developer.
>Sign up Now:  http://www.4d.com/community/partner/registration.html
>
>
>4D Internet Users Group (4D iNUG)
>FAQ:  http://lists.4d.com/faqnug.html
>Archive:  http://lists.4d.com/archives.html
>Options: https://lists.4d.com/mailman/options/4d_tech
>Unsub:  mailto:[hidden email]
>**********************************************************************


--
Doug Cottrill
PTM Software, LLC

**********************************************************************
The New 4D Partner Program - All the tools you need to be a successful 4D Developer.  
Sign up Now:  http://www.4d.com/community/partner/registration.html
   

4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: automatic execution of methods on server

Bob McKeever-2
In reply to this post by Herman Van Doorslaer
I spawn a new process on the server. That process does the following:

                        $MyTime:=Current time
                        $RunAt:=†29:00:00†
                       
                        $Diff:=$RunAt-$MyTime
                        $Diff:=$Diff*60
                       
                        DELAY PROCESS(Current process;$Diff)

That starts the code I need to execute at 5:00 AM.

It actually runs in a loop, running the process every morning. If I  
take the server down, then it starts up when I start the server again.  
Works really well.

For clients that log in and leave their machines on, I do a similar  
thing to log them off at 1:00 AM so backup can run.

On Mar 15, 2010, at 12:48 PM, Herman Van Doorslaer wrote:

> Hi all,
>
> i'm trying to have the 4D server execute methods on specific times.
> eg: at 03:00 AM, check all outstanding orders by suppliers and send  
> them a mail requesting an update.
>
> Anybody got a clue how to best go about this?
>
> thx
> Herman Van Doorslaer
>
> Van Doorslaer BVBA
> Puursesteenweg 374
> 2880 BORNEM
>
> url: www.vandoorslaer.be
>
>
>
> **********************************************************************
> The New 4D Partner Program - All the tools you need to be a  
> successful 4D Developer.
> Sign up Now:  http://www.4d.com/community/partner/registration.html
>
>
> 4D Internet Users Group (4D iNUG)
> FAQ:  http://lists.4d.com/faqnug.html
> Archive:  http://lists.4d.com/archives.html
> Options: https://lists.4d.com/mailman/options/4d_tech
> Unsub:  mailto:[hidden email]
> **********************************************************************

_________________________________________
Bob McKeever                      http://www.mswl.com
McKeever's Software Wizardry
Maple Ridge, B.C.
[hidden email]



**********************************************************************
The New 4D Partner Program - All the tools you need to be a successful 4D Developer.
Sign up Now:  http://www.4d.com/community/partner/registration.html


4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: automatic execution of methods on server

Sean Broderick-2
In reply to this post by Herman Van Doorslaer
Herman Van Doorslaer:

"trying to have the 4D server execute methods on specific times"

My code will be somewhat redundant, but I did lots of overnight process scheduling work...

(It might be worth mentioning that you could actually have a polling process on the server that checks for trigger files, which could be created by cron jobs.)

I used a drone client, which would then run tasks on the server or locally, as required, from about 5pm through 6:45am, when systems would be backed up. Two servers worked in tandem, and users were locked out from about 8pm until 7am.

Naturally, a server-side scheduler could run the show. Using a drone station gave me the flexibility to easily shut everything down.

In the primary batch process, there were a few sheduling blocks like this...

  If ($test_mode)
    ALERT("Test Mode: bypassing wait until 17:20.")
  Else
    If (Current time(*)>Time("06:00:00"))
      If (Current time(*)<Time("23:59:00"))
        Shell_Process_Schedule_Delay (Time("17:20:00");Current date(*);6)
      End if
    End if
  End if

When the overnight process was done, it would launch another process that merely scheduled the overnight process to spawn later.

  If (Not($fatal_error | Shell_Process_Stop))
      `  <•> update progress status
      ` [redacted]
      `  <•> wait for launch date-time
    Shell_Process_Schedule_Delay ($tms_time_value;$tms_date;6)
  End if
 
    `  <<-->> execute task <<-->>
  If (Not($fatal_error | Shell_Process_Stop))
    EXECUTE($tms_task)
  End if

I think the method below makes such scheduling easy and flexible.

####
  `  Method: Shell_Process_Schedule_Delay
  `  
  `  Description: delay process until launch threshold time

C_TIME($launch_time_threshold;$1)
C_DATE($launch_date_threshold;$2)
C_LONGINT($check_interval_in_minutes;$3)
C_LONGINT($ticks_per_second)
C_LONGINT($seconds_per_minute)
C_LONGINT($delay)

  `  <<-->> obtain parameters <<-->>
$lauch_time_threshold:=$1
$launch_date_threshold:=$2
$check_interval_in_minutes:=$3

  `  <<-->> delay process <<-->>
  `  implemented via polling, much more difficult
  `  ... to test and validate when working with
  `  ... single calculated delay, if we throw
  `  ... interrupt, only have to wait for
  `  ... check interval to run down
$ticks_per_second:=60
$seconds_per_minute:=60
$delay:=($check_interval_in_minutes*$seconds_per_minute*$ticks_per_second)
  ` wait until desired date
While (($launch_date_threshold>Current date(*)) & Not(Shell_Process_Stop))
  DELAY PROCESS(Current process;$delay)
End while
  ` wait until desired time
While (($lauch_time_threshold>Current time(*)) & Not(Shell_Process_Stop))
  DELAY PROCESS(Current process;$delay)
End while
####

Sincerely,
Sean Broderick


On Mar 15, 2010, at 3:48 PM, Herman Van Doorslaer wrote:

> Hi all,
>
> i'm trying to have the 4D server execute methods on specific times.
> eg: at 03:00 AM, check all outstanding orders by suppliers and send them a mail requesting an update.
>
> Anybody got a clue how to best go about this?

**********************************************************************
The New 4D Partner Program - All the tools you need to be a successful 4D Developer.
Sign up Now:  http://www.4d.com/community/partner/registration.html


4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: automatic execution of methods on server

Chuck Miller-2
I have a component in the works that will control execution of  
processes on server and client, with much granularity. If interested,  
I would sell source, which in 2004 based as of now.

It controls hourly, every x minutes, weekly, monthly, yearly, first  
monday of month, last day of month, first monday of first full week etc.

I have one remaining bug regarding skip times that I am fixing.

Using this you can schedule an unlimited number of jobs simply by  
adding a record to the table.

Regards

Chuck
On Mar 16, 2010, at 3:01 AM, Sean Broderick wrote:

> Herman Van Doorslaer:
>
> "trying to have the 4D server execute methods on specific times"
>
> My code will be somewhat redundant, but I did lots of overnight  
> process scheduling work...
>
> (It might be worth mentioning that you could actually have a polling  
> process on the server that checks for trigger files, which could be  
> created by cron jobs.)
>
> I used a drone client, which would then run tasks on the server or  
> locally, as required, from about 5pm through 6:45am, when systems  
> would be backed up. Two servers worked in tandem, and users were  
> locked out from about 8pm until 7am.
>
> Naturally, a server-side scheduler could run the show. Using a drone  
> station gave me the flexibility to easily shut everything down.
>
> In the primary batch process, there were a few sheduling blocks like  
> this...
>
>  If ($test_mode)
>    ALERT("Test Mode: bypassing wait until 17:20.")
>  Else
>    If (Current time(*)>Time("06:00:00"))
>      If (Current time(*)<Time("23:59:00"))
>        Shell_Process_Schedule_Delay (Time("17:20:00");Current  
> date(*);6)
>      End if
>    End if
>  End if
>
> When the overnight process was done, it would launch another process  
> that merely scheduled the overnight process to spawn later.
>
>  If (Not($fatal_error | Shell_Process_Stop))
>      `  <•> update progress status
>      ` [redacted]
>      `  <•> wait for launch date-time
>    Shell_Process_Schedule_Delay ($tms_time_value;$tms_date;6)
>  End if
>
>    `  <<-->> execute task <<-->>
>  If (Not($fatal_error | Shell_Process_Stop))
>    EXECUTE($tms_task)
>  End if
>
> I think the method below makes such scheduling easy and flexible.
>
> ####
>  `  Method: Shell_Process_Schedule_Delay
>  `
>  `  Description: delay process until launch threshold time
>
> C_TIME($launch_time_threshold;$1)
> C_DATE($launch_date_threshold;$2)
> C_LONGINT($check_interval_in_minutes;$3)
> C_LONGINT($ticks_per_second)
> C_LONGINT($seconds_per_minute)
> C_LONGINT($delay)
>
>  `  <<-->> obtain parameters <<-->>
> $lauch_time_threshold:=$1
> $launch_date_threshold:=$2
> $check_interval_in_minutes:=$3
>
>  `  <<-->> delay process <<-->>
>  `  implemented via polling, much more difficult
>  `  ... to test and validate when working with
>  `  ... single calculated delay, if we throw
>  `  ... interrupt, only have to wait for
>  `  ... check interval to run down
> $ticks_per_second:=60
> $seconds_per_minute:=60
> $delay:=($check_interval_in_minutes*$seconds_per_minute*
> $ticks_per_second)
>  ` wait until desired date
> While (($launch_date_threshold>Current date(*)) &  
> Not(Shell_Process_Stop))
>  DELAY PROCESS(Current process;$delay)
> End while
>  ` wait until desired time
> While (($lauch_time_threshold>Current time(*)) &  
> Not(Shell_Process_Stop))
>  DELAY PROCESS(Current process;$delay)
> End while
> ####
>
> Sincerely,
> Sean Broderick
>
>
> On Mar 15, 2010, at 3:48 PM, Herman Van Doorslaer wrote:
>
>> Hi all,
>>
>> i'm trying to have the 4D server execute methods on specific times.
>> eg: at 03:00 AM, check all outstanding orders by suppliers and send  
>> them a mail requesting an update.
>>
>> Anybody got a clue how to best go about this?
>
> **********************************************************************
> The New 4D Partner Program - All the tools you need to be a  
> successful 4D Developer.
> Sign up Now:  http://www.4d.com/community/partner/registration.html
>
>
> 4D Internet Users Group (4D iNUG)
> FAQ:  http://lists.4d.com/faqnug.html
> Archive:  http://lists.4d.com/archives.html
> Options: https://lists.4d.com/mailman/options/4d_tech
> Unsub:  mailto:[hidden email]
> **********************************************************************

------------------------------------------------------------------------------------------------
  Chuck Miller Voice: (617) 739-0306
  Informed Solutions, Inc. Fax: (617) 232-1064
  PO Box 1720 mailto:[hidden email]
  Brookline, MA 02446 USA Registered 4D Developer
        Providers of 4D and Sybase connectivity
           http://www.informed-solutions.com
------------------------------------------------------------------------------------------------
This message and any attached documents contain information which may  
be confidential, subject to privilege or exempt from disclosure under  
applicable law.  These materials are intended only for the use of the  
intended recipient. If you are not the intended recipient of this  
transmission, you are hereby notified that any distribution,  
disclosure, printing, copying, storage, modification or the taking of  
any action in reliance upon this transmission is strictly prohibited.  
Delivery of this message to any person other than the intended  
recipient shall not compromise or waive such confidentiality,  
privilege or exemption from disclosure as to this communication.



**********************************************************************
The New 4D Partner Program - All the tools you need to be a successful 4D Developer.
Sign up Now:  http://www.4d.com/community/partner/registration.html


4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Loading...