
Security News
AGENTS.md Gains Traction as an Open Format for AI Coding Agents
AGENTS.md is a fast-growing open format giving AI coding agents a shared, predictable way to understand project setup, style, and workflows.
Wouldn't be nice if you could easily queue model method calls to Sidekiq? With Sidekiq::Delay you can!
You have just to include a module and call delay
before any method call. Actually, your model class have to respond to some methods, but if you are using ActiveRecord
or Mongoid
they already do.
NOTE: It doesn't support block
arguments.
Add this line to your application's Gemfile:
gem 'sidekiq-delay'
And then execute:
$ bundle
Or install it yourself as:
$ gem install sidekiq-delay
First you have to include Sidekiq::Delay
at your model.
class Band
include Mongoid::Document
include Sidekiq::Delay
field :name
def play!
# a long task
sleep 3
end
end
Now you can delay
method calls to a Sidekiq queue.
band = Band.create(name: 'Daft Punk')
band.delay.play!
It queues an job with model class, model id, method name and args. Later, at Sidekiq, it finds your model using class and id and calls method with args. Your class must respond to find(id)
and return same model.
NOTE: Your model must be stored at database before delay
any call.
What if you class doesn't respond to find
or you want to use another Sidekiq
plugin? You can easily write an custom worker. You have just to set your model to use it with worker
method.
Your worker just need to include Sidekiq::Delay::Strategy
or extend Sidekiq::Delay::Worker
.
class TeamWorker
include Sidekiq::Worker
include Sidekiq::Delay::Strategy
def record(klass, id)
klass.custom_find(id)
end
end
class Team
include Mongoid::Document
include Sidekiq::Delay
worker TeamWorker
field :name
def self.custom_find(id)
find(id)
end
def play!
# a long task
sleep 3
end
end
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)FAQs
Unknown package
We found that sidekiq-delay demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
AGENTS.md is a fast-growing open format giving AI coding agents a shared, predictable way to understand project setup, style, and workflows.
Security News
/Research
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.