fcl_rails_daemon 2.0.2 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/fcld +5 -14
- data/lib/core/daemon.rb +21 -2
- data/lib/core/manager.rb +5 -15
- data/lib/fcl_rails_daemon/version.rb +1 -1
- data/lib/fcl_rails_daemon.rb +3 -2
- 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: 9470229042d48e6dadee57277d8cbf00d3bd7266
|
4
|
+
data.tar.gz: 9ba3fb356cd6763c5e1a08dd94044d3d46283176
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e82a4f6c5b0eea9aad6ce5d5e25c3d5fbd41832db53b844058f38a623469197239ca55e80e9c51ee040b6e8538d5d8c6edcde2fa99f42a367c94166b35287068
|
7
|
+
data.tar.gz: 14a40ab4dc47badf34e3dd4c8c8532f692cd8f12bd8b1c1121d247d78c55f39785dd88f663299e0ad0fedb2b35c106991d50d4ff70dbed5c3a3a20c6cd94270e
|
data/bin/fcld
CHANGED
@@ -39,22 +39,12 @@ class CommandSample < FclRailsDaemon::Daemon
|
|
39
39
|
}
|
40
40
|
end
|
41
41
|
|
42
|
-
|
42
|
+
# Is necessary to implement the method "run"
|
43
43
|
def run
|
44
44
|
# Call the run method of the parent class (super) through a block that will contain your code
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
loop do
|
49
|
-
# Write your code here !!!
|
50
|
-
# Do not use Process.exit (true) , exit () , abort ( ) in your code because it infers the death of the Daemon process
|
51
|
-
|
52
|
-
@counter_sample += 1
|
53
|
-
puts "Running "+ @command +" for " + @counter_sample.to_s + " time :)"
|
54
|
-
|
55
|
-
# Wait in seconds before running your command again
|
56
|
-
sleep(10)
|
57
|
-
end
|
45
|
+
# You can optionally provide the parameter "loop" and "sleep" for the command to run repeatedly
|
46
|
+
super(loop: true, sleep:10) do
|
47
|
+
puts "Running "+ @command +" :)"
|
58
48
|
end
|
59
49
|
end
|
60
50
|
|
@@ -94,5 +84,6 @@ begin
|
|
94
84
|
FclRailsDaemon::Manager.run(ARGV)
|
95
85
|
rescue => e
|
96
86
|
puts e.message
|
87
|
+
e.backtrace.each {|l| puts l}
|
97
88
|
end
|
98
89
|
|
data/lib/core/daemon.rb
CHANGED
@@ -24,7 +24,9 @@ module FclRailsDaemon
|
|
24
24
|
raise " ༼ つ ◕_◕ ༽つ OOOPS... It was not implemented 'self.help' method in command "
|
25
25
|
end
|
26
26
|
|
27
|
-
def run(&block)
|
27
|
+
def run(loop: false, sleep: nil, &block )
|
28
|
+
raise " ༼ つ ◕_◕ ༽つ OOOPS... Block is mandatory to run the command. " unless block_given?
|
29
|
+
|
28
30
|
#check if exist rails environment file
|
29
31
|
env_file = File.join(DAEMON_ROOT, "config", "environment.rb")
|
30
32
|
raise " ༼ つ ◕_◕ ༽つ OOOPS... Could not find the Rails environment file. " unless File.exist? env_file
|
@@ -42,7 +44,15 @@ module FclRailsDaemon
|
|
42
44
|
$stderr.reopen(@log_file, 'a')
|
43
45
|
$stdout.sync = true
|
44
46
|
|
45
|
-
|
47
|
+
if loop.equal? true
|
48
|
+
loop do
|
49
|
+
runner &block
|
50
|
+
sleep(sleep) if sleep.is_a? Numeric
|
51
|
+
end
|
52
|
+
else
|
53
|
+
runner &block
|
54
|
+
end
|
55
|
+
|
46
56
|
end
|
47
57
|
end
|
48
58
|
|
@@ -129,5 +139,14 @@ module FclRailsDaemon
|
|
129
139
|
end
|
130
140
|
end
|
131
141
|
|
142
|
+
def runner(&block)
|
143
|
+
begin
|
144
|
+
block.call
|
145
|
+
rescue Exception => e
|
146
|
+
puts e.message
|
147
|
+
e.backtrace.each {|l| puts l}
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
132
151
|
end
|
133
152
|
end
|
data/lib/core/manager.rb
CHANGED
@@ -146,22 +146,12 @@ class #{command_camel} < FclRailsDaemon::Daemon
|
|
146
146
|
}
|
147
147
|
end
|
148
148
|
|
149
|
-
|
149
|
+
# Is necessary to implement the method "run"
|
150
150
|
def run
|
151
151
|
# Call the run method of the parent class (super) through a block that will contain your code
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
loop do
|
156
|
-
# Write your code here !!!
|
157
|
-
# Do not use Process.exit (true) , exit () , abort ( ) in your code because it infers the death of the Daemon process
|
158
|
-
|
159
|
-
@counter_sample += 1
|
160
|
-
puts "Running "+ @command +" for " + @counter_sample.to_s + " time :)"
|
161
|
-
|
162
|
-
# Wait in seconds before running your command again
|
163
|
-
sleep(10)
|
164
|
-
end
|
152
|
+
# You can optionally provide the parameter "loop" and "sleep" for the command to run repeatedly
|
153
|
+
super(loop: true, sleep:10) do
|
154
|
+
puts "Running "+ @command +" :)"
|
165
155
|
end
|
166
156
|
end
|
167
157
|
|
@@ -176,7 +166,7 @@ end
|
|
176
166
|
File.open(file, 'wb') {|f| f.write(content) }
|
177
167
|
|
178
168
|
file_record = File.join(DAEMON_ROOT, DAEMON_CONFIG['register_file'] )
|
179
|
-
content_to_register = "\nFclRailsDaemon::Recorder.add(command: '#{command_undescore}',
|
169
|
+
content_to_register = "\nFclRailsDaemon::Recorder.add(command: '#{command_undescore}', class_reference: #{command_camel})"
|
180
170
|
File.open(file_record, 'a+') {|f| f << content_to_register }
|
181
171
|
|
182
172
|
puts " ༼ つ ◕_◕ ༽つ OK... Command created and registered!!! "
|
data/lib/fcl_rails_daemon.rb
CHANGED
@@ -14,7 +14,8 @@ require_relative "core/manager.rb"
|
|
14
14
|
# Load commands files
|
15
15
|
command_dir = File.join(DAEMON_ROOT, DAEMON_CONFIG['command_path'])
|
16
16
|
raise " ༼ つ ◕_◕ ༽つ OOOPS... Could not find the command directory. Run 'fcld --configure' " unless File.directory? command_dir
|
17
|
-
Dir[File.join(command_dir, "**/*.rb")].each {|file| require file }
|
18
17
|
|
19
|
-
|
18
|
+
Dir[File.join(command_dir, "**/*.rb")].each {|file| load file }
|
19
|
+
|
20
|
+
load File.join(DAEMON_ROOT, "config", "fcl_rails_daemon.rb")
|
20
21
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fcl_rails_daemon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Washington Silva
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01-
|
11
|
+
date: 2016-01-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|