dry-transaction and wondering how one might facilitate long running tasks: eg.
step :preprocess_params enqueue :generate_report # long running, handled by exector/threadpool or sidekiq step :extract_and_parse_report_output step :persist_to_storage step :email_user_notification
I like the idea that the transaction encapsulates and clearly declares the end to end steps, but I can't think of a clean way to handle the async or long running task.
I could wrap the whole transaction call in a thread/threadpool....
what's the best practice around this?
Clientclass defined my the file
lib/api/clientis inside a module called
I’m having trouble getting dry-system to work, and I think I’m missing something obvious, but even after reading the docs and test cases I don’t know what it is. In
system/container.rb I have:
require 'dry/system/container' class Application < Dry::System::Container configure do |config| config.root = Pathname('.') config.auto_register = 'domain' config.auto_register = 'use_cases' end load_paths!('lib', 'use_cases') end Application.finalize! p Application['bot_reply']
system.import.rb I have:
require 'system/container' Import = Application.injector
lib/bot_reply.rb I have:
require 'dry-struct' require 'import' class BotReply < Dry::Struct # stuff end
If I execute
system/container.rb as a test, I get the error:
Nothing registered with the key "bot_reply" (Dry::Container::Error)
What am I missing?
lib/bot_reply.rbto be registered
auto_registerconfig (it can be an array)
config.auto_register = “lib”
Application.keysto see what it has
require 'dry/system/container' class Application < Dry::System::Container configure do |config| config.root = Pathname('.') config.auto_register = 'domain' # config.auto_register = 'use_cases' end load_paths!('domain') end Application.finalize! p Application.keys # => 
@timriley, if I test by running an
app.rb from the project root (ie, the dir containing
domain), which looks like this:
require_relative 'system/container' p Application.keys puts Application.config.root.realpath
I get the error:
require_component': could not resolve require file for bot_dialogue (Dry::System::FileNotFoundError)
bot_dialogue.rb is the alphabetically first file in the
domain directory, so this is some progress. It looks like this:
require 'import' class BotDialogue #stuff end
It errors before it gets to the line
puts Application.config.root.realpath in
app.rb so I can’t answer your other question.
require 'dry/system/container' class Application < Dry::System::Container configure do |config| config.root = Pathname(File.dirname(__FILE__)).parent config.auto_register = ['domain', 'lib', 'use_cases'] end load_paths!('domain', 'lib', 'use_cases') end Application.finalize!
to ground that question a bit, consider the example from the docs:
Let’s say that
logger had been auto-registered. How would you specify the
$stdout when creating it? Or some object may need to configure it with a different output, at runtime. So I want the
Logger class itself, so I can call
Logger.new(<whatever i want>) myself.
Hi ! :)
I try to use
around in Dry-Transaction but I have troubles :s
This is my code:
class Containers::Transaction extend ::Dry::Container::Mixin register(:transaction) do |input, &block| puts "Before" ActiveRecord::Base.transaction do next block.(Failure(input)) end puts "After" end end
class User::Invitation::Send include Dry::Transaction(container: Containers::Transaction) around :transaction tee :model! step :persist! tee :mailer! step :email! . . . end
And this give me
NoMethodError: undefined method `Failure' for Containers::Transaction:Class
Did you mean? fail
from /home/necros/.rvm/gems/ruby-2.3.6/gems/dry-configurable-0.7.0/lib/dry/configurable.rb:177:in `method_missing'
This happen with Success too.
Thanks for your help !