编辑:实际上非常简单,我忘了传入site
和token
我已经在Heroku上设置了Sidekiq和Redis,我能够使用这样非常简单的工作:
order_worker.rb
class OrderWorker
include Sidekiq::Worker
sidekiq_options retry: false
def perform(num_orders)
x=3*5
end
end
但根据Sidekiq网站,更复杂的工作仍然失败。我需要以某种方式包括ShopifyAPI和Faker吗?我对于正在运行的内容并不十分清楚。是整个应用程序,宝石和所有都是在工作人员dyno中创建的?
order_worker.rb
class OrderWorker
include Sidekiq::Worker
sidekiq_options retry: false
def perform(num_orders)
include ShopifyAPI
include Faker
# Initialize session
session = ShopifyAPI::Session.new(site, token)
ShopifyAPI::Base.activate_session(session)
#Create orders
num_orders.times do
new_order = ShopifyAPI::Order.new(
:line_items => [
ShopifyAPI::LineItem.new(
:quantity => 1,
:variant_id => 25701798472
)
]
)
new_order.billing_address = ShopifyAPI::BillingAddress.new(:name => Faker::Name.name, :zip => zips[rnd], :country => 'United States', :province => states[rnd], :address1 => Faker::Address.street_address, :city => Faker::Address.city)
new_order.email = r.rand(36**2).to_s(36) + '@yahoo.com'
new_order.created_at = Faker::Time.backward(390, :evening)
new_order.total_price = Faker::Number.decimal(3, 2)
new_order.save
@errs = @errs + new_order.errors.full_messages
sleep 0.03
end
end
end
答案 0 :(得分:0)
请注意def locate(list_var):
i = 0
for l in list_var:
if l == 1 and i == 0:
i = 1
elif l == 2 and i == 1:
i = 2
elif l == 3 and i == 2:
return "YES"
return "NO"
print(locate([45, 1, 5, 2, 77, 3]))
print(locate([45, 1, 3, 77, 2]))
是一个实例方法,这意味着它在OrderWorker#perform
的实例范围内运行,而不是在类OrderWorker
本身。实例没有方法OrderWorker
。它属于这个类。结果是,当任务运行时,您将获得include
。
P.S。看来你不必NoMethodError
任何东西。删除include
内的include
将使您的员工工作。