farmstead 0.0.47 → 0.0.48
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/farmstead/cli/db.rb +4 -3
- data/lib/farmstead/db.rb +17 -0
- data/lib/farmstead/pipeline/extract.rb +10 -22
- data/lib/farmstead/scaffold/Gemfile.erb +1 -0
- data/lib/farmstead/service.rb +8 -9
- data/lib/farmstead/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 76eed38e0bcb82ac852d9c5909f5b196e158dec9
|
4
|
+
data.tar.gz: 02c6768169ac7b44d792b1ac728ec2df7f291d6f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 967d13b9a83c5ddc18439538a9a0fe152d115344095669d10439d2f2023ec050b803dbb8cde264e6fe0c22e8a045b7affbee440ed8693c1cd30a0994b42d2269
|
7
|
+
data.tar.gz: 5263d000b55a24a1196530c5c9c407d92f1774be5859713c0ddd9eb3c45569e0cb536d4d9f28991f8a459a91bef5d0a88bb89fc0f2b764dd6e468b1f9275334e
|
data/Gemfile.lock
CHANGED
data/lib/farmstead/cli/db.rb
CHANGED
@@ -8,9 +8,10 @@ module Farmstead
|
|
8
8
|
Farmstead::DB.setup
|
9
9
|
end
|
10
10
|
|
11
|
-
desc "list", "List
|
12
|
-
def list
|
13
|
-
puts "List
|
11
|
+
desc "list table", "List all records in a table"
|
12
|
+
def list(table)
|
13
|
+
puts "List all records in a table"
|
14
|
+
Farmstead::DB.list(table)
|
14
15
|
end
|
15
16
|
end
|
16
17
|
end
|
data/lib/farmstead/db.rb
CHANGED
@@ -24,6 +24,23 @@ module Farmstead
|
|
24
24
|
String(:type)
|
25
25
|
String(:module)
|
26
26
|
end
|
27
|
+
@@DB.create_table :test do
|
28
|
+
primary_key(:id)
|
29
|
+
String(:result)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.list(table)
|
34
|
+
self.pull_variables
|
35
|
+
ds = @@DB[table]
|
36
|
+
puts ds.all
|
37
|
+
end
|
38
|
+
|
39
|
+
# Insert an array of values into a table
|
40
|
+
def self.insert(table,array)
|
41
|
+
self.pull_variables
|
42
|
+
ds = @@DB[table]
|
43
|
+
ds.insert(array)
|
27
44
|
end
|
28
45
|
|
29
46
|
end
|
@@ -9,35 +9,23 @@
|
|
9
9
|
# Every micro-service inherits the Service class
|
10
10
|
module Farmstead
|
11
11
|
module Extract
|
12
|
-
class
|
12
|
+
class Service < Farmstead::Service
|
13
13
|
def run
|
14
|
-
|
15
|
-
puts "Do something"
|
16
|
-
sleep 300
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
# Subscribed to the Field topic
|
22
|
-
# Works on message
|
23
|
-
class Consumer < Farmstead::Service
|
24
|
-
def run
|
25
|
-
@consumer.subscribe('Field')
|
14
|
+
@consumer.subscribe("Field")
|
26
15
|
trap('TERM') { @consumer.stop }
|
27
16
|
@consumer.each_message do |message|
|
28
17
|
puts "Received: #{message.value}"
|
29
|
-
|
18
|
+
# Run the extract method of the module referenced by the message
|
19
|
+
obj = JSON.parse(message.value)
|
20
|
+
my_module = Object.const_get "<%= ENV['name'].capitalize %>::#{obj["module"]}"
|
21
|
+
result = my_module::extract
|
22
|
+
Farmstead::DB.insert("test",[result])
|
23
|
+
@producer.produce(result, topic: "Forest")
|
24
|
+
@producer.deliver_messages
|
30
25
|
@consumer.mark_message_as_processed(message)
|
31
26
|
end
|
32
27
|
end
|
33
|
-
|
34
|
-
def magic_work(site)
|
35
|
-
hash = JSON.parse(site)
|
36
|
-
hash['scarecrow'] = 'true'
|
37
|
-
json = hash.to_json
|
38
|
-
puts "Writing: #{json}"
|
39
|
-
write_message(json, topic: 'Forest')
|
40
|
-
end
|
41
28
|
end
|
42
29
|
end
|
43
30
|
end
|
31
|
+
|
data/lib/farmstead/service.rb
CHANGED
@@ -23,15 +23,6 @@ module Farmstead
|
|
23
23
|
#@selenium_hub = ENV['SELENIUM_HUB']
|
24
24
|
end
|
25
25
|
|
26
|
-
def mysql_init
|
27
|
-
@mysql = Mysql2::Client.new(
|
28
|
-
host: @mysql_host,
|
29
|
-
username: @mysql_user,
|
30
|
-
password: @mysql_pass,
|
31
|
-
database: @mysql_db
|
32
|
-
)
|
33
|
-
end
|
34
|
-
|
35
26
|
# Runs on an infinite loop processing records
|
36
27
|
# on MySQL DB and writing messages accordingly
|
37
28
|
def producer
|
@@ -85,5 +76,13 @@ module Farmstead
|
|
85
76
|
time1 = Time.new
|
86
77
|
write_file(@logfile, "Current Time : #{time1.inspect}")
|
87
78
|
end
|
79
|
+
|
80
|
+
def magic_work(body)
|
81
|
+
hash = JSON.parse(body)
|
82
|
+
hash['scarecrow'] = 'true'
|
83
|
+
json = hash.to_json
|
84
|
+
puts "Writing: #{json}"
|
85
|
+
write_message(json, topic: 'Forest')
|
86
|
+
end
|
88
87
|
end
|
89
88
|
end
|
data/lib/farmstead/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: farmstead
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.48
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ken Jenney
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-01-
|
11
|
+
date: 2018-01-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|