Skip to content

Instantly share code, notes, and snippets.

View ayerdines's full-sized avatar

Dinesh Budhayer ayerdines

  • Employment Hero
  • Kathmandu, Nepal
  • 13:15 (UTC +05:45)
View GitHub Profile
@ayerdines
ayerdines / devise_helpers.md
Last active September 29, 2023 15:38
Devise URL helpers with corresponding pages
  • GET new_user_session_path -> Sign In Page
  • POST user_session_path -> Sign In Action
  • DELETE destroy_user_session_path -> Sign Out Action
  • GET edit_user_password_path -> Update Password Page
  • PATCH user_password_path -> Update Password Action
@ayerdines
ayerdines / delayed_jobs.md
Last active April 21, 2022 10:20
Read before using delayed jobs

Things to be careful about when using delayed jobs

  1. Do not use delayed jobs if your system can have 100k+ jobs at a time in delayed jobs table. It'll cause the jobs to run very slow.

  2. Check conditions before adding the jobs to queue, instead of checking inside the job. This'll prevent delayed jobs table from being over-populated.

    # bad
    class Order < ApplicationRecord
      after_create :send_to_webhook
      

def send_to_webhook

@ayerdines
ayerdines / generic_job.rb
Last active April 21, 2023 06:03
handle_asynchronously, delay with sidekiq, make sidekiq work with instance methods
class GenericJob
include Sidekiq::Job
def perform(klass, id, undelayed_method, *args)
object = klass.constantize.find(id)
object.send(undelayed_method, *args)
end
end