{"id":15527234,"url":"https://github.com/zorbash/sidekiq-dry","last_synced_at":"2025-04-23T12:16:14.937Z","repository":{"id":37899857,"uuid":"328242764","full_name":"zorbash/sidekiq-dry","owner":"zorbash","description":"Serialization and deserialization of Dry::Struct arguments for Sidekiq jobs","archived":false,"fork":false,"pushed_at":"2022-06-14T17:50:45.000Z","size":43,"stargazers_count":11,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-23T12:15:51.317Z","etag":null,"topics":["dry-rb","queues","rails","sidekiq"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zorbash.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-01-09T20:43:45.000Z","updated_at":"2024-07-15T12:29:23.000Z","dependencies_parsed_at":"2022-09-01T20:02:23.362Z","dependency_job_id":null,"html_url":"https://github.com/zorbash/sidekiq-dry","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zorbash%2Fsidekiq-dry","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zorbash%2Fsidekiq-dry/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zorbash%2Fsidekiq-dry/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zorbash%2Fsidekiq-dry/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zorbash","download_url":"https://codeload.github.com/zorbash/sidekiq-dry/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250430599,"owners_count":21429324,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dry-rb","queues","rails","sidekiq"],"created_at":"2024-10-02T11:05:09.184Z","updated_at":"2025-04-23T12:16:14.906Z","avatar_url":"https://github.com/zorbash.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Sidekiq::Dry\n\n[![Gem version](https://badge.fury.io/rb/sidekiq-dry.png)](http://badge.fury.io/rb/sidekiq-dry)\n[![Build Status](https://travis-ci.org/zorbash/sidekiq-dry.svg?branch=master)](https://travis-ci.org/zorbash/sidekiq-dry)\n\nGem to provide serialization and deserialization of [Dry::Struct][dry-struct]\narguments for [Sidekiq][sidekiq] jobs.\n\nRead more about this gem [here](https://zorbash.com/post/sidekiq-dry/).\n\n## Rationale\n\n**Argument Validation**\n\nBy using `Dry::Struct` arguments you can choose to validate some attributes and mark\nany of them as optional. An attempt to enqueue a job with invalid arguments will raise,\nminimizing resource waste from jobs which would otherwise be retried multiple times without any chance of completing successfully.\n\nExample:\n\n```ruby\nclass Coupons::ApplyCouponJob::Params \u003c Dry::Struct\n  attribute :user_id,     Types::Strict::Integer\n  attribute :coupon_code, Types::Strict::String\nend\n\njob_params = Coupons::ApplyCouponJob::Params.new(user_id: user.id, coupon_code: coupon.code)\n\nUsers::SendConfirmationEmailJob.perform_async(job_params)\n```\n\n**Documentation**\n\nInstead of documenting the types of each job argument, which can easily become outdated, you can refer to the types of the attributes of the struct.\n\n**Positional Arguments are Error Prone**\n\nYou won't ever have to remember the order of arguments of a job.\n\n**Versioning**\n\nAdding this gem does not break any existing jobs in your app.\nIt only works on jobs enqueued with `Dry::Struct` objects.\n\nAdding a new attribute to a parameter struct won't break already enqueued jobs.\n\nIt's trivial to version your structs using either a `version` attribute:\n\n```ruby\nclass Coupons::ApplyCouponJob::Params \u003c Dry::Struct\n  attribute :user_id,     Types::Strict::Integer\n  attribute :coupon_code, Types::Strict::String\n  attribute :version,     Types::Strict::String.default('1')\nend\n```\n\nor versioned classes:\n\n```ruby\nclass Coupons::ApplyCouponJob::Params::V1 \u003c Dry::Struct\n  attribute :user_id,     Types::Strict::Integer\n  attribute :coupon_code, Types::Strict::String\nend\n```\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'sidekiq-dry'\n```\n\nAnd then execute:\n\n    $ bundle install\n\nConfigure Sidekiq to use the middlewares provided by this gem:\n\n```ruby\n# File: config/initializers/sidekiq.rb\nSidekiq.configure_client do |config|\n  config.client_middleware do |chain|\n    chain.prepend Sidekiq::Dry::Client::SerializationMiddleware\n  end\nend\n\nSidekiq.configure_server do |config|\n  # Ensure jobs enqueued by other jobs serialize their structs\n  config.client_middleware do |chain|\n    chain.prepend Sidekiq::Dry::Client::SerializationMiddleware\n  end\n\n  config.server_middleware do |chain|\n    chain.add Sidekiq::Dry::Server::DeserializationMiddleware\n  end\nend\n```\n\nSee [Middleware usage](sidekiq-middlewares) on the Sidekiq wiki for more info.\n\n## Usage\n\n**Enqueuing Jobs**\n\n```ruby\nclass Users::SendConfirmationEmailJob::Params \u003c Dry::Struct\n  attribute :email, Types::Strict::String\nend\n\njob_params = Users::SendConfirmationEmailJob::Params.new(email: user.email)\n\nUsers::SendConfirmationEmailJob.perform_async(job_params)\n```\n\n**Authoring Jobs**\n\n```ruby\nclass Users::SendConfirmationEmailJob\n  include Sidekiq::Worker\n\n  def perform(params)\n    # params is an instance of Users::SendConfirmationEmailJob::Params\n    mail(to: params.email, subject: 'Welcome!')\n  end\nend\n```\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/zorbash/sidekiq-dry. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/zorbash/sidekiq-dry/blob/master/CODE_OF_CONDUCT.md).\n\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the Sidekiq::Dry project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/zorbash/sidekiq-dry/blob/master/CODE_OF_CONDUCT.md).\n\n[dry-struct]: https://dry-rb.org/gems/dry-struct/1.0/\n[sidekiq]: https://sidekiq.org/\n[sidekiq-middlewares]: https://github.com/mperham/sidekiq/wiki/Middleware\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzorbash%2Fsidekiq-dry","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzorbash%2Fsidekiq-dry","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzorbash%2Fsidekiq-dry/lists"}