Skip to content

Commit

Permalink
close #2187 separate UniqueJob and ApplicationJob
Browse files Browse the repository at this point in the history
  • Loading branch information
LengTech11 committed Jan 10, 2025
1 parent c591267 commit 2031c46
Show file tree
Hide file tree
Showing 21 changed files with 28 additions and 19 deletions.
3 changes: 3 additions & 0 deletions app/jobs/application_unique_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Add any logics inside app/jobs/spree_cm_commissioner/application_job.rb instead.
# Let application override this.
class ApplicationUniqueJob < ActiveJob::Base; end # rubocop:disable Rails/ApplicationJob
6 changes: 6 additions & 0 deletions app/jobs/spree_cm_commissioner/application_unique_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# override this on your server.
module SpreeCmCommissioner
class ApplicationUniqueJob < ::ApplicationUniqueJob
queue_as :default
end
end
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module SpreeCmCommissioner
class ChatraceOrderCreatorJob < ApplicationJob
class ChatraceOrderCreatorJob < ApplicationUniqueJob
# :chatrace_user_id, :chatrace_return_flow_id, :chatrace_api_host, :chatrace_access_token
# :guest_token, :order_params
def perform(options)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module SpreeCmCommissioner
class ConversionPreCalculatorJob < ApplicationJob
class ConversionPreCalculatorJob < ApplicationUniqueJob
queue_as :default

def perform(product_id)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module SpreeCmCommissioner
class CustomerContentNotificationCreatorJob < ApplicationJob
class CustomerContentNotificationCreatorJob < ApplicationUniqueJob
def perform(options)
SpreeCmCommissioner::CustomerContentNotificationCreator.new(options).call
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module SpreeCmCommissioner
class CustomerNotificationSenderJob < ApplicationJob
class CustomerNotificationSenderJob < ApplicationUniqueJob
def perform(customer_notification_id, user_ids = nil)
customer_notification = SpreeCmCommissioner::CustomerNotification.find(customer_notification_id)
SpreeCmCommissioner::CustomerNotificationSender.call(customer_notification: customer_notification, user_ids: user_ids)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module SpreeCmCommissioner
module EnqueueCart
class AddItemJob < ApplicationJob
class AddItemJob < ApplicationUniqueJob
def perform(order_id, variant_id, quantity, public_metadata, private_metadata, options) # rubocop:disable Metrics/ParameterLists
SpreeCmCommissioner::EnqueueCart::AddItem.call(
order_id: order_id,
Expand Down
2 changes: 1 addition & 1 deletion app/jobs/spree_cm_commissioner/export_csv_job.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module SpreeCmCommissioner
class ExportCsvJob < ApplicationJob
class ExportCsvJob < ApplicationUniqueJob
def perform(id)
Exports::ExportGuestCsvService.new(id).call
end
Expand Down
2 changes: 1 addition & 1 deletion app/jobs/spree_cm_commissioner/import_order_job.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module SpreeCmCommissioner
class ImportOrderJob < ApplicationJob
class ImportOrderJob < ApplicationUniqueJob
def perform(import_order_id, import_by_user_id, import_type)
if import_type == 'new_order'
SpreeCmCommissioner::Imports::CreateOrderService.new(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module SpreeCmCommissioner
class InvalidateCacheRequestJob < ApplicationJob
class InvalidateCacheRequestJob < ApplicationUniqueJob
def perform(pattern)
SpreeCmCommissioner::InvalidateCacheRequest.call(pattern: pattern)
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module SpreeCmCommissioner
class OptionTypeVariantsPublicMetadataUpdaterJob < ApplicationJob
class OptionTypeVariantsPublicMetadataUpdaterJob < ApplicationUniqueJob
def perform(option_type_id)
optino_type = ::Spree::OptionType.find(option_type_id)
optino_type.variants.find_each(&:set_options_to_public_metadata!)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module SpreeCmCommissioner
class OptionValueVariantsPublicMetadataUpdaterJob < ApplicationJob
class OptionValueVariantsPublicMetadataUpdaterJob < ApplicationUniqueJob
def perform(option_value_id)
option_value = ::Spree::OptionValue.find(option_value_id)
option_value.variants.find_each(&:set_options_to_public_metadata!)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# queue_webhooks_requests! already contains queue job, but before it prepare to call queue_webhooks_requests!,
# it could raise serializer error which needed to be recorded in queue dashboard.
module SpreeCmCommissioner
class OrderCompleteTelegramSenderJob < ApplicationJob
class OrderCompleteTelegramSenderJob < ApplicationUniqueJob
queue_as :telegram_bot

def perform(order_id)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# queue_webhooks_requests! already contains queue job, but before it prepare to call queue_webhooks_requests!,
# it could raise serializer error which needed to be recorded in queue dashboard.
module SpreeCmCommissioner
class QueueOrderWebhooksRequestsJob < ApplicationJob
class QueueOrderWebhooksRequestsJob < ApplicationUniqueJob
def perform(options)
order_id = options[:order_id]
event = options[:event]
Expand Down
2 changes: 1 addition & 1 deletion app/jobs/spree_cm_commissioner/sms_job.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module SpreeCmCommissioner
class SmsJob < ApplicationJob
class SmsJob < ApplicationUniqueJob
end
end
2 changes: 1 addition & 1 deletion app/jobs/spree_cm_commissioner/state_job.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module SpreeCmCommissioner
class StateJob < ApplicationJob
class StateJob < ApplicationUniqueJob
def perform(state_id)
state = ::Spree::State.find_by(id: state_id)
StateUpdater.call(state: state)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module SpreeCmCommissioner
class TelegramDebugPinCodeSenderJob < ApplicationJob
class TelegramDebugPinCodeSenderJob < ApplicationUniqueJob
def perform(pin_code_id)
pin_code = SpreeCmCommissioner::PinCode.find(pin_code_id)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module SpreeCmCommissioner
class TelegramNotificationSenderJob < ApplicationJob
class TelegramNotificationSenderJob < ApplicationUniqueJob
def perform(options)
return if options[:chat_id].nil?

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module SpreeCmCommissioner
class TelegramStartMessageSenderJob < ApplicationJob
class TelegramStartMessageSenderJob < ApplicationUniqueJob
queue_as :telegram_bot

# :chat_id, :telegram_bot_id
Expand Down
2 changes: 1 addition & 1 deletion app/jobs/spree_cm_commissioner/vendor_job.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module SpreeCmCommissioner
class VendorJob < ApplicationJob
class VendorJob < ApplicationUniqueJob
def perform(vendor_id)
vendor = ::Spree::Vendor.find(vendor_id)
VendorUpdater.call(vendor: vendor)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module SpreeCmCommissioner
class WebhookSubscriberOrdersSenderJob < ApplicationJob
class WebhookSubscriberOrdersSenderJob < ApplicationUniqueJob
def perform(options)
order_state = options[:order_state]
webhooks_subscriber_id = options[:webhooks_subscriber_id]
Expand Down

0 comments on commit 2031c46

Please sign in to comment.