Module: Funktor

Defined in:
lib/funktor/middleware/new_relic.rb,
lib/funktor.rb,
lib/funktor/job.rb,
lib/funktor/rails.rb,
lib/funktor/logger.rb,
lib/funktor/worker.rb,
lib/funktor/counter.rb,
lib/funktor/testing.rb,
lib/funktor/version.rb,
lib/funktor/cli/init.rb,
lib/funktor/job_pusher.rb,
lib/funktor/aws/sqs/event.rb,
lib/funktor/cli/bootstrap.rb,
lib/funktor/error_handler.rb,
lib/funktor/job_activator.rb,
lib/funktor/aws/sqs/record.rb,
lib/funktor/fake_job_queue.rb,
lib/funktor/cli/application.rb,
lib/funktor/web/application.rb,
lib/funktor/activity_tracker.rb,
lib/funktor/middleware_chain.rb,
lib/funktor/cli/generate/base.rb,
lib/funktor/middleware/metrics.rb,
lib/funktor/work_queue_handler.rb,
lib/funktor/incoming_job_handler.rb,
lib/funktor/worker/funktor_options.rb,
lib/funktor/cli/generate/work_queue.rb

Overview

Defined Under Namespace

Modules: Aws, CLI, ErrorHandler, FakeJobQueue, Middleware, TestingPusher, Web, Worker Classes: ActivityTracker, Counter, DelayTooLongError, Error, IncomingJobHandler, Job, JobActivator, JobPusher, Logger, MiddlewareChain, Rails, Testing, WorkQueueHandler

Constant Summary collapse

DEFAULT_OPTIONS =
{
  error_handlers: [],
  log_level: Logger::DEBUG, # Set a high log level during early, active development
  enable_work_queue_visibility: true, # Enable this by default during early, active development
  enable_activity_tracking: true, # Enable this by default during early, active development
}
VERSION =
"0.7.30"

Class Method Summary collapse

Class Method Details

.configure_incoming_job_handler {|_self| ... } ⇒ Object

TODO - Maybe we don’t need this either? Maybe this should be a super dumb thing that also just pushed JSON around? Maybe we want to centralize middlewares in only two spots?

  1. Job pushing.

  2. Job execution.

🤔

Yields:

  • (_self)

Yield Parameters:

  • _self (Funktor)

    the object that the method was called on



57
58
59
# File 'lib/funktor.rb', line 57

def self.configure_incoming_job_handler
  yield self
end

.configure_job_activator {|_self| ... } ⇒ Object

TODO - Does this actually make any sense? Should the JobActivator even know about jobs/classes? Maybe it should be super dumb and just push JSON blobs around?

Yields:

  • (_self)

Yield Parameters:

  • _self (Funktor)

    the object that the method was called on



69
70
71
# File 'lib/funktor.rb', line 69

def self.configure_job_activator
  yield self
end

.configure_job_pusher {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (Funktor)

    the object that the method was called on



28
29
30
# File 'lib/funktor.rb', line 28

def self.configure_job_pusher
  yield self
end

.configure_work_queue_handler {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (Funktor)

    the object that the method was called on



42
43
44
# File 'lib/funktor.rb', line 42

def self.configure_work_queue_handler
  yield self
end

.dump_json(object) ⇒ Object



83
84
85
# File 'lib/funktor.rb', line 83

def self.dump_json(object)
  JSON.generate(object)
end

.dynamodb_clientObject



150
151
152
# File 'lib/funktor.rb', line 150

def self.dynamodb_client
  @dynamodb_client ||= ::Aws::DynamoDB::Client.new
end

.enable_activity_trackingObject



125
126
127
# File 'lib/funktor.rb', line 125

def self.enable_activity_tracking
  options[:enable_activity_tracking]
end

.enable_activity_tracking=(enabled) ⇒ Object



129
130
131
# File 'lib/funktor.rb', line 129

def self.enable_activity_tracking= enabled
  options[:enable_activity_tracking] = enabled
end

.enable_work_queue_visibilityObject



117
118
119
# File 'lib/funktor.rb', line 117

def self.enable_work_queue_visibility
  options[:enable_work_queue_visibility]
end

.enable_work_queue_visibility=(enabled) ⇒ Object



121
122
123
# File 'lib/funktor.rb', line 121

def self.enable_work_queue_visibility= enabled
  options[:enable_work_queue_visibility] = enabled
end

.error_handlersObject

Register a proc to handle any error which occurs within the Funktor active job handler.

Funktor.error_handlers << proc {|error, context| ErrorsAsAService.notify(error, context) }

The default error handler logs errors to STDOUT



100
101
102
# File 'lib/funktor.rb', line 100

def self.error_handlers
  options[:error_handlers]
end

.incoming_job_handler_middleware {|@incoming_job_handler_chain| ... } ⇒ Object

Yields:

  • (@incoming_job_handler_chain)


61
62
63
64
65
# File 'lib/funktor.rb', line 61

def self.incoming_job_handler_middleware
  @incoming_job_handler_chain ||= MiddlewareChain.new
  yield @incoming_job_handler_chain if block_given?
  @incoming_job_handler_chain
end

.job_activator_middleware {|@job_activator_chain| ... } ⇒ Object

Yields:

  • (@job_activator_chain)


73
74
75
76
77
# File 'lib/funktor.rb', line 73

def self.job_activator_middleware
  @job_activator_chain ||= MiddlewareChain.new
  yield @job_activator_chain if block_given?
  @job_activator_chain
end

.job_pusherObject



32
33
34
# File 'lib/funktor.rb', line 32

def self.job_pusher
  @job_pusher ||= JobPusher.new
end

.job_pusher_middleware {|@job_pusher_chain| ... } ⇒ Object

Yields:

  • (@job_pusher_chain)


36
37
38
39
40
# File 'lib/funktor.rb', line 36

def self.job_pusher_middleware
  @job_pusher_chain ||= MiddlewareChain.new
  yield @job_pusher_chain if block_given?
  @job_pusher_chain
end

.loggerObject



104
105
106
# File 'lib/funktor.rb', line 104

def self.logger
  @logger ||= Funktor::Logger.new($stdout, level: options[:log_level])
end

.logger=(logger) ⇒ Object



108
109
110
111
112
113
114
115
# File 'lib/funktor.rb', line 108

def self.logger=(logger)
  if logger.nil?
    self.logger.level = Logger::FATAL
    return self.logger
  end

  @logger = logger
end

.new_relic!Object



30
31
32
33
34
35
36
# File 'lib/funktor/middleware/new_relic.rb', line 30

def self.new_relic!
  Funktor.configure_work_queue_handler do |config|
    config.work_queue_handler_middleware do |chain|
      chain.add Funktor::Middleware::NewRelic
    end
  end
end

.optionsObject



87
88
89
# File 'lib/funktor.rb', line 87

def self.options
  @options ||= DEFAULT_OPTIONS.dup
end

.options=(opts) ⇒ Object



91
92
93
# File 'lib/funktor.rb', line 91

def self.options=(opts)
  @options = opts
end

.parse_json(string) ⇒ Object



79
80
81
# File 'lib/funktor.rb', line 79

def self.parse_json(string)
  JSON.parse(string)
end

.raw_loggerObject

We have a raw_logger that doesn’t add timestamps and what not. This is used to publish CloudWatch metrics that can be used in dashboards.



135
136
137
138
139
# File 'lib/funktor.rb', line 135

def self.raw_logger
  @raw_logger ||= Funktor::Logger.new($stdout, level: options[:log_level], formatter: proc {|severity, datetime, progname, msg|
    "#{msg}\n"
  })
end

.raw_logger=(raw_logger) ⇒ Object



141
142
143
144
145
146
147
148
# File 'lib/funktor.rb', line 141

def self.raw_logger=(raw_logger)
  if raw_logger.nil?
    self.raw_logger.level = Logger::FATAL
    return self.raw_logger
  end

  @raw_logger = raw_logger
end

.sqs_clientObject



154
155
156
# File 'lib/funktor.rb', line 154

def self.sqs_client
  @sqs_client ||= ::Aws::SQS::Client.new
end

.work_queue_handler_middleware {|@work_queue_handler_chain| ... } ⇒ Object

Yields:

  • (@work_queue_handler_chain)


46
47
48
49
50
# File 'lib/funktor.rb', line 46

def self.work_queue_handler_middleware
  @work_queue_handler_chain ||= MiddlewareChain.new
  yield @work_queue_handler_chain if block_given?
  @work_queue_handler_chain
end