sidekiq | Simple , efficient background processing for Ruby | Job Scheduling library
kandi X-RAY | sidekiq Summary
kandi X-RAY | sidekiq Summary
Simple, efficient background processing for Ruby
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Parse command line options
- Processes a workitem .
- Recursively attempt to retry the exception .
- Retrieve a list of items from the cache .
- Fetch stats from redis cache
- Parses the command line options .
- Shut down workers .
- Removes a job with the given name .
- Dispatch to the given job .
- Execute a job
sidekiq Key Features
sidekiq Examples and Code Snippets
Community Discussions
Trending Discussions on sidekiq
QUESTION
I'm running:
- ruby 3.1.1
- Rails 7.0.2.3
- Sidekiq 6.4.1
I was upgrading from earlier versions of the bunch and I have this line of code in initializers/sidekiq.rb
...ANSWER
Answered 2022-Mar-24 at 03:23Starting in Sidekiq version 5, they disabled the delayed extensions by default, with their reasoning documented here. Due to their flexibility, they were prone to misuse.If all you were using the delayed extensions for was to run a job in the future, there are two replacements you can use.
Sidekiq's way to handle this is called Scheduled Jobs, which looks a bit like SomeSidekiqWorker.perform_in(3.hours, 'argument 1', 'argument 2')
, or if you have a specific time you'd like the job to execute, perform_at
.
This functionality is also now built into ActiveJob (Rails guide, API documentation), and looks like SomeJob.set(wait: 3.hours).perform_later('argument 1', 'argument 2')
.
The simplest option with a standard rails mailer would be something like these, which use the ActiveJob mechanism under the hood (API Documentation).
QUESTION
So right now we are trying to get a Bitnami Redis Sentinel cluster working, together with our Rails app + Sidekiq.
We tried different things, but it's not really clear to us, how we should specify the sentinels for Sidekiq (crutial part is here, that the sentinel nodes are READ ONLY, so we cannot use them for sidekiq, since job states get written).
Since on Kubernetes there are only 2 services available: "redis" and "redis-headless" (not sure how they differ?) - how can I specify the sentinels like this:
...ANSWER
Answered 2022-Mar-08 at 20:51Let's get started by clarifying the difference between a Headless Service and a Service.
A Service allows one to connect to one Pod, while a headless Service returns the list of available IP addresses from all the available pods, allowing to auto-discover.
A better detailed explanation by Marco Luksa has been published on SO here:
Each connection to the service is forwarded to one randomly selected backing pod. But what if the client needs to connect to all of those pods? What if the backing pods themselves need to each connect to all the other backing pods. Connecting through the service clearly isn’t the way to do this. What is?
For a client to connect to all pods, it needs to figure out the the IP of each individual pod. One option is to have the client call the Kubernetes API server and get the list of pods and their IP addresses through an API call, but because you should always strive to keep your apps Kubernetes-agnostic, using the API server isn’t ideal
Luckily, Kubernetes allows clients to discover pod IPs through DNS lookups. Usually, when you perform a DNS lookup for a service, the DNS server returns a single IP — the service’s cluster IP. But if you tell Kubernetes you don’t need a cluster IP for your service (you do this by setting the clusterIP field to None in the service specification ), the DNS server will return the pod IPs instead of the single service IP. Instead of returning a single DNS A record, the DNS server will return multiple A records for the service, each pointing to the IP of an individual pod backing the service at that moment. Clients can therefore do a simple DNS A record lookup and get the IPs of all the pods that are part of the service. The client can then use that information to connect to one, many, or all of them.
Setting the clusterIP field in a service spec to None makes the service headless, as Kubernetes won’t assign it a cluster IP through which clients could connect to the pods backing it.
"Kubernetes in Action" by Marco Luksa
How to specify the sentinelsAs the Redis documentation say:
When using the Sentinel support you need to specify a list of sentinels to connect to. The list does not need to enumerate all your Sentinel instances, but a few so that if one is down the client will try the next one. The client is able to remember the last Sentinel that was able to reply correctly and will use it for the next requests.
So the idea is to give what you have, and if you scale up the redis pods, then you don't need to re-configure Sidekiq (or Rails if you're using Redis for caching).
Combining all togetherNow you just need a way to fetch the IP addresses from the headless service in Ruby, and configure Redis client sentinels.
Fortunately, since Ruby 2.5.0, the Resolv class is available and can do that for you.
QUESTION
I have this regex:
...ANSWER
Answered 2022-Feb-21 at 17:07Built-in character classes are more table-driven.
Given that, Negative built-in ones like \W
, \S
etc...
are difficult for engines to merge into a positive character class.
In this case, there are some obvious bugs because as you've said, it doesn't time out on
some target strings.
In fact, [a-xzA-XZ\W]
works given the sample string. It times out when Y
is included anywhere
but just for that particular string.
Let's see if we can determine if this is a bug or not.
First, some tests:
Test - Fail [a-zA-Z\W]
QUESTION
I'm using sidekiq to run background jobs in ROR application. Recently redis gem version got updated to 4.6.0 (automatically as sidekiq dependency), but its producing some multi pipeline commands warning continuously as sidekiq logs flooded with these logs and its difficult to track Worker logs. Please let me know how can i remove these warnings?
Sidekiq logs:
...ANSWER
Answered 2022-Feb-04 at 18:56Here is the reason for that:
That’s from the Redis gem. 6.4.1 will be released Monday and fix it. Downgrade that gem or use Sidekiq’s main branch if you want an immediate fix.
https://github.com/mperham/sidekiq/issues/5178#issuecomment-1029545859
QUESTION
I am trying to send email using sidekiq
but it's not working. Here is how i setup sidekiq
with ActiveJob
Gemfile
...ANSWER
Answered 2022-Jan-13 at 15:53You need to tell sidekiq which queues to process. By default, some frameworks have their own queue names.
Create a sidekiq configuration file (e. g. config/sidekiq.yml
) and define the queues that it should use
QUESTION
I am using Sorcery Gem
to Authenticate user in my Rails application. Everything is working fine. When user register then I am able to send user activation email. However sending email is taking long time so I was thinking to delay the email or send email in backgroud using Sidekiq
. I read Sorcery documentation but couldn't find the way to delay the email using Sidekiq.
Please guide me how to delay the email send by Sorcery gem using Sidekiq.
...ANSWER
Answered 2022-Jan-12 at 14:48There could be two approach to this:
- Call Sidekiq worker inside Mailer
QUESTION
I have been implementing horizontal database sharding in Rails 6.1 using the new native multiple database connection switching. This has worked great in general, but I am trying to find the best way ensure that background jobs (via Sidekiq backed by a shared Redis DB) are run against the same database shard that they were initiated from.
e.g I have two horizontal database shards, Database A and Database B. The job is enqueued from a web process while connected to database A (using a Rack middleware). When that job is run later in the Sidekiq process, I would like the job to be automatically run against Database A.
A brute-force way to do this would be to pass the current connected database as an argument into every job, and then, in each job, connect to the database specified in the argument using the functionality at https://guides.rubyonrails.org/active_record_multiple_databases.html.
If I was using an older solution to horizontal sharding like Apartment, the https://github.com/influitive/apartment-sidekiq gem would be exactly what I needed. However I cannot find any solutions on how to do something similar with Rails's new native functionality.
What is the best way to accomplish this?
...ANSWER
Answered 2021-Dec-20 at 21:17You want to save the current shard using a client middleware and restore it in a server middleware. See the notes about ActiveSupport::CurrentAttributes and the Middleware wiki page.
QUESTION
I have to check if the same job has already been added to the queue before enqueue again.
Currently I use this code but it's very inefficient because it loads all object into memory. Is there a way to query like a normal active record?
Ideally, I would something like
...ANSWER
Answered 2021-Oct-18 at 15:42There is no out-of-the-box solution, but there is a simpler way to determine if a job's been already queued (true
/false
):
QUESTION
I am perplexed about the error in my docker-compose config. I am adding redis alongside sidekiq to the existing rails app that uses docker-compose but I am failing hard on attempts to make the containers communicate with each other. I have tried several different options and looked at pretty much every reasonable topic on SO that touches this subject but I keep failing on basically the same thing. Here is my current config (or at least the relevant parts of it) and error:
docker-compose.yml ...ANSWER
Answered 2021-Oct-13 at 20:17You are probably not exposing redis port to the sidekiq service try exposing this in docker compose. This probably may work.
QUESTION
I have an issue with a Sidekiq (6.2.1) and Redis (4.4.0) running with docker-compose. I found nothing useful on internet, Redis is up and running, it also seems that Sidekiq can connect but then, Sidekiq exits at start because of some kind of concurrency:
...ANSWER
Answered 2021-Oct-05 at 08:27After rebooting my computer, it now works...
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install sidekiq
On a UNIX-like operating system, using your system’s package manager is easiest. However, the packaged Ruby version may not be the newest one. There is also an installer for Windows. Managers help you to switch between multiple Ruby versions on your system. Installers can be used to install a specific or multiple Ruby versions. Please refer ruby-lang.org for more information.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page