
Security News
New Website “Is It Really FOSS?” Tracks Transparency in Open Source Distribution Models
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.
A tool to collect the same class jobs together and running in batch.
Add this line to your application's Gemfile:
gem 'sidekiq_bulk_job'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install sidekiq_bulk_job
process_fail = lambda do |job_class_name, args, exception|
# do something
# send email
end
SidekiqBulkJob.config({
redis: Redis.new,
logger: Logger.new(STDOUT),
process_fail: process_fail,
async_delay: ASYNC_DELAY,
scheduled_delay: SCHEDULED_DELAY,
queue: :test,
batch_size: BATCH_SIZE,
prefix: "SidekiqBulkJob"
})
// push a job
SidekiqBulkJob.perform_async(TestJob, 10)
At first define a TestJob as example
# create a sidekiq worker, use default queue
class TestJob
include Sidekiq::Worker
sidekiq_options queue: :default
def perform(*args)
puts args
end
end
SidekiqBulkJob will collect the same job in to a list, a batch job will create when beyond the batch_size
in async_delay
amount, and clear the list. The list will continue to collect the job which pushing inside. If reach theasync_delay
time, the SidekiqBulkJob will also created to finish all job collected.
# create a sidekiq worker, use default queue
class TestJob
include Sidekiq::Worker
sidekiq_options queue: :default
def perform(*args)
puts args
end
end
# simple use
SidekiqBulkJob.perform_async(TestJob, 10)
# here will not create 1001 job in sidekiq
# now there are tow jobs created, one is collected 1000 TestJob in batch, another has 1 job inside.
(BATCH_SIZE + 1).times do |i|
SidekiqBulkJob.perform_async(TestJob, i)
end
# same as SidekiqBulkJob.perform_async(TestJob, 10)
TestJob.batch_perform_async(10)
# run at 1 minute after with single job
SidekiqBulkJob.perform_at(1.minutes.after, TestJob, 10)
# same as below
SidekiqBulkJob.perform_in(1 * 60, TestJob, 10)
# same as SidekiqBulkJob.perform_at(1.minutes.after, TestJob, 10)
TestJob.batch_perform_at(1.minutes.after, 10)
# same as SidekiqBulkJob.perform_in(1 * 60, TestJob, 10)
TestJob.batch_perform_in(1.minute, 10)
# set queue to test and run async
TestJob.set(queue: :test).batch_perform_async(10)
# set queue to test and run after 90 seconds
TestJob.set(queue: :test, in: 90).batch_perform_async(10)
#batch_perform_in first params interval will be overrided 'in'/'at' option at setter
# run after 90 seconds instead of 10 seconds
TestJob.set(queue: :test, in: 90).batch_perform_in(10, 10)
process_fail = lambda do |job_class_name, args, exception|
# do something
# send email
end
SidekiqBulkJob.config({
redis: Redis.new,
logger: Logger.new(STDOUT),
process_fail: process_fail,
async_delay: ASYNC_DELAY,
scheduled_delay: SCHEDULED_DELAY,
queue: :test,
batch_size: BATCH_SIZE,
prefix: "SidekiqBulkJob"
})
// push a job
SidekiqBulkJob.perform_async(TestJob, 10)
设置一个TestJob举例子
# create a sidekiq worker, use default queue
class TestJob
include Sidekiq::Worker
sidekiq_options queue: :default
def perform(*args)
puts args
end
end
SidekiqBulkJob会把同类型的job汇总到一个list中,当async_delay
时间内超过batch_size
,会新建一个batch job立刻执行汇总的全部jobs,清空list,清空的list会继续收集后续推入的job;如果在async_delay
时间内未到达batch_size
则会在最后一个job推入后等待async_delay
时间创建一个batch job执行汇总的全部jobs
# create a sidekiq worker, use default queue
class TestJob
include Sidekiq::Worker
sidekiq_options queue: :default
def perform(*args)
puts args
end
end
# simple use
SidekiqBulkJob.perform_async(TestJob, 10)
# here will not create 1001 job in sidekiq
# now there are tow jobs created, one is collected 1000 TestJob in batch, another has 1 job inside.
(BATCH_SIZE + 1).times do |i|
SidekiqBulkJob.perform_async(TestJob, i)
end
# same as SidekiqBulkJob.perform_async(TestJob, 10)
TestJob.batch_perform_async(10)
# run at 1 minute after with single job
SidekiqBulkJob.perform_at(1.minutes.after, TestJob, 10)
# same as below
SidekiqBulkJob.perform_in(1 * 60, TestJob, 10)
# same as SidekiqBulkJob.perform_at(1.minutes.after, TestJob, 10)
TestJob.batch_perform_at(1.minutes.after, 10)
# same as SidekiqBulkJob.perform_in(1 * 60, TestJob, 10)
TestJob.batch_perform_in(1.minute, 10)
# set queue to test and run async
TestJob.set(queue: :test).batch_perform_async(10)
# set queue to test and run after 90 seconds
TestJob.set(queue: :test, in: 90).batch_perform_async(10)
#batch_perform_in first params interval will be overrided 'in'/'at' option at setter
# run after 90 seconds instead of 10 seconds
TestJob.set(queue: :test, in: 90).batch_perform_in(10, 10)
Bug reports and pull requests are welcome on GitHub at https://github.com/scalaview/sidekiq_bulk_job. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the SidekiqBulkJob project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.
FAQs
Unknown package
We found that sidekiq_bulk_job 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
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.
Security News
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
Security News
The Latio podcast explores how static and runtime reachability help teams prioritize exploitable vulnerabilities and streamline AppSec workflows.