Skip to content

Commit

Permalink
job ok
Browse files Browse the repository at this point in the history
  • Loading branch information
thib44 committed Apr 4, 2017
1 parent 6bbd9fd commit 22c555e
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 5 deletions.
11 changes: 6 additions & 5 deletions app/controllers/backend/inventories_controller.rb
Expand Up @@ -67,11 +67,12 @@ def refresh

def reflect
return unless @inventory = find_and_check
if @inventory.reflect
notify_success(:changes_have_been_reflected)
else
notify_error(:changes_have_not_been_reflected)
end
ReflectInventoryJob.perform_later(@inventory, current_user)
# if @inventory.reflect
# notify_success(:changes_have_been_reflected)
# else
# notify_error(:changes_have_not_been_reflected)
# end
redirect_to action: :index
end
end
Expand Down
32 changes: 32 additions & 0 deletions app/jobs/reflect_inventory_job.rb
@@ -0,0 +1,32 @@
class ReflectInventoryJob < ActiveJob::Base
queue_as :default

def perform(inventory, user)
result = inventory.reflect
user.notifications.build(notification_params(result, inventory))
# if inventory.reflect
# user.notifications.build(notification_params(:success, inventory))
# # notify_success(:changes_have_been_reflected)
# else
# notify_error(:changes_have_not_been_reflected)
# end
end

private

def notification_params(result, inventory)
{
message: (result ? :changes_have_been_reflected : :changes_have_not_been_reflected),
level: (result ? :success : :error),
target_type: "Inventory",
interpolations: {
inventory_id: inventory.id,
inventory_name: inventory.name
}
}
end

def result_message(result)
result ? :changes_have_been_reflected : :changes_have_not_been_reflected
end
end
5 changes: 5 additions & 0 deletions test/jobs/reflect_inventory_job_test.rb
@@ -0,0 +1,5 @@
require 'test_helper'

class ReflectInventoryJobTest < ActiveJob::TestCase

end

0 comments on commit 22c555e

Please sign in to comment.