Skip to content

Commit 816dd6e

Browse files
committed
Add kafka
1 parent 0f95960 commit 816dd6e

File tree

6 files changed

+44
-2
lines changed

6 files changed

+44
-2
lines changed

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ gem 'sass-rails', '~> 5.0'
4646
gem 'rack-mini-profiler', '~> 1.0', '>= 1.0.1'
4747
gem 'flamegraph', '~> 0.9.5'
4848
gem 'stackprof', '~> 0.2.12'
49+
gem 'ruby-kafka', '~> 0.7.10'
4950

5051
group :assets do
5152
gem 'jquery-rails', '~> 3.1.2'
@@ -62,6 +63,7 @@ group :development, :test do
6263
gem 'rspec-core', '~> 3.5.2'
6364
gem 'rspec-rails', '~> 3.5.1'
6465
# gem 'selenium-webdriver', '~> 2.44.0'
66+
gem 'irb'
6567
gem 'brakeman', require: false
6668
gem 'bundler-audit'
6769
gem 'pry'

Gemfile.lock

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ GEM
7979
declarative (0.0.10)
8080
declarative-option (0.1.0)
8181
diff-lcs (1.3)
82+
digest-crc (0.4.1)
8283
docile (1.3.0)
8384
domain_name (0.5.20180417)
8485
unf (>= 0.0.5, < 1.0.0)
@@ -131,6 +132,7 @@ GEM
131132
hurley (0.2)
132133
i18n (0.9.5)
133134
concurrent-ruby (~> 1.0)
135+
irb (1.0.0)
134136
jaro_winkler (1.5.1)
135137
jquery-rails (3.1.4)
136138
railties (>= 3.0, < 5.0)
@@ -301,6 +303,8 @@ GEM
301303
rubocop-rails_config (0.2.4)
302304
railties (>= 3.0)
303305
rubocop (~> 0.56)
306+
ruby-kafka (0.7.10)
307+
digest-crc
304308
ruby-prof (0.12.2)
305309
ruby-progressbar (1.10.0)
306310
sass (3.5.6)
@@ -386,6 +390,7 @@ DEPENDENCIES
386390
google-spreadsheet-ruby
387391
gravtastic (~> 3.2.6)
388392
hiredis
393+
irb
389394
jquery-rails (~> 3.1.2)
390395
json-schema (~> 2.7.0)
391396
launchy
@@ -418,6 +423,7 @@ DEPENDENCIES
418423
rspec-rails (~> 3.5.1)
419424
rubocop (~> 0.59.2)
420425
rubocop-rails_config (~> 0.2.4)
426+
ruby-kafka (~> 0.7.10)
421427
ruby-prof (~> 0.12.2)
422428
sass-rails (~> 5.0)
423429
simplecov
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# frozen_string_literal: true
2+
3+
require "kafka"
4+
5+
6+
class KafkaBatchUpdatePointsTask
7+
def initialize
8+
seed_brokers = SiteSetting.value('kafka_seed_brokers')
9+
@kafka = seed_brokers && Kafka.new(seed_brokers, client_id: "tmc-server")
10+
end
11+
12+
def run
13+
return unless @kafka
14+
producer = @kafka.producer
15+
task = KafkaBatchUpdatePoints.first
16+
course = task.course
17+
puts "Batch publishing points for course #{course.name}."
18+
19+
end
20+
21+
def wait_delay
22+
5
23+
end
24+
end
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class KafkaBatchUpdatePoints < ActiveRecord::Base
2+
3+
end
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class CreateKafkaBatchUpdatePoints < ActiveRecord::Migration
2+
def change
3+
create_table :kafka_batch_update_points do |t|
4+
t.references :course, index: true, foreign_key: true
5+
t.timestamps
6+
end
7+
end
8+
end

db/schema.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
#
1212
# It's strongly recommended that you check this file into your version control system.
1313

14-
ActiveRecord::Schema.define(version: 20200112230121) do
15-
14+
ActiveRecord::Schema.define(version: 20200112230122) do
1615
# These are extensions that must be enabled in order to support this database
1716
enable_extension "plpgsql"
1817

0 commit comments

Comments
 (0)