@@ -53,44 +53,45 @@ bundle exec ruby -pi -e \
53
53
" sub(/class Event < ApplicationRecord/, \" class Event < ApplicationRecord\\ n after_create { Outboxer::Message.queue(messageable: self) }\" )" \
54
54
app/models/event.rb
55
55
56
- bundle exec rails runner ' Event.create!'
56
+ bundle exec ruby - << 'RUBY '
57
+ require_relative " config/environment"
57
58
58
- bundle exec ruby - << RUBY
59
- publisher_cmd = File .join(Dir .pwd, " bin" , " outboxer_publisher" )
60
- read_io, write_io = IO .pipe
59
+ event = Event .create!
61
60
62
- pid = spawn (" ruby" , publisher_cmd, out: write_io, err: write_io)
63
- write_io.close
61
+ env = { " RAILS_ENV" => ENV [" RAILS_ENV" ] }
62
+ publisher_cmd = File .join(Dir .pwd, " bin" , " outboxer_publisher" )
63
+ publisher_pid = spawn (env, " ruby" , publisher_cmd)
64
64
65
- output = + " "
66
65
attempt = 1
67
- max_attempts = 20
66
+ max_attempts = 10
68
67
delay = 1
69
68
70
- while attempt <= max_attempts
71
- begin
72
- partial = read_io.read_nonblock(1024 )
73
- output << partial if partial
74
- rescue IO ::WaitReadable , EOFError
75
- end
69
+ messageable_was_published = false
76
70
77
- break if output.include?( " published message " )
71
+ published_messages = Outboxer :: Message .list( status: :published )[ :messages ]
78
72
79
- sleep delay
80
- attempt += 1
73
+ messageable_was_published = published_messages.any? do |published_message |
74
+ published_message[:messageable_type ] == event.class .name &&
75
+ published_message[:messageable_id ] == event.id.to_s
81
76
end
82
77
83
- Process .kill(" TERM" , pid)
84
- Process .wait(pid)
85
- read_io.close
78
+ while (attempt <= max_attempts) && ! messageable_was_published
79
+ warn " Outboxer message not published yet. Retrying (#{ attempt } /#{ max_attempts } )..."
80
+ sleep delay
81
+ attempt += 1
86
82
87
- if output.include?( " published message " )
88
- puts " Outboxer published message found "
89
- exit 0
90
- else
91
- puts " Outboxer published message not found after #{ max_attempts } attempts "
92
- exit 1
83
+ published_messages = Outboxer :: Message .list( status: :published )[ :messages ]
84
+
85
+ messageable_was_published = published_messages.any? do | published_message |
86
+ published_message[ :messageable_type ] == event. class .name &&
87
+ published_message[ :messageable_id ] == event.id.to_s
88
+ end
93
89
end
90
+
91
+ Process .kill(" TERM" , publisher_pid)
92
+ Process .wait(publisher_pid)
93
+
94
+ exit (messageable_was_published ? 0 : 1 )
94
95
RUBY
95
96
96
97
# TARGET_RUBY_VERSION=3.2.2 TARGET_RAILS_VERSION=7.1.5.1 TARGET_DATABASE_ADAPTER=postgresql ./quickstart_e2e_tests.sh
0 commit comments