Hier sind fünf Dateien hinzugefügt my app (keine Datenbank, kein Setup als solche erforderlich) mit:Handhabung zirkuläre Abhängigkeit in Schienen während Fäden
lib/Aufgaben/precomputation.rake
namespace :precomputation do
desc "This fetches data for precomputation"
task fetch_all: :environment do
Precomputation.precompute_all_data
# end
end
end
app/models /precomputation.rb
class Precomputation
def self.precompute_all_data
ad_accounts = [1,2,3]
bgthread = BackgroundThread::BGThreadPool.new(1)
tasks = []
ad_accounts.each do |ad_account_id|
p = Proc.new do
begin
MongoPipeline::FbAdCampaignMongoPipeline.new(ad_account_id).fetch_all
false
ensure
GC.start
end
end
tasks << [p, "test #{ad_account_id}"]
end
bgthread.add_randomized_tasks(tasks)
bgthread.do_work
end
end
app/Modelle/mongo_pipeline.rb
module MongoPipeline
class Base
def initialize(ad_account_id)
end
def insert_data
puts 'inserting data'
end
def fetch_all
extract_data # Child Class defines this method
insert_data # Base class defines this method
end
end
end
app/models/mongo_pipeline/fb_ad_campaign_mongo_pipeline.rb
module MongoPipeline
class FbAdCampaignMongoPipeline < MongoPipeline::Base
def extract_data
puts 'here is campaign data'
end
end
end
und app/models/background_thread.rb
(HINWEIS: Alternative Implementierung parallel gem und keine Hintergrundthread mit kollabiert auch mit ähnlichen Fehler - : https://github.com/pratik60/circular_dependency_havoc/tree/parallel)
Fehlerprotokoll
rake aborted!
Circular dependency detected while autoloading constant MongoPipeline
/Users/pratikbothra/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:492:in `load_missing_constant'
/Users/pratikbothra/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:184:in `const_missing'
/Users/pratikbothra/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:526:in `load_missing_constant'
/Users/pratikbothra/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:184:in `const_missing'
/webapps/circular_dependency_havoc/app/models/precomputation.rb:9:in `block (2 levels) in precompute_all_data'
/webapps/circular_dependency_havoc/app/models/background_thread.rb:91:in `call'
/webapps/circular_dependency_havoc/app/models/background_thread.rb:91:in `block in background'
Tasks: TOP => precomputation:fetch_all
(See full trace by running task with --trace)
Irgendwelche Ideen, was ich falsch mache? Die Hintergrund-Thread-Bibliothek wurde geklont und einfach modifiziert. Fühlen Sie sich frei, es zu ersetzen, wenn Sie denken, dass das das Problem ist. Irgendwelche Vorschläge, irgendwelche Ideen sind mehr als willkommen.
Themen und automatisches Laden nicht tun gut zusammenarbeiten. Können Sie dies in der Produktionsumgebung statt in der Entwicklungsumgebung ausführen? –
@SteveJorgensen Nein, kein Glück. Gibt es noch andere Bibliotheken, die ich benutzen möchte? –