mushy 0.2.7 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 92ba64469be678fe9889628ae7b6897f78935605605c83652d257f2c4a948d3d
4
- data.tar.gz: 1fa13be3acb6a38f8062536d416630f92867ed93b8f28ac3c140f91a6dfd1385
3
+ metadata.gz: 3a41b5499e19c46d620ec9794fb8265224ce142516be73f977cfacc5597a844f
4
+ data.tar.gz: c74dfd1f76f24da513947edba159a97f4cf613308775346fcf22d8d8eb69a71e
5
5
  SHA512:
6
- metadata.gz: d9aaebd4c3a70c7e64417eb515d719ad6e0bd0c6ccacdde4a2b8ae21845e77b63ee2ca0639d1207aa2d064c8aa3bda48f282a3f640e07b26c171cd1819191416
7
- data.tar.gz: ba95b540eb1746ae7b525221c746aee163861c62956e3ac08e5405738bdf329eea32c0d8378283b6c625a1d1919d6f1fd11b936548822ce2a15c438651112a6f
6
+ metadata.gz: b4ca21536b4b8d740c619ce7632d86d33b7b3db3b36d8279839bf1ceeb6fbd67edec6cd9f38bca7ce15d870223034c20b5bc46c7c55d3d15adda794b23e867de
7
+ data.tar.gz: 0d0254cabb3bd1943872f3db3afede763b9edf4773cc08b4c1dbe54f86f2c3ce9fa55cd24d42b2a30b53044e58925446a0deb504372b57d3c2905ad0fd18098b
@@ -1,3 +1,5 @@
1
+ require 'daemons'
2
+
1
3
  module Mushy
2
4
 
3
5
  module Builder
@@ -32,9 +34,34 @@ module Mushy
32
34
  file = "#{file}.json" unless file.downcase.end_with?('.json')
33
35
  flow = File.open(file).read
34
36
  flow = Mushy::Flow.parse flow
35
- flux = flow.fluxs.select { |x| x.type == 'Cli' }.first
36
37
 
37
- Mushy::Runner.new.start event, flux, flow
38
+ service_fluxes = flow.fluxs.select { |x| x.respond_to? :loop }
39
+
40
+ pwd = Dir.pwd
41
+
42
+ if service_fluxes.any?
43
+ calls = service_fluxes
44
+ .map { |s| { flux: s, proc: ->(e) do
45
+ Dir.chdir pwd
46
+ Mushy::Runner.new.start e, s, flow
47
+ end } }
48
+ .map { |p| ->() { p[:flux].loop &p[:proc] } }
49
+ .map { |x| ->() { loop &x } }
50
+ .map { |x| run_as_a_daemon &x }
51
+
52
+ puts calls.inspect
53
+
54
+ exit
55
+ end
56
+
57
+ cli_flux = flow.fluxs.select { |x| x.kind_of?(Mushy::Cli) }.first
58
+
59
+ Mushy::Runner.new.start event, cli_flux, flow
60
+ end
61
+
62
+ def self.run_as_a_daemon &block
63
+ #block.call
64
+ Daemons.call(&block).pid.pid
38
65
  end
39
66
 
40
67
  def self.get_flow file
@@ -0,0 +1,75 @@
1
+ require 'csv'
2
+
3
+ module Mushy
4
+
5
+ class Interval < Flux
6
+
7
+ def self.setup
8
+ {
9
+ seconds: ->(x) { x },
10
+ minutes: ->(x) { x * 60 },
11
+ hours: ->(x) { x * 60 * 60 },
12
+ days: ->(x) { x * 60 * 60 * 24 },
13
+ weeks: ->(x) { x * 60 * 60 * 24 * 7 },
14
+ }
15
+ end
16
+
17
+ def self.details
18
+ {
19
+ name: 'Interval',
20
+ description: 'Fire an event every X minutes.',
21
+ config: {},
22
+ }.tap do |c|
23
+ setup.keys.each do |key|
24
+ c[:config][key] = {
25
+ description: "#{key.to_s.capitalize} until the job is fired again.",
26
+ type: 'integer',
27
+ shrink: true,
28
+ value: '',
29
+ }
30
+ end
31
+ end
32
+ end
33
+
34
+ def loop &block
35
+ event = { time: time }
36
+ block.call event
37
+ sleep time
38
+ end
39
+
40
+ def time
41
+ the_time = self.class.setup.keys
42
+ .select { |x| config[x].to_s != '' }
43
+ .map { |x| self.class.setup[x].call(config[x].to_i) }
44
+ .sum
45
+
46
+ the_time > 0 ? the_time : 60
47
+ end
48
+
49
+ def process event, config
50
+ now = Time.now
51
+ {
52
+ year: nil,
53
+ month: nil,
54
+ day: nil,
55
+ hour: nil,
56
+ minute: :min,
57
+ second: :sec,
58
+ nanosecond: :nsec,
59
+ utc_offset: nil,
60
+ weekday: :wday,
61
+ day_of_month: :mday,
62
+ day_of_year: :yday,
63
+ string: :to_s,
64
+ epoch_integer: :to_i,
65
+ epoch_float: :to_f,
66
+ }.reduce({}) do |t, i|
67
+ method = i[1] || i[0]
68
+ t[i[0]] = now.send method
69
+ t
70
+ end
71
+ end
72
+
73
+ end
74
+
75
+ end
data/mushy.gemspec CHANGED
@@ -4,7 +4,7 @@ require 'mushy/version'
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = 'mushy'
7
- s.version = '0.2.7'
7
+ s.version = '0.3.0'
8
8
  s.date = '2020-11-23'
9
9
  s.summary = 'Process streams of work using common modules.'
10
10
  s.description = 'This tool assists in the creation and processing of workflows.'
@@ -25,4 +25,5 @@ Gem::Specification.new do |s|
25
25
  s.add_runtime_dependency 'nokogiri'
26
26
  s.add_runtime_dependency 'faraday'
27
27
  s.add_runtime_dependency 'pony'
28
+ s.add_runtime_dependency 'daemons'
28
29
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mushy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Darren Cauthon
@@ -136,6 +136,20 @@ dependencies:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: daemons
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
139
153
  description: This tool assists in the creation and processing of workflows.
140
154
  email: darren@cauthon.com
141
155
  executables:
@@ -163,6 +177,7 @@ files:
163
177
  - lib/mushy/fluxs/format.rb
164
178
  - lib/mushy/fluxs/get.rb
165
179
  - lib/mushy/fluxs/git_log.rb
180
+ - lib/mushy/fluxs/interval.rb
166
181
  - lib/mushy/fluxs/ls.rb
167
182
  - lib/mushy/fluxs/parse_html.rb
168
183
  - lib/mushy/fluxs/pdf.rb