class AsyncExampleProgram(AsyncBaseProgram): (source)
This asynchronous server program demonstrates how to use ini files that contain both environment variables and secrets that are expanded as well as dynamically handles changing parameters in a running program.
The program also shows how to monitor a directory for arriving files as well as how to send topic queue messages and subscribe for topic queue messages using RabbitMQ.
There's also a scheduling mechanism that handles periodic events. The program is stopped gracefully by pressing Ctrl-C or pressing the 'X' in the upper right corner of the terminal window. The program handles both Windows and Linux platforms.
- macOS caveat:
- You have to add some code in tools/file_utilities.is_file_available() that handles file availability if not lsof is available.
- You also have to add a [darwin] platform block in the INI file.
- The following environment variable dependencies exist:
- ENVIRONMENT (on all servers)
- HOSTNAME (on Linux servers only - set by OS)
- COMPUTERNAME (on Windows servers only - set by OS)
- The following secret dependencies exist:
- mongo_pwd
- The following jobs are scheduled:
- _schedule_ini_check(): runs every five seconds.
- _schedule_dump_check(): runs every five seconds.
- _schedule_state_pruning(): runs at midnight every day, and at startup.
RabbitMQ is used for sending messages to external programs. Messages that are to be sent to the RabbitMQ will be stored offline if the communication goes down and will be re-sent when the communication is re-established.
- Subscribe temporarily for the following RabbitMQ message topic(s):
- Health.Request
- Subscribe permanently for the following RabbitMQ message topic(s):
- File.ReportRequest.<SERVER>
- Sends RabbitMQ messages with the following topic(s):
- File.Report.<server>
- File.Detected.<server>
- Error.Message.AsyncExampleProgram.<server>
- Health.Response.AsyncExampleProgram.<server>
| Instance Variable | ini |
Handles INI file parameters for this program. |
| Instance Variable | worker |
Handles the bulk of the work for this program. |
| Async Method | _initiate |
Initiate unique resources used by the program. |
| Async Method | _schedule |
Send INI file update notification to the worker. |