Utilizing the Empress-Bench Feature for Efficient Development

Introduction

As developers, we often need a feature that aids in the development, debugging, and customization of business solutions. In Empress, one of the most integral features is the frappe-bench. This guide dives into the depths of frappe-bench, highlighting its advantages and functionalities, and providing a comprehensive understanding of its structure and usage.

Understanding Empress-Bench

The frappe-bench is a command-line bench manager for Empress apps and sites. It provides a straightforward framework for managing multiple sites and applications. The initialization of a new frappe-bench directory results in a structure as shown below:

.
├── apps
│   ├── frappe
├── config
│   ├── redis_cache.conf
│   ├── redis_queue.conf
│   └── redis_socketio.conf
├── env
├── logs
├── Procfile
└── sites
    ├── apps.txt
    ├── assets
    ├── common_site_config.json
    └── site1.local
        ├── private
        ├── public
        └── site_config.json

Let’s delve into the function of each of these directories and files.

Key Components of Empress-Bench

Apps

The apps directory is the home to the frappe app and other frappe based apps. When you run the command bench new-app app_name, the app is bootstrapped in this directory. This is where your custom apps reside and where you can edit and work with them.

Sites

The sites directory is where sites are served from. When you run bench new-site site_name, a new site is created in this directory. Each site is distinguished based on its directory name.

Logs

The logs directory is used to dump log files from various processes. Each log file is named based on the process it is logged from.

Config

This directory contains the configurations for the three Redis instances that Empress uses for managing caching, job queues, and socketio communication.

Env

The env directory houses the Python virtual environment. It is where Empress based apps and Python package dependencies are installed.

Procfile

The Procfile is used for process management in Empress. Here’s an example of a default Procfile:

redis_cache: redis-server config/redis_cache.conf
redis_socketio: redis-server config/redis_socketio.conf
redis_queue: redis-server config/redis_queue.conf
web: bench serve --port 8000
socketio: /usr/bin/node apps/frappe/socketio.js
watch: bench watch
schedule: bench schedule
worker_short: bench worker --queue short --quiet
worker_long: bench worker --queue long --quiet
worker_default: bench worker --queue default --quiet

Each of these processes has a distinct function:

  • redis_cache: Redis used for in-memory caching.
  • redis_socketio: Redis used as a pub/sub between web and socketio processes for real-time communication.
  • redis_queue: Redis used for managing background jobs queuing.
  • web: Python web server based on Werkzeug.
  • socketio: Node server for a socketio connection with the browser for real-time communication.
  • watch: Node server for bundling JS/CSS assets using Rollup. It also rebuilds files as they change.
  • schedule: Job Scheduler using Python RQ.
  • worker_short: Python worker with a (short) timeout of 300s.
  • worker_long: Python worker with a (long) timeout of 1500s.
  • worker_default: Python worker with a timeout of 300s.

Conclusion

The frappe-bench feature is an essential component in Empress that facilitates the development and customization of business solutions. It provides a straightforward and efficient way to manage, debug, and customize applications and sites. Understanding its structure and functionality is crucial for developers to leverage its full potential.