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 +4 -4
- data/.rubocop.yml +5 -1
- data/lib/legion/extensions/scheduler/data/migrations/006_add_transform_to_schedule.rb +7 -0
- data/lib/legion/extensions/scheduler/runners/schedule.rb +24 -4
- data/lib/legion/extensions/scheduler/transport/messages/send_task.rb +12 -2
- data/lib/legion/extensions/scheduler/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1594d2e1b206c9074f9f0be71337c5322a2e5d18088e42faddbd1381ecb4d8e3
|
4
|
+
data.tar.gz: 36b2c9752e52df2f6ce332fc28d0bf807ad8251afa001af7f2fe691d48793753
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f58ff3e752717c49aa71369d8ca33bdcff54cd574063a447585e38564543b6c77a0b069ee5cdfe360daaf4ee56c4e14cfbab869b0fd6594499940f9c043a8bde
|
7
|
+
data.tar.gz: 5230c4c2c6e3f71ff532d9f7d083006d25d5c4364ac5d54afc3e661bdf6cb4305a0ffd66004291fa2af5e2e557ff4a1bee6514e25c786c1a1caa63eff1eb1b56
|
data/.rubocop.yml
CHANGED
@@ -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],
|
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
|
-
|
24
|
-
|
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(
|
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
|
-
|
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
|
-
|
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
|
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.
|
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-
|
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
|