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.



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/pallets/configuration.rb', line 52

def initialize
  @backend = :redis
  @backend_args = {}
  @blocking_timeout = 5
  @concurrency = 2
  @failed_job_lifespan = 7_776_000 # 3 months
  @failed_job_max_count = 1_000
  @job_timeout = 1_800 # 30 minutes
  @max_failures = 3
  @scheduler_polling_interval = 10
  @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

#failed_job_max_countObject

Maximum number of failed jobs that can be in the given up set. When this number is reached, the oldest jobs will be permanently deleted



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

def failed_job_max_count
  @failed_job_max_count
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



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

def job_timeout
  @job_timeout
end

#max_failuresObject

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



29
30
31
# File 'lib/pallets/configuration.rb', line 29

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 }


50
51
52
# File 'lib/pallets/configuration.rb', line 50

def middleware
  @middleware
end

#pool_sizeObject



66
67
68
# File 'lib/pallets/configuration.rb', line 66

def pool_size
  @pool_size || @concurrency + 1
end

#scheduler_polling_intervalObject

Number of seconds at which the scheduler checks whether there are jobs due to be (re)processed. Note that this interval is per process; it might require tweaking in case of running multiple Pallets instances, so that the backend is not polled too often



38
39
40
# File 'lib/pallets/configuration.rb', line 38

def scheduler_polling_interval
  @scheduler_polling_interval
end

#serializerObject

Serializer used for jobs



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

def serializer
  @serializer
end

Instance Method Details

#default_middlewareObject



70
71
72
73
74
# File 'lib/pallets/configuration.rb', line 70

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