Module: Funktor

Defined in:
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/middleware/new_relic.rb,
lib/funktor/worker/funktor_options.rb,
lib/funktor/cli/generate/work_queue.rb

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
}
VERSION =
"0.7.29"

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



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

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



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

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



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

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



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

def self.configure_work_queue_handler
  yield self
end

.dump_json(object) ⇒ Object



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

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

.dynamodb_clientObject



141
142
143
# File 'lib/funktor.rb', line 141

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

.enable_work_queue_visibilityObject



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

def self.enable_work_queue_visibility
  options[:enable_work_queue_visibility]
end

.enable_work_queue_visibility=(enabled) ⇒ Object



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

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



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

def self.error_handlers
  options[:error_handlers]
end

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

Yields:

  • (@incoming_job_handler_chain)


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

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)


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

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

.job_pusherObject



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

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

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

Yields:

  • (@job_pusher_chain)


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

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

.loggerObject



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

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

.logger=(logger) ⇒ Object



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

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

  @logger = logger
end

.new_relic!Object



25
26
27
28
29
30
31
# File 'lib/funktor/middleware/new_relic.rb', line 25

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



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

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

.options=(opts) ⇒ Object



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

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

.parse_json(string) ⇒ Object



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

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.



126
127
128
129
130
# File 'lib/funktor.rb', line 126

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



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

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



145
146
147
# File 'lib/funktor.rb', line 145

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)


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

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