arq 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/arq/action.rb +1 -1
- data/lib/arq/runnable.rb +35 -16
- data/lib/arq/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 83941043c326bd9f80903aa4755c49ae3affe39584f12d3757ab8a05e0878987
|
4
|
+
data.tar.gz: d94724fe95ba5dfe444c3d2587357ec60c825a61c5a0a5743a55b8c44c2b3b05
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 418c2ba2e7f9373056b1eb52503c9af47749921c8c696bdf4dce98bcf0649684eab3f2a48742f3943aed00839c1e776178e0fc4b0932409203d7c04891fa52bf
|
7
|
+
data.tar.gz: 543ada56b97ebef9d58fd01e614583aca4a123707917bd3d11607e2645c6ae4688db1b942be279fd0fac86c0986d6d5f7d9c9c198d8ee5742efaffbcced27f88
|
data/lib/arq/action.rb
CHANGED
data/lib/arq/runnable.rb
CHANGED
@@ -16,9 +16,7 @@ module Arq
|
|
16
16
|
|
17
17
|
validate_required_params
|
18
18
|
|
19
|
-
import_context
|
20
19
|
val = run_block
|
21
|
-
export_context
|
22
20
|
|
23
21
|
# If the block returned an array, attempt to run
|
24
22
|
run_sequence(val) if val.is_a?(Array)
|
@@ -33,20 +31,22 @@ module Arq
|
|
33
31
|
Arq::Runnable.new(@ctx, [], [], &block)
|
34
32
|
end
|
35
33
|
|
36
|
-
def fail!(message)
|
34
|
+
def fail!(message = nil)
|
37
35
|
@ctx.fail!(message)
|
38
36
|
end
|
39
37
|
|
40
|
-
def fail_now!(message)
|
38
|
+
def fail_now!(message = nil)
|
41
39
|
@ctx.fail_now!(message)
|
42
40
|
end
|
43
41
|
|
44
42
|
private
|
45
43
|
|
46
44
|
def run_block
|
47
|
-
|
48
|
-
|
49
|
-
|
45
|
+
with_context do
|
46
|
+
instance_eval(&@block)
|
47
|
+
rescue Arq::FailureError
|
48
|
+
nil
|
49
|
+
end
|
50
50
|
end
|
51
51
|
|
52
52
|
def run_sequence(sequence)
|
@@ -60,20 +60,39 @@ module Arq
|
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
-
|
63
|
+
# Runs the block with context parameters set as instance variables, then
|
64
|
+
# imports all context parameters and any new instance vars into the context.
|
65
|
+
# Returns the return value of the block.
|
66
|
+
def with_context
|
67
|
+
# Grab all current variables to know what is being returned
|
68
|
+
before_vars = instance_variables
|
69
|
+
|
70
|
+
# Load all context parameters into runnable instance
|
71
|
+
import_context_to_vars
|
72
|
+
|
73
|
+
# Run block
|
74
|
+
val = yield
|
75
|
+
|
76
|
+
# Grab all ctx + new vars
|
77
|
+
ctx_vars = instance_variables - before_vars
|
78
|
+
|
79
|
+
# Import instance vars into ctx
|
80
|
+
import_vars_to_context(ctx_vars)
|
81
|
+
|
82
|
+
# Return block value
|
83
|
+
val
|
84
|
+
end
|
85
|
+
|
86
|
+
def import_context_to_vars
|
64
87
|
@ctx.each do |key, val|
|
65
88
|
instance_variable_set(:"@#{key}", val)
|
66
89
|
end
|
67
90
|
end
|
68
91
|
|
69
|
-
def
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
instance_key = :"@#{key}"
|
74
|
-
# Must check for existence since getting non-existent
|
75
|
-
# instance variables will return nil.
|
76
|
-
@ctx[key] = instance_variable_get(instance_key) if instance_variables.include?(instance_key)
|
92
|
+
def import_vars_to_context(vars)
|
93
|
+
vars.each do |var|
|
94
|
+
key = var[1..].to_sym
|
95
|
+
@ctx[key] = instance_variable_get(var)
|
77
96
|
end
|
78
97
|
end
|
79
98
|
|
data/lib/arq/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arq
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kavin Phan
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-09-
|
11
|
+
date: 2022-09-09 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A service skeleton framework heavily inspired by LightService with the
|
14
14
|
primary goal of being less verbose.
|