Force no communication with frontend

Started by José V., July 07, 2021, 03:29:24 PM

Previous topic - Next topic

José V.

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.

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.

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 (genero) Select
IF FGL_GETENV("MY_RUN_MODE") = "FOREGROUND" THEN
   OPTIONS INPUT WRAP
   OPTIONS FIELD ORDER FORM
END IF

IF FGL_GETENV("MY_RUN_MODE") = "BACKGROUND" THEN
   -- write error to output file
ELSE
   ERROR error_text
END IF




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 (genero) Select
MAIN
    RUN "fglWrt -a info users"
    OPTIONS INPUT WRAP
    RUN "fglWrt -a info users"
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 (genero) Select
FUNCTION validate_field(value)
   IF bad-value THEN
      CALL FGL_WINMESSAGE("Error","Value must be good","stop")
   END IF
END FUNCTION


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

Code (genero) Select
FUNCTION valid_field(value)
   IF bad-value THEN
      RETURN FALSE, "Value must be good"
   END IF
   RETURN TRUE, ""
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.

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.