Module: Wurk
- Defined in:
- lib/wurk.rb,
lib/wurk/api.rb,
lib/wurk/cli.rb,
lib/wurk/job.rb,
lib/wurk/lua.rb,
lib/wurk/web.rb,
lib/wurk/cron.rb,
lib/wurk/flow.rb,
lib/wurk/keys.rb,
lib/wurk/batch.rb,
lib/wurk/queue.rb,
lib/wurk/stats.rb,
lib/wurk/swarm.rb,
lib/wurk/client.rb,
lib/wurk/deploy.rb,
lib/wurk/engine.rb,
lib/wurk/errors.rb,
lib/wurk/health.rb,
lib/wurk/leader.rb,
lib/wurk/logger.rb,
lib/wurk/queues.rb,
lib/wurk/sentry.rb,
lib/wurk/status.rb,
lib/wurk/unique.rb,
lib/wurk/worker.rb,
lib/wurk/api/app.rb,
lib/wurk/capsule.rb,
lib/wurk/context.rb,
lib/wurk/fetcher.rb,
lib/wurk/history.rb,
lib/wurk/job_set.rb,
lib/wurk/limiter.rb,
lib/wurk/manager.rb,
lib/wurk/metrics.rb,
lib/wurk/railtie.rb,
lib/wurk/testing.rb,
lib/wurk/version.rb,
lib/wurk/api/auth.rb,
lib/wurk/api/fast.rb,
lib/wurk/api/jobs.rb,
lib/wurk/api/page.rb,
lib/wurk/collapse.rb,
lib/wurk/dead_set.rb,
lib/wurk/debounce.rb,
lib/wurk/embedded.rb,
lib/wurk/flow_set.rb,
lib/wurk/job_util.rb,
lib/wurk/launcher.rb,
lib/wurk/profiler.rb,
lib/wurk/throttle.rb,
lib/wurk/topology.rb,
lib/wurk/watchdog.rb,
lib/wurk/work_set.rb,
lib/wurk/api/flows.rb,
lib/wurk/api/swarm.rb,
lib/wurk/batch_set.rb,
lib/wurk/component.rb,
lib/wurk/flow/node.rb,
lib/wurk/heartbeat.rb,
lib/wurk/job_retry.rb,
lib/wurk/pid_cache.rb,
lib/wurk/processor.rb,
lib/wurk/retry_set.rb,
lib/wurk/scheduled.rb,
lib/wurk/telemetry.rb,
lib/wurk/api/queues.rb,
lib/wurk/api/router.rb,
lib/wurk/encryption.rb,
lib/wurk/flow/chain.rb,
lib/wurk/job_logger.rb,
lib/wurk/job_record.rb,
lib/wurk/lua/loader.rb,
lib/wurk/middleware.rb,
lib/wurk/queue_slot.rb,
lib/wurk/rails_boot.rb,
lib/wurk/redis_pool.rb,
lib/wurk/timer_loop.rb,
lib/wurk/web/config.rb,
lib/wurk/web/search.rb,
lib/wurk/api/problem.rb,
lib/wurk/api/request.rb,
lib/wurk/api/roll_up.rb,
lib/wurk/batch/empty.rb,
lib/wurk/flow/status.rb,
lib/wurk/job/options.rb,
lib/wurk/process_set.rb,
lib/wurk/profile_set.rb,
lib/wurk/api/response.rb,
lib/wurk/api/throttle.rb,
lib/wurk/batch/buffer.rb,
lib/wurk/batch/status.rb,
lib/wurk/flow/builder.rb,
lib/wurk/iterable_job.rb,
lib/wurk/limiter/base.rb,
lib/wurk/sorted_entry.rb,
lib/wurk/web/rack_app.rb,
lib/wurk/api/read_only.rb,
lib/wurk/configuration.rb,
lib/wurk/flow/creation.rb,
lib/wurk/limiter/leaky.rb,
lib/wurk/metrics/query.rb,
lib/wurk/pool_checkout.rb,
lib/wurk/redis_options.rb,
lib/wurk/scheduled_set.rb,
lib/wurk/shutdown_gate.rb,
lib/wurk/status/record.rb,
lib/wurk/swarm/backoff.rb,
lib/wurk/swarm/restart.rb,
lib/wurk/web/extension.rb,
lib/wurk/worker/setter.rb,
lib/wurk/api/validation.rb,
lib/wurk/fetcher/capped.rb,
lib/wurk/fetcher/reaper.rb,
lib/wurk/limiter/bucket.rb,
lib/wurk/limiter/points.rb,
lib/wurk/limiter/window.rb,
lib/wurk/metrics/rollup.rb,
lib/wurk/metrics/statsd.rb,
lib/wurk/web/enterprise.rb,
lib/wurk/web/pool_scope.rb,
lib/wurk/api/idempotency.rb,
lib/wurk/api/serializers.rb,
lib/wurk/batch/callbacks.rb,
lib/wurk/client/buffered.rb,
lib/wurk/command_builder.rb,
lib/wurk/flow/completion.rb,
lib/wurk/metrics/flusher.rb,
lib/wurk/metrics/history.rb,
lib/wurk/middleware/i18n.rb,
lib/wurk/status/progress.rb,
lib/wurk/fetcher/reliable.rb,
lib/wurk/middleware/chain.rb,
lib/wurk/redis_connection.rb,
lib/wurk/swarm/child_boot.rb,
lib/wurk/web/batch_status.rb,
lib/wurk/limiter/unlimited.rb,
lib/wurk/middleware/expiry.rb,
lib/wurk/middleware/status.rb,
lib/wurk/sentry/middleware.rb,
lib/wurk/active_job/wrapper.rb,
lib/wurk/batch/callback_job.rb,
lib/wurk/dashboard_manifest.rb,
lib/wurk/iterable_job_query.rb,
lib/wurk/limiter/concurrent.rb,
lib/wurk/middleware/timeout.rb,
lib/wurk/sentry/job_context.rb,
lib/wurk/swarm/orphan_guard.rb,
lib/wurk/batch/death_handler.rb,
lib/wurk/metrics/accumulator.rb,
lib/wurk/sentry/retry_policy.rb,
lib/wurk/fetcher/unit_of_work.rb,
lib/wurk/metrics/queue_rollup.rb,
lib/wurk/redis_client_adapter.rb,
lib/wurk/sentry/error_handler.rb,
lib/wurk/web/locale_negotiator.rb,
lib/wurk/middleware/poison_pill.rb,
lib/wurk/batch/client_middleware.rb,
lib/wurk/batch/server_middleware.rb,
lib/wurk/transaction_aware_client.rb,
lib/wurk/limiter/server_middleware.rb,
app/controllers/wurk/api/pagination.rb,
app/controllers/wurk/api_controller.rb,
app/controllers/wurk/api/serializers.rb,
lib/wurk/iterable_job/csv_enumerator.rb,
lib/wurk/telemetry/client_middleware.rb,
lib/wurk/telemetry/server_middleware.rb,
lib/wurk/middleware/interrupt_handler.rb,
lib/wurk/middleware/current_attributes.rb,
app/controllers/wurk/profiles_controller.rb,
app/controllers/wurk/dashboard_controller.rb,
app/controllers/wurk/extensions_controller.rb,
app/controllers/concerns/wurk/sse_streaming.rb,
app/controllers/wurk/application_controller.rb,
lib/generators/wurk/install/install_generator.rb,
lib/wurk/iterable_job/active_record_enumerator.rb,
app/controllers/concerns/wurk/same_origin_guard.rb,
app/controllers/concerns/wurk/stream_concurrency_guard.rb
Overview
Wurk-namespaced alias kept tight against the Sidekiq definition above; the extra module is a pure constant rebind, not a second class definition.
Defined Under Namespace
Modules: API, ActiveJob, Api, Collapse, CommandBuilder, Component, Context, Cron, DashboardManifest, Debounce, Encryption, Generators, Health, IterableJob, Job, JobUtil, Keys, Limiter, Lua, Metrics, Middleware, PidCache, PoolCheckout, Profiler, QueueSlot, Queues, RailsBoot, RedisConnection, RedisOptions, SameOriginGuard, Scheduled, Sentry, SseStreaming, Status, StreamConcurrencyGuard, Telemetry, Testing, Throttle, Unique, Worker Classes: ApiController, ApplicationController, Batch, BatchSet, CLI, Capsule, Client, Configuration, DashboardController, DeadSet, Deploy, Embedded, Engine, Error, ExtensionsController, Fetcher, Flow, FlowSet, Heartbeat, History, IterableJobQuery, JobLogger, JobRecord, JobRetry, JobSet, Launcher, Leader, Logger, Manager, Process, ProcessSet, Processor, ProfileRecord, ProfileSet, ProfilesController, Queue, Railtie, RedisClientAdapter, RedisPool, RetrySet, ScheduledSet, Shutdown, ShutdownGate, SortedEntry, SortedSet, Stats, Swarm, TimerLoop, Topology, TransactionAwareClient, Watchdog, Web, Work, WorkSet
Constant Summary collapse
- DEFAULT_JOB_OPTIONS =
Process-wide job option defaults. Per-class options from
sidekiq_optionstake precedence; this hash is the floor. { 'retry' => true, 'queue' => 'default' }.freeze
- Periodic =
Cron- VERSION =
'1.7.2'- Workers =
Deprecated alias. Sidekiq <8 used
Workersfor what is nowWorkSet; third-party gems may still reference it. Resolved at load time so the alias survives a constant lookup by either name. WorkSet
Class Attribute Summary collapse
-
.server ⇒ Object
writeonly
Sets the attribute server.
Class Method Summary collapse
- .configuration ⇒ Object (also: default_configuration)
- .configure_client ⇒ Object
-
.configure_embed {|configuration| ... } ⇒ Object
Embedded mode: caller runs Wurk inside its own process (Puma, rake task, etc.) without forking.
- .configure_server ⇒ Object
-
.const_missing(name) ⇒ Object
Lazily loads the Rails engine the first time something asks for
Wurk::Engine. -
.default_job_options ⇒ Object
--- default job options -----------------------------------------.
-
.default_job_options=(hash) ⇒ Object
Merges (does not replace) into the current defaults.
- .dump_json(object) ⇒ Object
- .ent? ⇒ Boolean
-
.enter_server_mode(config = configuration) ⇒ Object
Enter server mode: set the module flag (read by third-party gems via
Sidekiq.server?) AND the per-configserver?predicate that gatesconfigure_server. -
.load_json(string) ⇒ Object
--- JSON ---------------------------------------------------------.
- .logger ⇒ Object
- .logger=(logger) ⇒ Object
-
.pro? ⇒ Boolean
Wurk ships Pro+Ent features in the free gem; these flags exist solely for third-party gems that branch on Sidekiq.pro? / Sidekiq.ent?.
-
.redis(idempotent: false) ⇒ Object
idempotent: trueasserts the block is safe to re-run after a command may already have applied server-side, buying back the full connection backoff (see RedisPool#with). -
.redis_pool ⇒ Object
Capsule-aware pool lookup.
-
.server? ⇒ Boolean
True inside the swarm/manager process (set by exe/wurk / the railtie).
-
.strict_args!(mode = :raise) ⇒ Object
Sets the global mode used by Wurk::JobUtil#verify_json.
-
.strict_args_mode ⇒ Object
defined?distinguishes "never set" from "set to false". -
.testing!(mode = :fake) ⇒ Object
Sidekiq-compatible test-mode entry point.
-
.testing? ⇒ Boolean
True when in :fake or :inline mode (i.e. not pushing to real Redis).
-
.transactional_push! ⇒ Object
Opt in to enqueue-after-commit globally: every
perform_asyncbuilds a Wurk::TransactionAwareClient that defers its push to the surrounding ActiveRecord transaction's commit.
Class Attribute Details
.server=(value) ⇒ Object (writeonly)
Sets the attribute server
215 216 217 |
# File 'lib/wurk.rb', line 215 def server=(value) @server = value end |
Class Method Details
.configuration ⇒ Object Also known as: default_configuration
127 128 129 |
# File 'lib/wurk.rb', line 127 def configuration @configuration ||= Configuration.new end |
.configure_client ⇒ Object
107 108 109 |
# File 'lib/wurk.rb', line 107 def configure_client(&) configuration.configure_client(&) end |
.configure_embed {|configuration| ... } ⇒ Object
Embedded mode: caller runs Wurk inside its own process (Puma, rake task,
etc.) without forking. Concurrency is defaulted to 2 — the GIL makes
higher thread counts counterproductive inside a host process that has
its own pool. The block can override anything before the Embedded
instance is built. Returns a Wurk::Embedded the caller drives with
#run / #quiet / #stop.
117 118 119 120 121 122 123 124 125 |
# File 'lib/wurk.rb', line 117 def if configuration.frozen? raise FrozenError, 'Wurk configuration is frozen; build all embedded instances before calling run' end configuration.concurrency = 2 yield configuration if block_given? Embedded.new(configuration) end |
.configure_server ⇒ Object
103 104 105 |
# File 'lib/wurk.rb', line 103 def configure_server(&) configuration.configure_server(&) end |
.const_missing(name) ⇒ Object
Lazily loads the Rails engine the first time something asks for
Wurk::Engine. See the note above the require "wurk/rails" guard at the
bottom of this file for why the guard alone isn't enough (#282), and why
this loads the engine and not the railtie.
242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/wurk.rb', line 242 def const_missing(name) return super unless name == :Engine return super unless defined?(::Rails::Engine) && defined?(::ActionDispatch::Routing::RouteSet) require_relative 'wurk/engine' # If engine.rb somehow didn't define it, fall through to the real NameError # rather than recursing back into here. return super unless const_defined?(:Engine, false) const_get(:Engine, false) end |
.default_job_options ⇒ Object
--- default job options -----------------------------------------
170 171 172 |
# File 'lib/wurk.rb', line 170 def @default_job_options ||= DEFAULT_JOB_OPTIONS.dup end |
.default_job_options=(hash) ⇒ Object
Merges (does not replace) into the current defaults. Keys are stringified so symbol-keyed callers don't shadow string keys.
176 177 178 |
# File 'lib/wurk.rb', line 176 def (hash) @default_job_options = .merge(hash.transform_keys(&:to_s)) end |
.dump_json(object) ⇒ Object
164 165 166 |
# File 'lib/wurk.rb', line 164 def dump_json(object) ::JSON.generate(object) end |
.ent? ⇒ Boolean
234 235 236 |
# File 'lib/wurk.rb', line 234 def ent? false end |
.enter_server_mode(config = configuration) ⇒ Object
Enter server mode: set the module flag (read by third-party gems via
Sidekiq.server?) AND the per-config server? predicate that gates
configure_server. Both must be set before the app's initializers run,
or configure_server blocks (server middleware, error handlers,
lifecycle hooks) are silently skipped. Defaults to the global config; the
CLI passes its own (possibly test-injected) Configuration instance.
223 224 225 226 |
# File 'lib/wurk.rb', line 223 def enter_server_mode(config = configuration) @server = true config[:server] = true end |
.load_json(string) ⇒ Object
--- JSON ---------------------------------------------------------
160 161 162 |
# File 'lib/wurk.rb', line 160 def load_json(string) ::JSON.parse(string) end |
.logger ⇒ Object
150 151 152 |
# File 'lib/wurk.rb', line 150 def logger configuration.logger end |
.logger=(logger) ⇒ Object
154 155 156 |
# File 'lib/wurk.rb', line 154 def logger=(logger) configuration.logger = logger end |
.pro? ⇒ Boolean
Wurk ships Pro+Ent features in the free gem; these flags exist solely for third-party gems that branch on Sidekiq.pro? / Sidekiq.ent?.
230 231 232 |
# File 'lib/wurk.rb', line 230 def pro? false end |
.redis(idempotent: false) ⇒ Object
idempotent: true asserts the block is safe to re-run after a command may
already have applied server-side, buying back the full connection backoff
(see RedisPool#with). Every wrapper down the chain — Capsule,
Configuration, Component, middleware, Sidekiq.redis — forwards it, so a
caller can claim apply-safety wherever it holds; PoolCheckout drops the
claim for a host-supplied pool that wouldn't understand it. The zero-arg
shape is the drop-in contract: Sidekiq.redis { |c| ... } never changes.
139 140 141 |
# File 'lib/wurk.rb', line 139 def redis(idempotent: false, &) PoolCheckout.with(redis_pool, idempotent, &) end |
.redis_pool ⇒ Object
Capsule-aware pool lookup. Thread-local override wins so per-capsule
workers (Thread.current[:wurk_capsule] = cap) read from their own
connections without leaking to the default capsule.
146 147 148 |
# File 'lib/wurk.rb', line 146 def redis_pool (Thread.current[:wurk_capsule] || configuration.default_capsule).redis_pool end |
.server? ⇒ Boolean
True inside the swarm/manager process (set by exe/wurk / the railtie).
211 212 213 |
# File 'lib/wurk.rb', line 211 def server? !!@server end |
.strict_args!(mode = :raise) ⇒ Object
Sets the global mode used by Wurk::JobUtil#verify_json. mode ∈ [:raise, :warn, false].
191 192 193 |
# File 'lib/wurk.rb', line 191 def strict_args!(mode = :raise) @strict_args_mode = mode end |
.strict_args_mode ⇒ Object
defined? distinguishes "never set" from "set to false".
196 197 198 |
# File 'lib/wurk.rb', line 196 def strict_args_mode defined?(@strict_args_mode) ? @strict_args_mode : Configuration::DEFAULTS[:on_complex_arguments] end |
.testing!(mode = :fake) ⇒ Object
Sidekiq-compatible test-mode entry point. Delegates to Wurk::Testing
(the single source of truth for the mode): a block scopes the mode to the
current thread; no block sets it globally. Sidekiq.testing! aliases here.
205 |
# File 'lib/wurk.rb', line 205 def testing!(mode = :fake, &) = Wurk::Testing.__set_test_mode(mode, &) |
.testing? ⇒ Boolean
True when in :fake or :inline mode (i.e. not pushing to real Redis).
208 |
# File 'lib/wurk.rb', line 208 def testing? = Wurk::Testing.enabled? |
.transactional_push! ⇒ Object
Opt in to enqueue-after-commit globally: every perform_async builds a
Wurk::TransactionAwareClient that defers its push to the surrounding
ActiveRecord transaction's commit. Idempotent. Spec: sidekiq-free.md §3.
183 184 185 |
# File 'lib/wurk.rb', line 183 def transactional_push! ['client_class'] = Wurk::TransactionAwareClient end |