averi
(Andrea Veri)
October 2, 2019, 10:44am
1
We recently upgraded to 2.4.0.beta5 from 2.4.0.beta4 and sidekiq fails to start with the following traceback:
> $ bundle exec sidekiq -C config/sidekiq.yml
> uninitialized constant SiteSetting::SiteSettingExtension
> /discourse/app/models/site_setting.rb:5:in `<class:SiteSetting>'
> /discourse/app/models/site_setting.rb:3:in `<top (required)>'
> /discourse/vendor/bundle/ruby/2.5.0/gems/zeitwerk-2.1.10/lib/zeitwerk/kernel.rb:23:in `require'
> /discourse/vendor/bundle/ruby/2.5.0/gems/zeitwerk-2.1.10/lib/zeitwerk/kernel.rb:23:in `require'
> /discourse/vendor/bundle/ruby/2.5.0/gems/activesupport-6.0.0/lib/active_support/dependencies/interlock.rb:14:in `block in loading'
> /discourse/vendor/bundle/ruby/2.5.0/gems/activesupport-6.0.0/lib/active_support/concurrency/share_lock.rb:151:in `exclusive'
> /discourse/vendor/bundle/ruby/2.5.0/gems/activesupport-6.0.0/lib/active_support/dependencies/interlock.rb:13:in `loading'
> /discourse/config/initializers/004-message_bus.rb:120:in `<top (required)>'
> /discourse/vendor/bundle/ruby/2.5.0/gems/railties-6.0.0/lib/rails/engine.rb:667:in `block in load_config_initializer'
> /discourse/vendor/bundle/ruby/2.5.0/gems/activesupport-6.0.0/lib/active_support/notifications.rb:182:in `instrument'
> /discourse/vendor/bundle/ruby/2.5.0/gems/railties-6.0.0/lib/rails/engine.rb:666:in `load_config_initializer'
> /discourse/vendor/bundle/ruby/2.5.0/gems/railties-6.0.0/lib/rails/engine.rb:624:in `block (2 levels) in <class:Engine>'
> /discourse/vendor/bundle/ruby/2.5.0/gems/railties-6.0.0/lib/rails/engine.rb:623:in `each'
> /discourse/vendor/bundle/ruby/2.5.0/gems/railties-6.0.0/lib/rails/engine.rb:623:in `block in <class:Engine>'
> /discourse/vendor/bundle/ruby/2.5.0/gems/railties-6.0.0/lib/rails/initializable.rb:32:in `instance_exec'
> /discourse/vendor/bundle/ruby/2.5.0/gems/railties-6.0.0/lib/rails/initializable.rb:32:in `run'
> /discourse/vendor/bundle/ruby/2.5.0/gems/railties-6.0.0/lib/rails/initializable.rb:61:in `block in run_initializers'
> /usr/local/lib/ruby/2.5.0/tsort.rb:228:in `block in tsort_each'
> /usr/local/lib/ruby/2.5.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
> /usr/local/lib/ruby/2.5.0/tsort.rb:422:in `block (2 levels) in each_strongly_connected_component_from'
> /usr/local/lib/ruby/2.5.0/tsort.rb:431:in `each_strongly_connected_component_from'
> /usr/local/lib/ruby/2.5.0/tsort.rb:421:in `block in each_strongly_connected_component_from'
> /discourse/vendor/bundle/ruby/2.5.0/gems/railties-6.0.0/lib/rails/initializable.rb:50:in `each'
> /discourse/vendor/bundle/ruby/2.5.0/gems/railties-6.0.0/lib/rails/initializable.rb:50:in `tsort_each_child'
> /usr/local/lib/ruby/2.5.0/tsort.rb:415:in `call'
> /usr/local/lib/ruby/2.5.0/tsort.rb:415:in `each_strongly_connected_component_from'
> /usr/local/lib/ruby/2.5.0/tsort.rb:349:in `block in each_strongly_connected_component'
> /usr/local/lib/ruby/2.5.0/tsort.rb:347:in `each'
> /usr/local/lib/ruby/2.5.0/tsort.rb:347:in `call'
> /usr/local/lib/ruby/2.5.0/tsort.rb:347:in `each_strongly_connected_component'
> /usr/local/lib/ruby/2.5.0/tsort.rb:226:in `tsort_each'
> /usr/local/lib/ruby/2.5.0/tsort.rb:205:in `tsort_each'
> /discourse/vendor/bundle/ruby/2.5.0/gems/railties-6.0.0/lib/rails/initializable.rb:60:in `run_initializers'
> /discourse/vendor/bundle/ruby/2.5.0/gems/railties-6.0.0/lib/rails/application.rb:363:in `initialize!'
> /discourse/vendor/bundle/ruby/2.5.0/gems/railties-6.0.0/lib/rails/railtie.rb:190:in `public_send'
> /discourse/vendor/bundle/ruby/2.5.0/gems/railties-6.0.0/lib/rails/railtie.rb:190:in `method_missing'
> /discourse/config/environment.rb:7:in `<top (required)>'
> /discourse/vendor/bundle/ruby/2.5.0/gems/sidekiq-5.2.7/lib/sidekiq/cli.rb:288:in `boot_system'
> /discourse/vendor/bundle/ruby/2.5.0/gems/sidekiq-5.2.7/lib/sidekiq/cli.rb:46:in `run'
> /discourse/vendor/bundle/ruby/2.5.0/gems/sidekiq-5.2.7/bin/sidekiq:12:in `<top (required)>'
> /discourse/vendor/bundle/ruby/2.5.0/bin/sidekiq:23:in `load'
> /discourse/vendor/bundle/ruby/2.5.0/bin/sidekiq:23:in `<top (required)>'
> /usr/local/lib/ruby/site_ruby/2.5.0/bundler/cli/exec.rb:74:in `load'
> /usr/local/lib/ruby/site_ruby/2.5.0/bundler/cli/exec.rb:74:in `kernel_load'
> /usr/local/lib/ruby/site_ruby/2.5.0/bundler/cli/exec.rb:28:in `run'
> /usr/local/lib/ruby/site_ruby/2.5.0/bundler/cli.rb:463:in `exec'
> /usr/local/lib/ruby/site_ruby/2.5.0/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
> /usr/local/lib/ruby/site_ruby/2.5.0/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
> /usr/local/lib/ruby/site_ruby/2.5.0/bundler/vendor/thor/lib/thor.rb:387:in `dispatch'
> /usr/local/lib/ruby/site_ruby/2.5.0/bundler/cli.rb:27:in `dispatch'
> /usr/local/lib/ruby/site_ruby/2.5.0/bundler/vendor/thor/lib/thor/base.rb:466:in `start'
> /usr/local/lib/ruby/site_ruby/2.5.0/bundler/cli.rb:18:in `start'
> /usr/local/bin/bundle:30:in `block in <main>'
> /usr/local/lib/ruby/site_ruby/2.5.0/bundler/friendly_errors.rb:124:in `with_friendly_errors'
> /usr/local/bin/bundle:22:in `<main>'
Any guidance on where to look next? Thanks!
1 Like
Falco
(Falco)
October 2, 2019, 12:14pm
2
This isnāt a install that followed our official guide, so there isnāt much we can help you with.
1 Like
averi
(Andrea Veri)
October 2, 2019, 12:27pm
3
Weāre currently running discourse on Openshift so surely itās not a standard install, Iāll review the official guide and see whether I missed anything on the current deployment, thanks.
1 Like
azawawi
(Ahmad M. Zawawi)
October 2, 2019, 12:39pm
4
Actually even the following docker command is triggering the same stack trace in my discourse vagrant machine over virtualbox:
vagrant ssh -c '(cd ~/discourse && sudo bin/docker/sidekiq)'
Falco
(Falco)
October 2, 2019, 12:42pm
5
You sure about that? The official guide doesnāt have anything related manual starts of sidekiq and there is no /home/discourse folder in it.
Are you running a development install in production ??
1 Like
azawawi
(Ahmad M. Zawawi)
October 2, 2019, 12:45pm
6
I am using the docker commands to test and develop discourse plugins.
The other script I am currently using is:
# Clear temporary discourse cache and launch development rails
vagrant ssh -c '(rm -rf ~/discourse/tmp/cache)'
vagrant ssh -c '(cd ~/discourse && sudo bin/docker/rails s)'
azawawi
(Ahmad M. Zawawi)
October 2, 2019, 12:50pm
8
1 Like
Falco
(Falco)
October 2, 2019, 12:51pm
9
Oh it may be. The fact that you didnāt state that this is your development setup and not a dev environment didnāt help.
So you are saying that our docker dev setup is currently broken?
1 Like
azawawi
(Ahmad M. Zawawi)
October 2, 2019, 12:59pm
11
Reverting that commit makes sidekiq work again.
1 Like
Falco
(Falco)
October 2, 2019, 1:11pm
12
Looks like this is one for you @kris.kotlarek
8 Likes
Ok, I know what happened here, it is my fault. I removed a lot of require_dependency since they are not required anymore when using Zeitwerk autoloader.
However, in application.rb we got that:
if !Sidekiq.server?
config.autoload_paths += Dir["#{config.root}/lib"]
end
Which means that Sidekiq is not looking for lib directory to find dependencies and we explicitly define what is required in specific files.
I can bring back that require_depenedency for files which are used by Sidekiq or remove that guard in application.rb.
I guess that we used that explicit require to save some memory for workers, so probably we should follow that path. I will bring back require_dependency
@sam what is your opinion?
3 Likes
sam
(Sam Saffron)
October 2, 2019, 11:36pm
14
We should remove the guard, I donāt like it cause you have no idea if your process will become a sidekiq or not. In our deployments we have: unicorn master ā fork ā sidekiq worker. At fork time application.rb was already parsed.
4 Likes
azawawi
(Ahmad M. Zawawi)
October 3, 2019, 7:18am
15
@kris.kotlarek Thanks for the fix. Sidekiq is now working along with the discourse official plugins .
Most of my 3rd-party plugins with jobs are not working now . Most likely caused by the following commit not being applied on their Jobs:: classes.
committed 05:39PM - 16 Sep 19 UTC
Broken 3rd-party plugins
module Jobs
class MigrateStaticPagesPlugin < ::Jobs::Onceoff
# Migrate content from dl_static_pages name to procourse_static_pages
def execute_onceoff(args)
dl_page_presence = PluginStoreRow.where(plugin_name: "dl_static_pages").exists?
if dl_page_presence
# Migrate the page content rows
PluginStoreRow.where(plugin_name: 'dl_static_pages')
.find_each do |row|
PluginStore.set("procourse_static_pages", row.key, row.value)
row.destroy # clean up dl_static_pages row
end
# frozen_string_literal: true
# name: discourse-whos-online
# about: Display a list of online users at the top of the screen
# meta_topic_id: 52345
# version: 2.0
# authors: David Taylor
# url: https://github.com/discourse/discourse-whos-online
enabled_site_setting :whos_online_enabled
register_asset "stylesheets/whos_online.scss"
after_initialize do
module ::DiscourseWhosOnline
CHANNEL_NAME = "/whos-online/online"
end
register_presence_channel_prefix("whos-online") do |channel_name|
if channel_name == "/whos-online/online"
config = PresenceChannel::Config.new(timeout: SiteSetting.whos_online_active_timeago * 60)
if SiteSetting.whos_online_display_public
config.public = true
else
config.allowed_group_ids = [::Group::AUTO_GROUPS[:trust_level_0]]
end
config.count_only = SiteSetting.whos_online_count_only
config
end
end
on(:user_seen) do |user|
hidden = false
hidden ||= user.user_option.hide_presence if defined?(user.user_option.hide_presence)
hidden ||= user.id < 0
next if hidden
PresenceChannel.new(DiscourseWhosOnline::CHANNEL_NAME).present(
user_id: user.id,
client_id: "seen",
)
rescue PresenceChannel::InvalidAccess
end
add_to_serializer(
:site,
:whos_online_state,
include_condition: -> do
@whos_online_channel ||= PresenceChannel.new(DiscourseWhosOnline::CHANNEL_NAME)
@whos_online_channel.can_view?(user_id: scope.user&.id)
end,
) do
@whos_online_channel ||= PresenceChannel.new(DiscourseWhosOnline::CHANNEL_NAME)
PresenceChannelStateSerializer.new(@whos_online_channel.state, root: nil)
end
end
5 Likes
You are right, all Jobs::Onceoff, Jobs::Base and Jobs::Scheduled require now ::
I fixed discourse-whos-online and created pull requests for other plugins:
master ā KrisKotlarek:master
merged 11:50PM - 03 Oct 19 UTC
Fix similar to that one: https://github.com/discourse/discourse-assign/commit/d5⦠9e7fe1fbe95789324010b3729d0589a8a9789f
This is necessary since Discourse moved to Zeitwerk autoloader
master ā KrisKotlarek:master
merged 09:24PM - 07 Nov 19 UTC
Fix similar to that one: https://github.com/discourse/discourse-assign/commit/d5⦠9e7fe1fbe95789324010b3729d0589a8a9789f
This is necessary since Discourse moved to Zeitwerk autoloader
5 Likes
azawawi
(Ahmad M. Zawawi)
October 4, 2019, 5:13am
17
@kris.kotlarek Thanks a lot . I took a look at your post for the zeitwork auto-loader. Is there a plan to enable a development plugin auto-reloading feature to speed up plugin development.
Rails 6 ships with two autoloading modes: zeitwerk and classic. In that pull request DEV: Upgrading Discourse to Rails 6 by lis2 Ā· Pull Request #8083 Ā· discourse/discourse Ā· GitHub I upgraded Rails to version 6.0.0 with classic autoloader as a transitional phase. It would be interesting to try to switch to Zeitwerk.
Zeitwerk is an efficient and thread-safe code loader for Ruby. As long as the project is following naming conventions, Zeitwerk can find correct files and load them on demand or upfā¦
Efficient and thread-safe code loader for Ruby
3 Likes
There are still places containing require or require_dependency but many are removed.
I think that now pluginās code should be automatically reloaded without a problem. We need to play a little bit to ensure, but I have a positive feeling
5 Likes
azawawi
(Ahmad M. Zawawi)
October 6, 2019, 9:21am
19
It seems we need to enable it first as per its documentation. I tried it in development and no plugin changes were reloaded
Efficient and thread-safe code loader for Ruby
This guide documents how autoloading and reloading works in zeitwerk mode.After reading this guide, you will know: Related Rails configuration Project structure Autoloading, reloading, and eager loading Single Table Inheritance And more
1 Like
fzngagan
(Faizaan Gagan)
October 6, 2019, 9:23am
20
This would be great. I had some hope but your words give me more hope. Plugin devs will love this.
1 Like