We have recently faced issue with Elasticsearch field types and mapping, when if a field is mapped with a type other type can not be indexed for the same field. Elasticsearch indesing mechanism ristrict that. for example we have created a index named users and inserted a record with text type field name. Read on →

Distributed global locking using mysql get_lock(), ensures releasing orphaned lock.

USE CASE 1:

Eliminate SPOF of background jobs or scheduled/cron job

USE CASE 2:

A process that allowed to run only once on a given time however the process is deployed on multiple hosts as part of different micro-services, ie. scheduled jobs


GET_LOCK(str,timeout)

Tries to obtain a lock with a name given by the string str, using a timeout of timeout seconds. A negative timeout value means infinite timeout. The lock is exclusive. While held by one session, other sessions cannot Read on →

Setup Local DevEnv Replica Set

  1. update mongod.conf for replication

     #edit /usr/local/etc/mongod.conf
     systemLog:
         destination: file
         path: /usr/local/var/log/mongodb/mongo.log
         logAppend: true
     storage:
         dbPath: /usr/local/var/mongodb
     net:
         bindIp: 127.0.0.1
     replication:
         replSetName: rs0
         oplogSizeMB: 100
    
Read on →

Prepare helper scripts for application setup, app start and httpd config

Helper scripts can be stored as part of application code in directory scripts in project root directory.

Sample application setup script

# scripts/application_setup.sh

#! /bin/bash
bundle exec rake db:migrate
bundle exec rake db:seed
Read on →

ApplicationRecord

Similar to ApplicationController which is the common base class for all controllers that you get with new Rails apps, ApplicationRecord will provide a base class for your ActiveRecord models. This provides a common place to put any base model concerns. app/models/application_record.rb file will be automatically added to models in Rails 5 applications.

# app/models/application_record.rb
class ApplicationRecord < ActiveRecord::Base
    self.abstract_class = true
end

ActionCable

Action Cable can integrates websocket with rails application. Action Cable server can handle multiple connection instances. It has only one instance per websocket connection. The client websocker connection(consumer) can subscribe to multiple cable channels. Read on →