lex-scheduler 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c22cca866470f3df8eb371b2a467fbdbe6d9b9a37ff81eba37705640a5c813e4
4
- data.tar.gz: f502c95d2cbb51c45fe052493603db98dbc01cc21970a8650353736cfbcb91f3
3
+ metadata.gz: 1594d2e1b206c9074f9f0be71337c5322a2e5d18088e42faddbd1381ecb4d8e3
4
+ data.tar.gz: 36b2c9752e52df2f6ce332fc28d0bf807ad8251afa001af7f2fe691d48793753
5
5
  SHA512:
6
- metadata.gz: a3ca95510c2fb415ab488727cbe87a11d32d1387abcf156329f473f1f93b3ebf3b4133251900a4756360cbb13544f42ff2b90058aa22735098f5400d4e0447a3
7
- data.tar.gz: 4112f741dc77173ed6e52cc77dd718b0d5db4fd0b389509e0e6080b1bf785bc800e00cc1ec1b92bcc1805c52d3bd7471e587b07df515d16f4e76a62154257af7
6
+ metadata.gz: f58ff3e752717c49aa71369d8ca33bdcff54cd574063a447585e38564543b6c77a0b069ee5cdfe360daaf4ee56c4e14cfbab869b0fd6594499940f9c043a8bde
7
+ data.tar.gz: 5230c4c2c6e3f71ff532d9f7d083006d25d5c4364ac5d54afc3e661bdf6cb4305a0ffd66004291fa2af5e2e557ff4a1bee6514e25c786c1a1caa63eff1eb1b56
@@ -7,7 +7,11 @@ Metrics/ClassLength:
7
7
  Metrics/BlockLength:
8
8
  Max: 50
9
9
  Metrics/AbcSize:
10
- Max: 50
10
+ Max: 100
11
+ Metrics/CyclomaticComplexity:
12
+ Max: 15
13
+ Metrics/PerceivedComplexity:
14
+ Max: 20
11
15
  Style/Documentation:
12
16
  Enabled: false
13
17
  AllCops:
@@ -0,0 +1,7 @@
1
+ Sequel.migration do
2
+ change do
3
+ alter_table(:schedules) do
4
+ add_column :transformation, String, text: true
5
+ end
6
+ end
7
+ end
@@ -1,3 +1,5 @@
1
+ require 'fugit'
2
+
1
3
  module Legion
2
4
  module Extensions
3
5
  module Scheduler
@@ -13,17 +15,29 @@ module Legion
13
15
  end
14
16
 
15
17
  def refresh(**)
16
- Legion::Cache.set('scheduler_schedule_lock', Legion::Settings[:client][:name], 5)
18
+ Legion::Cache.set('scheduler_schedule_lock', Legion::Settings[:client][:name], 2)
17
19
  end
18
20
 
19
21
  def schedule_tasks(**)
20
22
  return unless Legion::Cache.get('scheduler_schedule_lock') == Legion::Settings[:client][:name]
21
23
 
22
24
  models_class::Schedule.where(active: 1).each do |row|
23
- next unless row.values[:interval].positive?
24
- next if (Time.now - row.values[:last_run]) < row.values[:interval]
25
+ if row.values[:interval].is_a?(Integer) && row.values[:interval].positive?
26
+ next if (Time.now - row.values[:last_run]) < row.values[:interval]
27
+ elsif row.values[:cron].is_a? String
28
+ cron_class = Fugit.parse(row.values[:cron])
29
+ if cron_class.respond_to? :to_sec
30
+ next if (Time.now - row.values[:last_run]) < cron_class.to_sec
31
+ elsif cron_class.respond_to? :previous_time
32
+ next if Time.now < Time.parse(cron_class.previous_time.to_s)
33
+ next if row.values[:last_run] > Time.parse(cron_class.previous_time.to_s)
34
+ end
35
+ end
25
36
 
26
- send_task(function_id: row.values[:function_id], **Legion::JSON.load(row.values[:payload]))
37
+ send_task(transformation: row.values[:transformation],
38
+ function_id: row.values[:function_id],
39
+ function: row.values[:name],
40
+ **Legion::JSON.load(row.values[:payload]))
27
41
  row.update(last_run: Sequel::CURRENT_TIMESTAMP)
28
42
  end
29
43
  end
@@ -34,6 +48,12 @@ module Legion
34
48
  payload[thing] = opts[thing] if opts.key? thing
35
49
  end
36
50
 
51
+ return Legion::Transport::Messages::Dynamic.new(**payload).publish if opts[:transformation].nil?
52
+
53
+ payload[:exchange] = 'task'
54
+ payload[:routing_key] = 'task.subtask.transform'
55
+ payload[:transformation] = opts[:transformation]
56
+
37
57
  Legion::Extensions::Scheduler::Transport::Messages::SendTask.new(**payload).publish
38
58
  end
39
59
  end
@@ -5,6 +5,8 @@ module Legion::Extensions::Scheduler::Transport::Messages
5
5
  end
6
6
 
7
7
  def message
8
+ return @options if routing_key == 'task.subtask.transform'
9
+
8
10
  {
9
11
  args: @options[:args] || @options,
10
12
  function: function.values[:name]
@@ -12,11 +14,19 @@ module Legion::Extensions::Scheduler::Transport::Messages
12
14
  end
13
15
 
14
16
  def routing_key
15
- "#{function.runner.extension.values[:name]}.#{function.runner.values[:name]}.#{function.values[:name]}"
17
+ @routing_key ||= if @options.key?(:routing_key)
18
+ @options[:routing_key]
19
+ else
20
+ "#{function.runner.extension.values[:name]}.#{function.runner.values[:name]}.#{function.values[:name]}" # rubocop:disable Layout/LineLength
21
+ end
16
22
  end
17
23
 
18
24
  def exchange
19
- Legion::Transport::Exchange.new(function.runner.extension.values[:exchange])
25
+ @exchange ||= if @options.key?(:exchange) && @options[:exchange].is_a?(String)
26
+ Legion::Transport::Exchange.new(@options[:exchange])
27
+ else
28
+ Legion::Transport::Exchange.new(function.runner.extension.values[:exchange])
29
+ end
20
30
  end
21
31
 
22
32
  def function
@@ -3,7 +3,7 @@
3
3
  module Legion
4
4
  module Extensions
5
5
  module Scheduler
6
- VERSION = '0.1.0'
6
+ VERSION = '0.1.1'
7
7
  end
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lex-scheduler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Esity
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-14 00:00:00.000000000 Z
11
+ date: 2020-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fugit
@@ -120,6 +120,7 @@ files:
120
120
  - lib/legion/extensions/scheduler/data/migrations/003_schedule_indexes.rb
121
121
  - lib/legion/extensions/scheduler/data/migrations/004_schedule_logs_indexes.rb
122
122
  - lib/legion/extensions/scheduler/data/migrations/005_add_payload_column.rb
123
+ - lib/legion/extensions/scheduler/data/migrations/006_add_transform_to_schedule.rb
123
124
  - lib/legion/extensions/scheduler/data/models/schedule.rb
124
125
  - lib/legion/extensions/scheduler/data/models/schedule_log.rb
125
126
  - lib/legion/extensions/scheduler/runners/schedule.rb