Where 'require' statements should be placed inside workers?

16 views
Skip to first unread message

jdeel

unread,
Oct 6, 2016, 9:45:16 AM10/6/16
to Sidekiq
I need to place require statements (require 'nokogiri' and require 'open-uri') inside a worker file.
What is the best place to pace them: before the class definition, inside the class or inside perform method?
Is there any issue in placing them inside the worker's class, straight after the 'include Sidekiq::Worker' statement like in the example below?

class HardWorker
  include Sidekiq::Worker
require 'nokogiri'
require 'open-uri'

  def perform(name, count) # do something end end


Mike Perham

unread,
Oct 6, 2016, 10:23:55 AM10/6/16
to sid...@googlegroups.com
It's idiomatic to put them at the top of the file.  There's zero benefit to placing them where you have them in your example.

--
You received this message because you are subscribed to the Google Groups "Sidekiq" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sidekiq+unsubscribe@googlegroups.com.
To post to this group, send email to sid...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sidekiq/be452c88-f07c-47fb-a774-6c417c74b351%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Mike Perham – CEO, Contributed Systems
Smart, effective open source infrastructure for your apps.

jdeel

unread,
Oct 6, 2016, 10:29:00 AM10/6/16
to Sidekiq
On Thursday, October 6, 2016 at 4:23:55 PM UTC+2, Mike Perham wrote:
It's idiomatic to put them at the top of the file.  There's zero benefit to placing them where you have them in your example.


Many thanks for your help.
I will place them at the top of the file as you suggest
Reply all
Reply to author
Forward
0 new messages