Subscribe for automatic updates: RSS icon RSS

Login icon Sign in for full access | Help icon Help
Advanced search

Pages: [1]
  Reply  |  Print  
Author Topic: Force no communication with frontend  (Read 1136 times)
Jos? V.
Posts: 23


« on: July 07, 2021, 03:29:24 pm »

I have a app that runs in 2 different modes:
* Interactive mode with forms and user interaction.
* Background mode with no form open or user interaction.

When in background mode I run into an error (Can not connect to GUI) every time an interactive instruction is called(ex. options input wrap).
This happens because the background mode is running without a GDC waiting for a connection.

Most of my code is protected against this kind of situation and behaves accordingly, but to safeguard that this error does not occur I have been using FGLGUI=0 when using background mode.
This is an awkward use of FGLGUI but works somewhat fine, since it behaves like a TUI app and that what it was in 4gl.

My question is, what is the best practice for this kind of situation? Should I change FLGUI before calling the app? Or forcing FGLGUI=0 on the profile file for background mode?
Is there any better options?

Thank you!
Sebastien F.
Four Js
Posts: 463


« Reply #1 on: July 08, 2021, 08:00:41 pm »

Hello!

There is no FGLPROFILE entry to run in TUI mode, only the FGLGUI=0 environment variable.

Setting FGLGUI=0 before starting your batch programs may help to prevent GUI connection errors.

However, even in TUI mode, if the code starts to use some UI instructions, fglrun can switch the terminal in raw mode, and TTY escape sequences can be generated, that would corrupt the output of your batch program (if you want to redirect into a file for ex)

Batch program should only use simple DISPLAY commands, and base.Channel.openFile("<stderr>","w") to write to stderr...

So the best solution to me is to avoid any instruction that is related to UI.

Maybe you want to isolate all you batch / processing code in dedicated .4gl modules, and write all the UI instructions in other modules.

When starting a batch program from another program, consider also RUN .. IN FORM/LINE MODE option, see:
https://4js.com/online_documentation/fjs-fgl-manual-html/#fgl-topics/c_fgl_programs_RUN.html

Seb
Reuben B.
Four Js
Posts: 834


« Reply #2 on: July 09, 2021, 04:40:02 am »

Definitely set FGLGUI=0.  If you also still run in TUI mode, you may also consider an additional proprietary environment variable that allows you too distinguish between TUI programs to a terminal and running with no UI  e.g.

Code
  1. IF FGL_GETENV("MY_RUN_MODE") = "FOREGROUND" THEN
  2.   OPTIONS INPUT WRAP
  3.   OPTIONS FIELD ORDER FORM
  4. END IF
  5.  
  6. IF FGL_GETENV("MY_RUN_MODE") = "BACKGROUND" THEN
  7.   -- write error to output file
  8. ELSE
  9.   ERROR error_text
  10. END IF
  11.  



Two gotchas

1. Default value in Genero of FGLGUI if not set is 1 (see http://4js.com/online_documentation/fjs-fgl-manual-html/#fgl-topics/c_fgl_Mig0000_013.html) .  So either make sure it is set or have code of the form IF nvl(FGL_GETENV("FGLGUI"),1) = 1 if you are testing FGLGUI = 1

2. Don't start background programs via launchURL or shellexec on a .gdc file.  If you are trying to set FGLGUI=0 in an .xcf file you are going down the wrong path.  You can call them from GUI program with something like RUN "export FGLGUI=0; fglrun background-program" WITHOUT WAITING



It will also be in your interests to ensure that there is no unexpected UI code executed.  A license is consumed when you use UI code.  Note the output of this at the command line with FGLGUI=0

Code
  1. MAIN
  2.    RUN "fglWrt -a info users"
  3.    OPTIONS INPUT WRAP
  4.    RUN "fglWrt -a info users"
  5. END MAIN



Separating UI from Business Logic not only helps avoid executing UI code but will also help with web services.  This can't be called in a web service or background job ...

Code
  1. FUNCTION validate_field(value)
  2.   IF bad-value THEN
  3.      CALL FGL_WINMESSAGE("Error","Value must be good","stop")
  4.   END IF
  5. END FUNCTION

... whereas this can be called from a GUI program, Web Service, or background job

Code
  1. FUNCTION valid_field(value)
  2.   IF bad-value THEN
  3.      RETURN FALSE, "Value must be good"
  4.   END IF
  5.   RETURN TRUE, ""
  6. END FUNCTION

Reuben

Product Consultant (Asia Pacific)
Developer Relations Manager (Worldwide)
Author of https://4js.com/ask-reuben
Contributor to https://github.com/FourjsGenero
Jos? V.
Posts: 23


« Reply #3 on: July 09, 2021, 04:32:26 pm »

When I said FGLPROFILE entry to force TUI mode I was refering to "gui.uiMode" as seen here:
https://4js.com/online_documentation/fjs-fgl-3.10.00-manual-html/#fgl-topics/c_fgl_fglprofile_004.html

Thank you for your explanations, I will force FGLGUI=0 and review all UI instructions like "options input" and displays.

Pages: [1]
  Reply  |  Print  
 
Jump to:  

Powered by SMF 1.1.21 | SMF © 2015, Simple Machines