{"id":19055769,"url":"https://github.com/taskrabbit/tresque","last_synced_at":"2026-05-11T14:30:21.657Z","repository":{"id":66227810,"uuid":"84372093","full_name":"taskrabbit/tresque","owner":"taskrabbit","description":"Patterns for Resque usage at TaskRabbit","archived":false,"fork":false,"pushed_at":"2017-04-07T16:22:01.000Z","size":14,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-01-02T11:27:11.387Z","etag":null,"topics":[],"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/taskrabbit.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,"publiccode":null,"codemeta":null}},"created_at":"2017-03-08T22:27:36.000Z","updated_at":"2018-04-23T21:36:58.000Z","dependencies_parsed_at":"2023-04-15T04:18:54.904Z","dependency_job_id":null,"html_url":"https://github.com/taskrabbit/tresque","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taskrabbit%2Ftresque","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taskrabbit%2Ftresque/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taskrabbit%2Ftresque/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taskrabbit%2Ftresque/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/taskrabbit","download_url":"https://codeload.github.com/taskrabbit/tresque/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240111983,"owners_count":19749572,"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-08T23:46:57.895Z","updated_at":"2026-05-11T14:30:21.513Z","avatar_url":"https://github.com/taskrabbit.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TResque\n\nPatterns for Resque usage at TaskRabbit\n\n* So work in instance method `work` instead of class method `perform`\n* Enqueue hash instead of struct for more flexibility and change management\n* Locking based on queue or timing\n* Easy way to delay method calls\n* Method for registering queue names to centralize ops\n* Abstraction so we can move to Sidekiq even easier when that is the goal\n\n## Worker\n\n```ruby\nrequire 'tresque'\n\nmodule MyEngine\n  class ImageProcessor\n    include ::TResque::Worker\n\n    inputs :user_id, :size\n\n    def work\n      User.find(user_id).upload_image!(size)\n    end\n  end\nend\n```\n\n#### Example Usage\n\n```ruby\n  MyEngine::ImageProcessor.enqueue(size: \"small\", user_id: 255)\n```\n\n## Queue Management\n\nSay what queues you process\n\n```ruby\nrequire 'tresque'\n\nTResque.register(\"account\") do\n  queue :default, 100\n  queue :refresh, -5000\nend\n```\n\nCan put workers in those queues\n\n```\nmodule Account\n  class RegularWorker\n    include ::TResque::Worker\n    # defaults to account_default queue\n  end\nend\n\nmodule Account\n  class RegularWorker\n    include ::TResque::Worker\n    queue :refresh # lower priority account_refresh queue\n  end\nend\n```\n\n#### Rake setup\n\n```ruby\nrequire 'resque/tasks'\nrequire 'resque_scheduler/tasks'\nrequire \"resque_bus/tasks\"\n\nnamespace :resque do\n  task :setup =\u003e [:environment] do\n    require 'resque_scheduler'\n    require 'resque/scheduler'\n    require 'tresque'\n  end\n  \n  task :queues =\u003e [:setup] do\n    queues = ::TResque::Registry.queues\n    ENV[\"QUEUES\"] = queues.join(\",\")\n    puts \"TResque: #{ENV[\"QUEUES\"]}\"\n  end\nend\n\n```\n\nWork those queues by priority\n```\n  $ bundle exec rake resque:queues resque:work\n  TResque: account_default, account_refresh\n```\n\n## Locking\n\n```ruby\nmodule MyEngine\n  class SingletonWorker\n    include ::TResque::Worker\n    inputs :user_id\n\n    # does not enqueue another worker if this worker with same user_id waiting to be processed\n    queue_lock :user_id\n  end\nend\n\nmodule MyEngine\n  class MutexWorker\n    include ::TResque::Worker\n    inputs :user_id, :any_other_input\n\n    # does work two of these workers at the same time for the same user_id\n    worker_lock :user_id\n  end\nend\n```\n\nThose locks are for the same worker. You can also coordinate across workers using a namespace. Or, in other words, the default namespace is the worker class name but can be overridden. The keys need the same name.\n\n```ruby\nmodule MyEngine\n  class FirstWorker\n    include ::TResque::Worker\n    inputs :user_id\n\n    lock_namespace :user_calculations\n    worker_lock :user_id\n  end\n\n  class SecondWorker\n    include ::TResque::Worker\n    inputs :user_id, :other_input\n\n    lock_namespace :user_calculations\n    worker_lock :user_id\n  end\n\n  class ThirdWorker\n    include ::TResque::Worker\n    inputs :other_key\n\n    lock_namespace :user_calculations\n    worker_lock :user_id\n\n    def user_id\n      # can be a method too\n      User.find_by_other_key(other_key).id\n    end\n  end\nend\n```\n\n## Delay\n\n```ruby\n  class User \u003c ::ActiveRecord::Base\n    include ::TResque::Delay\n\n    def heavy_lifting\n      # stuff in background\n    end\n    async :heavy_lifting, queue: 'my_queue'\n\n    def other_stuff\n\n    end\n  end\n```\n#### Example Usage\n\n```ruby\n  user = User.find(1)\n\n  # Always in the background\n  user.heavy_lifting\n\n  # optionally in the background\n  user.delay.other_stuff\n```\n\n## Notes\n\nGenerally based on [qe](https://github.com/fnando/qe).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftaskrabbit%2Ftresque","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftaskrabbit%2Ftresque","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftaskrabbit%2Ftresque/lists"}