05aa55e172
`Jobs::AutoJoinChannelBatch` was holding a lot of logic which should be in a service. Moreover, this refactoring is the opportunity to address a bug which could cause a duplicate key error. From now when trying to insert a new membership it won't fail if a membership is already present. Example error: ``` Job exception: ERROR: duplicate key value violates unique constraint "user_chat_channel_unique_memberships" DETAIL: Key (user_id, chat_channel_id)=(1, 2) already exists. Backtrace rack-mini-profiler-3.1.0/lib/patches/db/pg.rb:110:in `exec' rack-mini-profiler-3.1.0/lib/patches/db/pg.rb:110:in `async_exec' (eval):29:in `async_exec' mini_sql-1.4.0/lib/mini_sql/postgres/connection.rb:209:in `run' mini_sql-1.4.0/lib/mini_sql/active_record_postgres/connection.rb:38:in `block in run' mini_sql-1.4.0/lib/mini_sql/active_record_postgres/connection.rb:34:in `block in with_lock' activesupport-7.0.5.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt' activesupport-7.0.5.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchronize' activesupport-7.0.5.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt' activesupport-7.0.5.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize' mini_sql-1.4.0/lib/mini_sql/active_record_postgres/connection.rb:34:in `with_lock' mini_sql-1.4.0/lib/mini_sql/active_record_postgres/connection.rb:38:in `run' mini_sql-1.4.0/lib/mini_sql/postgres/connection.rb:64:in `query_single' /var/www/discourse/plugins/chat/app/jobs/regular/chat/auto_join_channel_batch.rb:38:in `execute' ``` Note this commit is also using main branch of `shoulda-matchers` as the gem has not been released yet. Co-authored-by: Loïc Guitaut <5648+Flink@users.noreply.github.com> |
||
---|---|---|
.. | ||
regular/chat | ||
scheduled/chat | ||
service_job.rb |