module Sidekiq

Sidekiq’s Data API provides a Ruby object model on top of Sidekiq’s runtime data in Redis. This API should never be used within application code for business logic.

The Sidekiq server process never uses this API: all data manipulation is done directly for performance reasons to ensure we are using Redis as efficiently as possible at every callsite.

This file is designed to be required within the user’s deployment script; it should need a bare minimum of dependencies. Usage:

require "sidekiq/deploy"
Sidekiq::Deploy.mark!("Some change")

If you do not pass a label, Sidekiq will try to use the latest git commit info.

Iterable jobs are ones which provide a sequence to process using ‘build_enumerator(*args, cursor: cursor)` and then process each element of that sequence in `each_iteration(item, *args)`.

The job is kicked off as normal:

ProcessUserSet.perform_async(123)

but instead of calling ‘perform`, Sidekiq will call:

enum = ProcessUserSet#build_enumerator(123, cursor:nil)

Your Enumerator must yield ‘(object, updated_cursor)` and Sidekiq will call your `each_iteration` method:

ProcessUserSet#each_iteration(object, 123)

After every iteration, Sidekiq will check for shutdown. If we are stopping, the cursor will be saved to Redis and the job re-queued to pick up the rest of the work upon restart. Your job will get the updated_cursor so it can pick up right where it stopped.

enum = ProcessUserSet#build_enumerator(123, cursor: updated_cursor)

The cursor object must be serializable to JSON.

Note there are several APIs to help you build enumerators for ActiveRecord Relations, CSV files, etc. See sidekiq/job/iterable/*.rb.

This file contains the components which track execution metrics within Sidekiq.

SdNotify is a pure-Ruby implementation of sd_notify(3). It can be used to notify systemd about state changes. Methods of this package are no-op on non-systemd systems (eg. Darwin).

The API maps closely to the original implementation of sd_notify(3), therefore be sure to check the official man pages prior to using SdNotify.

@see www.freedesktop.org/software/systemd/man/sd_notify.html

Sidekiq’s systemd integration allows Sidekiq to inform systemd:

1. when it has successfully started
2. when it is starting shutdown
3. periodically for a liveness check with a watchdog thread

Use ‘Sidekiq.transactional_push!` in your sidekiq.rb initializer