Как использовать отложенное задание для метода в ActiveModel (Ruby на Rails) - PullRequest
0 голосов
/ 23 марта 2020

У меня есть контроллер как

class Api::V2::Events::WegSessionsController < Api::V2::Events::ApplicationController

def synchronize
 if @service.valid_connection?
  @service.delay.synchronize
   render json: {
    status: :ok,
    message: @service.message
  }, status: :ok
else
  render json: {
    status: :unprocessable_entity,
    errors: @event.errors.full_messages
  }, status: :ok
 end
 ..Service instantiation and other code
 end
end

, и класс обслуживания выглядит как

class WegService
include ActiveModel::Model

def synchronize
 if event.weg_synced_at.present?
  update
 else
  create
 end

 event.update(weg_synced_at: Time.current)
end
...Some code
end

Но я не могу выполнить это, так как мой метод @ service.delay.synchronize выдает ошибку.

<ArgumentError: job cannot be created for non-persisted record:

Что мне здесь делать?

...