{"id":16746699,"url":"https://github.com/mkon/db_lock","last_synced_at":"2025-07-30T14:13:01.815Z","repository":{"id":19702142,"uuid":"22957148","full_name":"mkon/db_lock","owner":"mkon","description":"Obtains manual db locks.","archived":false,"fork":false,"pushed_at":"2025-07-18T08:25:55.000Z","size":141,"stargazers_count":5,"open_issues_count":1,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-27T13:50:44.213Z","etag":null,"topics":["database","hacktoberfest","mutex","ruby"],"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/mkon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"MIT-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}},"created_at":"2014-08-14T14:41:24.000Z","updated_at":"2024-08-01T04:44:29.000Z","dependencies_parsed_at":"2023-02-17T07:01:08.098Z","dependency_job_id":"311a7a39-c43b-4dca-9145-1da169cb4ef7","html_url":"https://github.com/mkon/db_lock","commit_stats":{"total_commits":85,"total_committers":12,"mean_commits":7.083333333333333,"dds":0.6823529411764706,"last_synced_commit":"785ffbad81b0f31ca06fc7710d44261049e9189b"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/mkon/db_lock","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkon%2Fdb_lock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkon%2Fdb_lock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkon%2Fdb_lock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkon%2Fdb_lock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mkon","download_url":"https://codeload.github.com/mkon/db_lock/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mkon%2Fdb_lock/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267881456,"owners_count":24159901,"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","status":"online","status_checked_at":"2025-07-30T02:00:09.044Z","response_time":70,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["database","hacktoberfest","mutex","ruby"],"created_at":"2024-10-13T02:08:09.800Z","updated_at":"2025-07-30T14:13:01.788Z","avatar_url":"https://github.com/mkon.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DBLock\n\n[![Gem Version](https://badge.fury.io/rb/db_lock.svg)](https://badge.fury.io/rb/db_lock)\n[![Tests](https://github.com/mkon/db_lock/actions/workflows/main.yml/badge.svg)](https://github.com/mkon/db_lock/actions/workflows/main.yml)\n\nGem to obtain and release manual db locks. This can be utilized for example to make sure that certain rake tasks do not run in parallel on the same database (for example when cron jobs run for too long or are accidentally started multiple times). Currently only supports:\n\n- MySQL\n- Microsoft SQL Server\n- Postgres\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n    gem 'db_lock'\n\nthen run `bundle`\n\n## Usage\n\n```ruby\nDBLock.with_lock('name_of_lock', 5) do\n  # code here\nend\n```\n\nBefore the code block is executed, it will attempt to acquire a db lock for X seconds (5 in this example). If this fails it will raise an `DBLock::AlreadyLocked` error. The lock is released after the block is executed, even if the block raised an error itself.\n\nThe locking will already fail with an error if the current thread already holds a lock via this gem.\n\nLocks are achieved on the database via:\n\n| Database  | Locking method     |\n|-----------|--------------------|\n| MySQL     | `GET_LOCK`         |\n| Postgres  | `pg_advisory_lock` |\n| SQLServer | `sp_getapplock`    |\n\n## Dynamic lock name\n\nIf you prefix the lock with a `.` in a Rails application, `.` will be automatically replaced with `YourAppName.environment` (production/development/etc).\nIf the lock name exceeds 64 characters, it will be replaced with a lock name of 64 characters, that consists of a pre- and suffix from the original lock name and a middle MD5 checksum.\n\n\n## Development\n\nBundle with the adapter you want to use, for example\n\n```bash\n$ bundle --with mysql\n```\n\nRun rspec with the database url env variables set. It will only run the specs it can run and skip the others.\n\nFor example\n```bash\n$ MYSQL_URL=mysql2://root:dummy@localhost/test SQLSERVER_URL=sqlserver://root:dummy@localhost/test rspec\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmkon%2Fdb_lock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmkon%2Fdb_lock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmkon%2Fdb_lock/lists"}