Class: Pallets::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/pallets/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/pallets/configuration.rb', line 42

def initialize
  @backend = :redis
  @backend_args = {}
  @blocking_timeout = 5
  @concurrency = 2
  @failed_job_lifespan = 7_776_000 # 3 months
  @job_timeout = 1_800 # 30 minutes
  @max_failures = 3
  @serializer = :json
  @middleware = default_middleware
end

Instance Attribute Details

#backendObject

Backend to use for handling workflows



4
5
6
# File 'lib/pallets/configuration.rb', line 4

def backend
  @backend
end

#backend_argsObject

Arguments used to initialize the backend



7
8
9
# File 'lib/pallets/configuration.rb', line 7

def backend_args
  @backend_args
end

#blocking_timeoutObject

Number of seconds to block while waiting for jobs



10
11
12
# File 'lib/pallets/configuration.rb', line 10

def blocking_timeout
  @blocking_timeout
end

#concurrencyObject

Number of workers to process jobs



13
14
15
# File 'lib/pallets/configuration.rb', line 13

def concurrency
  @concurrency
end

#failed_job_lifespanObject

Minimum number of seconds a failed job stays in the given up set. After this period, jobs will be permanently deleted



17
18
19
# File 'lib/pallets/configuration.rb', line 17

def failed_job_lifespan
  @failed_job_lifespan
end

#job_timeoutObject

Number of seconds allowed for a job to be processed. If a job exceeds this period, it is considered failed, and scheduled to be processed again



21
22
23
# File 'lib/pallets/configuration.rb', line 21

def job_timeout
  @job_timeout
end

#max_failuresObject

Maximum number of failures allowed per job. Can also be configured on a per task basis



25
26
27
# File 'lib/pallets/configuration.rb', line 25

def max_failures
  @max_failures
end

#middlewareObject (readonly)

Middleware used to wrap job execution with custom logic. Acts like a stack and accepts callable objects (lambdas, procs, objects that respond to call) that take three arguments: the worker handling the job, the job hash and the context

A minimal example of a middleware is:

->(worker, job, context, &b) { puts 'Hello World!'; b.call }


40
41
42
# File 'lib/pallets/configuration.rb', line 40

def middleware
  @middleware
end

#pool_sizeObject



54
55
56
# File 'lib/pallets/configuration.rb', line 54

def pool_size
  @pool_size || @concurrency + 1
end

#serializerObject

Serializer used for jobs



31
32
33
# File 'lib/pallets/configuration.rb', line 31

def serializer
  @serializer
end

Instance Method Details

#default_middlewareObject



58
59
60
61
62
# File 'lib/pallets/configuration.rb', line 58

def default_middleware
  Middleware::Stack[
    Middleware::JobLogger
  ]
end