title: Calling the service class from the active job class in rails
body: <p>I have my rails controller class which calls my active job class</p>
  
  <pre><code>class Api::V2::Events::WegSessionsController &lt; Api::V2::Events::ApplicationController
  before_action :load_service
  
  .... some code
  
  def synchronize
  @service.keep_cancelled = params[:keep_cancelled].to_b
  if @service.valid_connection?
  
    WegJob.perform_later
  
    render json: {
      status: :ok,
      message: @service.message
    }, status: :ok
  else
    render json: {
      status: :unprocessable_entity,
      errors: @event.errors.full_messages
    }, status: :ok
  end
  end
  
  ... some code
  
  def load_service
    @service = WegService.new(event: @event)
  end
  end
  </code></pre>
  
  <p>I have configured my job class in my Rails project to use Sidekiq and calling the service method here</p>
  
  <pre><code>class WegJob &lt; ApplicationJob
  queue_as :default
  
  def perform(*args)
   WegService.synchronize
  end
  end
  </code></pre>
  
  <p>This service class has the implementation of 'synchronize' method which I would be calling from my job class</p>
  
  <pre><code>class WegService
   include ActiveModel::Model
  
  ... some code
  
  def synchronize
   if event.weg_synced_at.present?
    update
   else
    create
   end
  
   event.update(weg_synced_at: Time.current)
  end
  
  ... some code along with update and create method implementations.
  end
  </code></pre>
  
  <p>When I am doing this, I am getting the following error</p>
  
  <pre><code>[ActiveJob] [WegJob] [fd7c1869-6909-471c-bf32-9b2270a8c39c] Error performing 
  WegJob (Job ID: fd7c1869-6909-471c-bf32-9b2270a8c39c) from Async(default) in 
  2556.3ms: NoMethodError (undefined method `synchronize' for WegService:Class):
  </code></pre>
  
  <p>I know my way calling the service method from the Job class is wrong. Where could I have possibly gone wrong?</p>