Comments (2)
@banzhihang1 can you share the implementation of ClassFactory.create_dynamic_model
? I'm imagining that its likely to be the problem here (i.e. not thread safe).
It would be most helpful if you can share a self-contained reproduction script without private/external dependencies.
from concurrent-ruby.
@bensheldon this is code
class ClassFactory
def self.create_dynamic_model(database_name, table_name, deletable=false)
new_class = self.name + database_name.camelize + table_name.singularize.camelize
if deletable
existing_classes = ActiveRecord::Base.descendants.reject(&:abstract_class).select{ |m| m.table_name == table_name && m.database_name == database_name }
if existing_classes.length == 1
include_delete_restore(existing_classes[0])
return existing_classes[0]
end
if existing_classes.length > 1
primary = find_primary_existing_class(existing_classes)
if primary.present?
include_delete_restore(primary)
return primary
end
end
end
existing_class = begin
k = Module.const_get(new_class)
if k.database_name == database_name && k.table_name == table_name
k
end
rescue NameError
nil
end
if existing_class
include_delete_restore(existing_class) if deletable
return existing_class
end
Object.const_set(new_class, Class.new(database_name == 'one_eye' ? ActiveRecord::Base : "#{database_name.camelcase}DatabaseRecord".constantize))
klass = new_class.constantize
klass.table_name = table_name
klass.inheritance_column = nil
if klass.primary_key == nil
# Rails can't handle composite PKs.
# We have to retrieve from the schema cache and explicitly set
key = klass.connection.schema_cache.primary_keys(table_name)
klass.primary_key = key
end
include_delete_restore(klass) if deletable
klass
end
private
def self.include_delete_restore(klass)
klass.include(DeleteRestore::Deletable)
klass.include(DeleteRestore::Restorable)
end
def self.find_primary_existing_class(existing_classes)
# First check to see if any have been marked as primary
primary = existing_classes.select { |c| c.instance_variable_defined?(:@primary_model_for_table) && c.instance_variable_get(:@primary_model_for_table) }
return primary[0] if primary.length == 1
# Then check to see if only one implements Deletable
deletable = existing_classes.select { |c| c < DeleteRestore::Deletable }
return deletable[0] if deletable.length == 1
# Check to see if only one override the delete_batch method
overriding = existing_classes.select { |c| c.respond_to?(:delete_batch) && c.method(:delete_batch).owner != DeleteRestore::Deletable::ClassMethods }
return overriding[0] if overriding.length == 1
# If we can't narrow it down, return nil
return nil
end
end
The code did not run in, but got stuck in an external call
from concurrent-ruby.
Related Issues (20)
- DaemonThreadFactory creating new Java thread factory each time it creates a new thread HOT 8
- `Concurrent::Promises::Future#value!` can return `nil` even when promise is not resolved yet HOT 6
- Version 1.2.2 crashes with Segmentation fault HOT 3
- Fiber.new causes SEGV when using Ruby 3.3.0 on Rails 7.1.2 in M1 Mac Docker environment HOT 5
- Segfault in lock_local_var.rb on aarch64 HOT 3
- [REDIRECT] Segfault on Ruby 3.3.0 on linux-aarch64? See https://bugs.ruby-lang.org/issues/20085
- Add new CI job with RUBY_MN_THREADS=1 HOT 4
- Add API to prestart threads in threadpools HOT 4
- Don't know how to build task 'parallel_spec' HOT 2
- Segmentation fault related to concurrent-ruby HOT 4
- Segmentation fault with Ruby 3.3.0 running with Docker HOT 1
- Add keyword arguments to async HOT 1
- ThreadPoolExecutor#shutdown? inconsistency in JRuby and C Ruby HOT 4
- test failure due to "uninitialized constant Concurrent::CAtomicReference" HOT 7
- CAtomicFixnum should probably be a private constant HOT 1
- support re-raising exceptions when shutting down a timertask HOT 4
- v1.2.0 release notes do not mention that RubyThreadLocalVar class was removed HOT 8
- NameError: uninitialized constant Concurrent::RubyThreadLocalVar HOT 1
- The Concurrent::Map default_proc is passed a Concurrent::Hash instead of the Concurrent::Map HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from concurrent-ruby.