{"id":18513336,"url":"https://github.com/jbox-web/sidekiq_alive","last_synced_at":"2025-05-14T12:20:34.440Z","repository":{"id":220036665,"uuid":"726644690","full_name":"jbox-web/sidekiq_alive","owner":"jbox-web","description":null,"archived":false,"fork":false,"pushed_at":"2025-04-16T00:03:38.000Z","size":162,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-14T12:19:51.817Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/jbox-web.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-12-03T00:06:59.000Z","updated_at":"2025-04-16T00:03:41.000Z","dependencies_parsed_at":"2025-01-28T23:23:31.640Z","dependency_job_id":"e111b886-d159-4aac-9b95-6b6296bae113","html_url":"https://github.com/jbox-web/sidekiq_alive","commit_stats":null,"previous_names":["jbox-web/sidekiq_alive"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbox-web%2Fsidekiq_alive","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbox-web%2Fsidekiq_alive/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbox-web%2Fsidekiq_alive/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jbox-web%2Fsidekiq_alive/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jbox-web","download_url":"https://codeload.github.com/jbox-web/sidekiq_alive/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254140805,"owners_count":22021225,"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":[],"created_at":"2024-11-06T15:37:41.861Z","updated_at":"2025-05-14T12:20:34.420Z","avatar_url":"https://github.com/jbox-web.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SidekiqAlive\n\n[![GitHub license](https://img.shields.io/github/license/jbox-web/sidekiq_alive.svg)](https://github.com/jbox-web/sidekiq_alive/blob/master/LICENSE)\n[![GitHub release](https://img.shields.io/github/release/jbox-web/sidekiq_alive.svg)](https://github.com/jbox-web/sidekiq_alive/releases/latest)\n[![CI](https://github.com/jbox-web/sidekiq_alive/workflows/CI/badge.svg)](https://github.com/jbox-web/sidekiq_alive/actions)\n[![Code Climate](https://codeclimate.com/github/jbox-web/sidekiq_alive/badges/gpa.svg)](https://codeclimate.com/github/jbox-web/sidekiq_alive)\n[![Test Coverage](https://codeclimate.com/github/jbox-web/sidekiq_alive/badges/coverage.svg)](https://codeclimate.com/github/jbox-web/sidekiq_alive/coverage)\n\nSidekiqAlive offers a solution to add liveness probe for a Sidekiq instance deployed in Kubernetes.\nThis library can be used to check sidekiq health outside kubernetes.\n\n**How?**\n\nA http server is started and on each requests validates that a liveness key is stored in Redis. If it is there means is working.\n\nA Sidekiq worker is the responsible to storing this key. If Sidekiq stops processing workers\nthis key gets expired by Redis an consequently the http server will return a 500 error.\n\nThis worker is responsible to requeue itself for the next liveness probe.\n\nEach instance in kubernetes will be checked based on `ENV` variable `HOSTNAME` (kubernetes sets this for each replica/pod).\n\nOn initialization SidekiqAlive will asign to Sidekiq::Worker a queue with the current host and add this queue to the current instance queues to process.\n\nexample:\n\n```\nhostname: foo\n  Worker queue: sidekiq_alive-foo\n  instance queues:\n   - sidekiq_alive-foo\n   *- your queues\n\nhostname: bar\n  Worker queue: sidekiq_alive-bar\n  instance queues:\n   - sidekiq_alive-bar\n   *- your queues\n```\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'sidekiq_alive'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install sidekiq_alive\n\n## Usage\n\nSidekiqAlive will start when running `sidekiq` command.\n\nRun `Sidekiq`\n\n```\nbundle exec sidekiq\n```\n\n```\ncurl localhost:7433\n#=\u003e Alive!\n```\n\n**how to disable?**\nYou can disabled by setting `ENV` variable `DISABLE_SIDEKIQ_ALIVE`\nexample:\n\n```\nDISABLE_SIDEKIQ_ALIVE=true bundle exec sidekiq\n```\n\n### Kubernetes setup\n\nSet `livenessProbe` in your Kubernetes deployment\n\nexample with recommended setup:\n\n#### Sidekiq \u003c 6\n\n```yaml\nspec:\n  containers:\n    - name: my_app\n      image: my_app:latest\n      env:\n        - name: RAILS_ENV\n          value: production\n      command:\n        - bundle\n        - exec\n        - sidekiq\n      ports:\n        - containerPort: 7433\n      livenessProbe:\n        httpGet:\n          path: /\n          port: 7433\n        initialDelaySeconds: 80 # app specific. Time your sidekiq takes to start processing.\n        timeoutSeconds: 5 # can be much less\n      readinessProbe:\n        httpGet:\n          path: /\n          port: 7433\n        initialDelaySeconds: 80 # app specific\n        timeoutSeconds: 5 # can be much less\n      lifecycle:\n        preStop:\n          exec:\n            # SIGTERM triggers a quick exit; gracefully terminate instead\n            command: ['bundle', 'exec', 'sidekiqctl', 'quiet']\n  terminationGracePeriodSeconds: 60 # put your longest Job time here plus security time.\n```\n\n#### Sidekiq \u003e= 6\n\nCreate file:\n\n_kube/sidekiq_quiet_\n\n```bash\n#!/bin/bash\n\n# Find Pid\nSIDEKIQ_PID=$(ps aux | grep sidekiq | grep busy | awk '{ print $2 }')\n# Send TSTP signal\nkill -SIGTSTP $SIDEKIQ_PID\n```\n\nMake it executable:\n\n```\n$ chmod +x kube/sidekiq_quiet\n```\n\nExecute it in your deployment preStop:\n\n```yaml\nspec:\n  containers:\n    - name: my_app\n      image: my_app:latest\n      env:\n        - name: RAILS_ENV\n          value: production\n      command:\n        - bundle\n        - exec\n        - sidekiq\n      ports:\n        - containerPort: 7433\n      livenessProbe:\n        httpGet:\n          path: /\n          port: 7433\n        initialDelaySeconds: 80 # app specific. Time your sidekiq takes to start processing.\n        timeoutSeconds: 5 # can be much less\n      readinessProbe:\n        httpGet:\n          path: /\n          port: 7433\n        initialDelaySeconds: 80 # app specific\n        timeoutSeconds: 5 # can be much less\n      lifecycle:\n        preStop:\n          exec:\n            # SIGTERM triggers a quick exit; gracefully terminate instead\n            command: ['kube/sidekiq_quiet']\n  terminationGracePeriodSeconds: 60 # put your longest Job time here plus security time.\n```\n\n### Outside kubernetes\n\nIt's just up to you how you want to use it.\n\nAn example in local would be:\n\n```\nbundle exec sidekiq\n# let it initialize ...\n```\n\n```\ncurl localhost:7433\n#=\u003e Alive!\n```\n\n## Options\n\n```ruby\nSidekiqAlive.setup do |config|\n  # ==\u003e Server host\n  # Host to bind the server.\n  # Can also be set with the environment variable SIDEKIQ_ALIVE_HOST.\n  # default: 0.0.0.0\n  #\n  #   config.host = 0.0.0.0\n\n  # ==\u003e Server port\n  # Port to bind the server.\n  # Can also be set with the environment variable SIDEKIQ_ALIVE_PORT.\n  # default: 7433\n  #\n  #   config.port = 7433\n\n  # ==\u003e Server path\n  # HTTP path to respond to.\n  # Can also be set with the environment variable SIDEKIQ_ALIVE_PATH.\n  # default: '/'\n  #\n  #   config.path = '/'\n\n  # ==\u003e Custom Liveness Probe\n  # Extra check to decide if restart the pod or not for example connection to DB.\n  # `false`, `nil` or `raise` will not write the liveness probe\n  # default: proc { true }\n  #\n  #     config.custom_liveness_probe = proc { db_running? }\n\n  # ==\u003e Liveness key\n  # Key to be stored in Redis as probe of liveness\n  # default: \"SIDEKIQ::LIVENESS_PROBE_TIMESTAMP\"\n  #\n  #   config.liveness_key = \"SIDEKIQ::LIVENESS_PROBE_TIMESTAMP\"\n\n  # ==\u003e Time to live\n  # Time for the key to be kept by Redis.\n  # Here is where you can set de periodicity that the Sidekiq has to probe it is working\n  # Time unit: seconds\n  # default: 10 * 60 # 10 minutes\n  #\n  #   config.time_to_live = 10 * 60\n\n  # ==\u003e Callback\n  # After the key is stored in redis you can perform anything.\n  # For example a webhook or email to notify the team\n  # default: proc {}\n  #\n  #    require 'net/http'\n  #    config.callback = proc { Net::HTTP.get(\"https://status.com/ping\") }\n\n  # ==\u003e Shutdown callback\n  # When sidekiq process is shutting down, you can perform some action, like cleaning up created queue\n  # default: proc {}\n  #\n  #    config.shutdown_callback = proc do\n  #      Sidekiq::Queue.all.find { |q| q.name == \"#{config.queue_prefix}-#{SidekiqAlive.hostname}\" }\u0026.clear\n  #    end\n\n  # ==\u003e Queue Prefix\n  # SidekiqAlive will run in a independent queue for each instance/replica\n  # This queue name will be generated with: \"#{queue_prefix}-#{hostname}.\n  # You can customize the prefix here.\n  # default: :sidekiq-alive\n  #\n  #    config.queue_prefix = :other\n\n  # ==\u003e Rack server\n  # Web server used to serve an HTTP response.\n  # Can also be set with the environment variable SIDEKIQ_ALIVE_SERVER.\n  # default: 'webrick'\n  #\n  #    config.server = 'puma'\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`.\n\nHere is an example [rails app](https://github.com/arturictus/sidekiq_alive_example)\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/arturictus/sidekiq_alive. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjbox-web%2Fsidekiq_alive","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjbox-web%2Fsidekiq_alive","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjbox-web%2Fsidekiq_alive/lists"}