Author: sifars

  • Best way to handle background processes in linux

    Best way to handle background processes in linux

    Reading Time: 2 minutes

    Every developer eventually reaches a stage where they need to run multiple background jobs on a server with high reliability and uptime. These background processes often support critical systems such as:

    • Website servers
    • Email servers
    • Job schedulers
    • Worker queues

    Such processes usually behave like daemon processes that run continuously in the background.

    However, background jobs may stop due to system errors, unexpected exceptions, or misconfigurations. Constant manual monitoring of these processes is not practical. Instead, developers use a process control system like Supervisor.

    Organizations building scalable platforms with a software development company often rely on tools like Supervisor to ensure critical background services remain active.

    What is Supervisor?

    Supervisor is a process control system for Linux that helps manage and monitor background processes. It automatically starts, stops, and restarts applications if they fail.

    Using Supervisor allows developers to ensure that long-running services remain active without manual intervention.

    Many companies that build scalable platforms with custom software development services rely on such tools to maintain stable server environments.

    Installing Supervisor on Ubuntu

    To install Supervisor on an Ubuntu system, run the following command:

    sudo apt-get install supervisor

    This will install the Supervisor package and enable the process management service.

    Configuring Supervisor

    Let’s assume you have a command that should run continuously in the background.

    python run_this_command

    Supervisor configuration files are stored inside the directory:

    /etc/supervisor/conf.d

    Create a new configuration file named:

    monitor-my-process.conf

    Now add the following configuration inside the file:

    [program:my-worker]
    process_name=%(program_name)s_%(process_num)02d
    command=python run_this_command
    autostart=true
    autorestart=true
    user=linux_user
    numprocs=8
    redirect_stderr=true
    stdout_logfile=/home/linux_user/app.com/worker.log

    Explanation of Important Parameters

    • command – the command that Supervisor will run
    • autostart=true – starts the process automatically
    • autorestart=true – restarts the process if it fails
    • numprocs=8 – runs 8 instances of the process
    • stdout_logfile – stores logs for debugging

    Replace linux_user with the username under which the process should run.

    Such background worker processes are commonly used in large platforms developed by a web application development company in usa where multiple server tasks must run continuously.

    Starting Supervisor

    After creating the configuration file, update Supervisor to load the new process configuration.

    Run the following commands:

    sudo supervisorctl reread
    sudo supervisorctl update
    sudo supervisorctl start my-worker:*

    Once started, Supervisor will automatically monitor the process and restart it if it fails.

    Now your background processes will run continuously with automatic recovery and monitoring.

    Useful Supervisor Commands

    Here are some useful commands that developers frequently use when managing background workers.

    Stop All Workers

    sudo supervisorctl stop my-worker:*

    Restart All Workers

    sudo supervisorctl restart my-worker:*

    Check Worker Status

    sudo supervisorctl status my-worker:*

    These commands help developers manage background tasks efficiently in production environments.

    Large applications developed by a SaaS web application development company often depend on background workers for tasks such as:

    • sending emails
    • processing payments
    • running scheduled jobs
    • handling asynchronous tasks

    Conclusion

    Handling background processes efficiently is essential for maintaining stable server infrastructure. Tools like Supervisor make it easy to monitor, restart, and manage long-running tasks without manual intervention.

    By using Supervisor, developers can ensure that critical services continue running even if errors occur.

    Many modern applications depend on background job processing, especially those built using scalable architectures.

    If you are building a complex platform or cloud-based application, working with an experienced custom software development services provider can help ensure reliable infrastructure and efficient system performance.

    🌐 www.sifars.com

  • Vuejs: Constants from back end API

    Vuejs: Constants from back end API

    Reading Time: 2 minutes

    When building modern applications, developers often work with repeated values such as configuration settings, feature flags, or application constants. Hardcoding these values across multiple files can make the code difficult to maintain.

    That is why developers usually define constants in a separate file and import them wherever needed.

    Example:

    import constants from 'path_to_file/constants.js'

    This method works well when constants are defined on the frontend. However, sometimes these values are stored on the backend server and must be fetched using an API request.

    In such cases, developers must ensure that these constants are loaded before any Vue components are rendered.

    Many companies working with a custom web application development services provider adopt structured solutions like this to keep applications scalable and maintainable.

    The Challenge with Backend Constants

    When constants are stored on the backend, developers typically fetch them using an AJAX request.

    However, simply requesting the data is not enough. The application must ensure that:

    • constants are available before the app loads
    • every component can access them
    • the solution remains clean and maintainable

    Writing the received constants into a file manually is not a practical solution. Instead, we can use JavaScript’s prototype-based inheritance to solve this problem.

    Understanding Object Prototype in JavaScript

    To understand this solution, we first need to look at function constructors and prototypes in JavaScript.

    Each object created using a function constructor has access to its prototype.

    Example:

    /**
    * A function constructor
    */
    function Person(firstname) {
    this.firstname = firstname;
    }// Add method to prototype
    Person.prototype.printFirstName = function() {
    console.log(this.firstname);
    }// Create objects
    let person1 = new Person('Munish')
    let person2 = new Person('John')

    Both objects created using the constructor can access the prototype method.

    person1.printFirstName()   // Munish
    person2.printFirstName() // John

    This prototype concept can also be applied in VueJS applications.

    Developers working with a web application development company in usa often use such architecture patterns to build scalable front-end applications.

    Using Vue Instance Prototype

    We can fetch constants from the backend API and attach them to the Vue prototype. This ensures that all components can access the constants easily.

    Example:

    axios.get('http://SERVER_ADDRESS/getConstants')
    .then(function(res) { Vue.prototype.$constants = res.body.data; // Initialize Vue instance after constants load
    new Vue({
    el: '#app'
    })});

    In this approach:

    • constants are fetched from the backend
    • stored in Vue.prototype
    • accessible across all Vue components

    This technique helps maintain clean code architecture and reduces duplication.

    Large applications developed by a SaaS web application development company often follow such practices to ensure maintainable front-end architecture.

    Accessing Constants in Vue Components

    Once the constants are added to the Vue prototype, they can be accessed inside any component using the following syntax:

    this.$constants.someConstant

    This approach ensures that the constants are globally available across the application.

    It simplifies development and keeps the codebase organized.

    Important Note

    Ensure that your getConstants API endpoint is lightweight and fast.

    The front-end application will not initialize until the API response is received. If the API performs heavy operations, it may delay the application startup.

    Therefore, the API should only return constant values without performing complex computations.

    Developers building scalable systems often work with custom web application developers who implement optimized backend APIs for better performance.

    Conclusion

    Managing constants efficiently is important for maintaining a clean and scalable codebase. When constants are stored on the backend, using the Vue prototype approach ensures that they are available globally across all components.

    This method avoids repeated API calls, keeps the application architecture organized, and simplifies frontend development.

    Modern businesses building scalable applications often rely on professional custom web application development services to implement efficient frontend architectures and API integrations.

    🌐 www.sifars.com