Skip to content

ActiveJobExtensions clobbers Sidekiq tenancy #328

@atcruice

Description

@atcruice

We recently encountered some difficulty trying to update to v1. The cause is an undesirable interaction between ActsAsTenant::Sidekiq::Server and the new ActsAsTenant::ActiveJobExtensions (introduced in #319) - due to their different tenancy control approaches:

Context

  • Ruby 3.1.4
  • Rails 7.1.2
  • Sidekiq Pro 7.2.0
  • codebase has both ActiveJob and Sidekiq::Job derived jobs

We use a rolling deploy strategy, so have both old and new code in active use for a period during release. The exceptions we encountered were due to:

  1. old code enqueuing jobs without passing through the new ActsAsTenant::ActiveJobExtensions#serialize (missing the "current_tenant" key)
  2. old code ActsAsTenant::Sidekiq::Client#call saving job tenancy in "acts_as_tenant" hash
  3. new code ActsAsTenant::Sidekiq::Server#call setting job tenancy from "acts_as_tenant" hash
  4. new code ActsAsTenant::ActiveJobExtensions#deserialize then nullifying ActsAsTenant.current_tenant because the "current_tenant" key was absent (clobbering the existing tenancy context)

Proposed Solution

I'd like to work on refactoring ActsAsTenant::ActiveJobExtensions#deserialize such that:

  1. it was similarly opportunistic
    • this would resolve issues during the crossover period
  2. perhaps short-circuit if ActsAsTenant.current_tenant is already set

Do these sound like reasonable improvements?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions