{"id":23162748,"url":"https://github.com/darrhiggs/sidekiq-trackable_batch","last_synced_at":"2025-08-25T00:32:25.780Z","repository":{"id":56895572,"uuid":"96461106","full_name":"darrhiggs/sidekiq-trackable_batch","owner":"darrhiggs","description":"Access detailed, up-to-date information about a Sidekiq::Batch as it runs","archived":false,"fork":false,"pushed_at":"2017-07-06T18:38:00.000Z","size":26,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-17T19:51:46.298Z","etag":null,"topics":["batch","rails","ruby","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/darrhiggs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-07-06T18:37:19.000Z","updated_at":"2023-03-26T18:11:37.000Z","dependencies_parsed_at":"2022-08-20T17:10:20.021Z","dependency_job_id":null,"html_url":"https://github.com/darrhiggs/sidekiq-trackable_batch","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darrhiggs%2Fsidekiq-trackable_batch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darrhiggs%2Fsidekiq-trackable_batch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darrhiggs%2Fsidekiq-trackable_batch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darrhiggs%2Fsidekiq-trackable_batch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/darrhiggs","download_url":"https://codeload.github.com/darrhiggs/sidekiq-trackable_batch/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230852567,"owners_count":18290084,"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":["batch","rails","ruby","sidekiq"],"created_at":"2024-12-18T00:13:20.724Z","updated_at":"2024-12-22T16:17:18.845Z","avatar_url":"https://github.com/darrhiggs.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Sidekiq::TrackableBatch\n\n`Sidekiq::TrackableBatch` is an extension to `Sidekiq::Batch` that provides access to detailed, up-to-date progress information about a `Sidekiq::Batch` as it runs.\n\n## Installation\n\nAdd the following to your application's Gemfile:\n\n```ruby\ngem 'sidekiq-trackable_batch'\n#\tand either\ngem 'sidekiq-pro'\n#\tor\ngem 'sidekiq-batch' # currently unsupported\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install sidekiq-trackable_batch\n\n## Usage\n\nAdd a `.max` to existing workers:\n```ruby\nclass MyWorker\n  def self.max; 42; end # some (total) amount of work\nend\n```\n\nUpdate the class' `#perform` method to use `#update_status`:\n```ruby\ndef perform(*args)\n  # do some work\n  update_status(value: 21) # made available through Sidekiq::Worker\n  # maybe do some more work\n  update_status(value: self.class.max, status_text: 'Done')\nend\n```\n\nCreate a batch using `Sidekiq::TrackableBatch`:\n```ruby\ntrackable_batch = Sidekiq::TrackableBatch.new\n#  set callbacks \u0026 description etc as required\ntrackable_batch.jobs\n  5.times { MyWorker.perform_async }\nend\n```\n\nTrack your batch:\n```ruby\nSidekiq::TrackableBatch::Tracking(trackable_batch).to_h\n# =\u003e { max: 210, value: 105 }\n```\n\nAll `Sidekiq::Batch` features should continue to work as before:\n```ruby\nSidekiq::Batch::Status.new(trackable_batch.bid)\ntrackable_batch.invalidate_all\n# …\n```\n\n### Really Complex Workflows with Batches\n\n`Sidekiq::TrackableBatch` is constrained by all jobs having to be exposed to the batch during initialization. To fulfil this constraint, an updated DSL has been provided to allow nested batch creation that requires ordered execution:\n```ruby\ntrackable_batch = Sidekiq::TrackableBatch.new do # Pass a block\n  # The :update callback has the same API as existing\n  # Sidekiq::Batch callbacks \n  on(:update, OrderStatusNotifier, order_id: order.id)\n  \n  # updates can be pushed to another queue other than the default\n  self.update_queue = 'priority'\n\n  # The DSL consists of three (aliased) chainable methods:\n  # #start_with, #then and #finally. As with a callback, a target\n  # can be passed (#on_update is called by default). \n  # A block can be passed for inline declaration.\n  start_with('pick', 'Fulfilment#pick', products: order.products)\n  .then('pack', 'Fulfilment#pack', boxes: order.boxes)\n  .finally('ship', 'Fulfilment#ship', boxes: order.boxes)\n  # The first argument will be set as the batch's description.\n  \n  # Optionally set an initial state\n  initial_status(status_text: 'Order sent for picking')\n  \n   # Sidekiq::Batch methods are also available \n   on(:complete, 'Fulfilment#fulfilment_complete', order_id: order.id)\nend\n```\nAll commands, their arguments and return values are documented, and available on [rdoc.info][docs] \n\n## DEMO\n\nCheck out the [demo app][da] ([source][dar]) to see how the [Really Complex Workflows with Batches][rcwwb] example would be created in a Rails 5 app using `Sidekiq::TrackableBatch`. The app specifically demonstrates how batch updates can be consumed through the use of the new `:update` callback, and uses ActionCable to asynchronously stream these updates to a client.\n\n## Caveats\n- ActiveJob is unsupported. [(wiki)][saj#c]\n- #update_status only accepts strings to be set for anything except the value.\n\n## TODOS\n- Integrate with sidekiq UI.\n- Provide mountable rack middleware à la Sidekiq Pro.\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec appraisal rake` 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/[USERNAME]/sidekiq-trackable_batch.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n\n[da]: https://sidekiq-trackable-batch-demo.herokuapp.com/\n[dar]: https://github.com/darrhiggs/sidekiq_trackable_batch_demo_app\n[docs]: TODO\n[rcwwb]: https://github.com/mperham/sidekiq/wiki/Really-Complex-Workflows-with-Batches\n[saj#c]: https://github.com/mperham/sidekiq/wiki/Active-Job#commercial-features\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdarrhiggs%2Fsidekiq-trackable_batch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdarrhiggs%2Fsidekiq-trackable_batch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdarrhiggs%2Fsidekiq-trackable_batch/lists"}