I have an API with the following code
class API::V1::ReceptionController < API::V1::APIController before_filter :ensure_document_exists def produto jid = ProdutoWorker.perform_async params[:document] render json: {jid: jid}, :status => 200 end def cliente jid = ClienteFornecedorWorker.perform_async params[:document] render json: {jid: jid}, :status => 200 end def nota_fiscal jid = NotaFiscalWorker.perform_async params[:document] render json: {jid: jid}, :status => 200 end def venda jid = VendaWorker.perform_async params[:document] render json: {jid: jid}, :status => 200 end def reducaoz jid = ReducaoZWorker.perform_async params[:document] render json: {jid: jid}, :status => 200 end def impressora_fiscal jid = ImpressoraFiscalWorker.perform_async params[:document] render json: {jid: jid}, :status => 200 end .............. and so on. What happens is: every method call a different worker, but all the body's methods are pretty much the same. My question is: how can I reduce this methods to maybe just one?
ProdutoWorkermeans? As your code is currently missing context. \$\endgroup\$params[:document]will always be a JSON that represents a model (a product, a client, an order and so) any of theseSomethingWorkerreceives this JSON and process him following some internal rules \$\endgroup\$