Giter VIP home page Giter VIP logo

tanhongit / send_mail_background_job Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 21.55 MB

Send mail background job Rails 6 with gem sidekiq

Home Page: https://tanhongit.github.io/send_mail_background_job/

License: MIT License

Ruby 77.27% JavaScript 8.05% CSS 1.51% HTML 12.78% SCSS 0.38%
background-jobs ruby ruby-on-rails sendmail rails-send-mail tanhongit rails6 backgound-job-mail sidekiq gem-sidekiq

send_mail_background_job's Introduction

Welcome to Rails 6 Send Mail Backgtound Job with gem sidekiq

The Rails 6 Send Mail Backgtound Job is a small task for everyone to practice more when programming with Ruby on Rails.

We will use gem sidekiq to perform this task.

Support for me

Support this project ๐Ÿ˜œ ๐Ÿ™

PayPal buymeacoffee TanHongIT

1. Technology

  • Ruby on Rails

2. Configuration requirements

We are going to build the web application using:

  • Rails 6.0.3.2
  • Ruby 2.7.1

4. What is background Job

Since you already know the call to your Application will be slow, you want it to happen in a background job, so that users can see the confirmation message in their browser immediately without having to wait for the charge to actually happen. To do this, you must create an Active Job class, implement that class to call charge!(), and then add code to the controller to execute this job. The flow looks like the following figure.

Image

5. Runing

5.1. Clone Repo

$ git clone https://github.com/TanHongIT/send_mail_background_job
$ cd send_mail_background_job

5.2. Bundle Install

$ bundle install

5.3. Yarn Install

$ yarn install

5.4. Create database with Postgresql

You must change the appropriate database configuration

Change configuration at "config/database.yml" with Postgresql.

default: &default
  adapter: postgresql
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  timeout: 5000
  username: send_mail_background_job
  password: 1234
  host: localhost

# tutorial for ubuntu linux:
# sudo -u postgres psql
# create user "send_mail_background_job" with password '1234';  
# create database "send_mail_background_job" owner "send_mail_background_job"; 

development:
  <<: *default
  database: send_mail_background_job

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  <<: *default
  database: send_mail_background_job_test

production:
  <<: *default
  database: send_mail_background_job_production

You must change the username, password and database name accordingly!

5.5. run rails db:migrate

$ rails db:migrate

5.6. Change your mail

Run console :

$ bundle exec figaro install

Go to config directory and add to file "config/application.yml"

user_mail: '[email protected]'
password: 'your password'

Change your mail in app/mailers/application_mailer.rb

class ApplicationMailer < ActionMailer::Base
  default from: 'your_mail'
  layout 'mailer'
end

5.7. Run sidekiq

$ bundle exec sidekiq

5.8. Run server

Open new terminal and run:

rails s

Now go to at http://localhost:3000/users/new and put your mail end waiting for a response to arrive

6. Demo

Image

license

send_mail_background_job's People

Contributors

tanhongit avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.