macaw_framework 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/macaw_framework/core/cron_runner.rb +2 -0
- data/lib/macaw_framework/version.rb +1 -1
- data/lib/macaw_framework.rb +27 -6
- data/sig/macaw_framework/macaw.rbs +3 -0
- 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: 684896888c97d23fc4763ddbf106a7248ca22acedb7550371cdc912a34e4e9ef
|
4
|
+
data.tar.gz: 8188e16ee9193d334360de46c66e7fadbb054e1ffd10183d8967cbc2fb1b763f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b3de5c64a50e8cb95eff2d9d13cbae3a5d24d60f42c4be2ccea7459bf28aaa0ed80d2aaa2a47a64e69fb4eacc8d354d78b38505c9e31b176481ba96aca3b4af7
|
7
|
+
data.tar.gz: 148d541c0ba4d2c6790e939da810e02dd405dd8bc056e8af38ef90bb8f7832b9a366933b3d5fce14df03bc9516d52b41f6a4294f47d8133d2dba1740b32ae0d9
|
data/CHANGELOG.md
CHANGED
@@ -79,3 +79,9 @@
|
|
79
79
|
|
80
80
|
- Adding native cron jobs
|
81
81
|
- Documentation improvement
|
82
|
+
|
83
|
+
## [1.1.2] - 2023-05-31
|
84
|
+
|
85
|
+
- Fixing retry bug in cron jobs, where retries were made after an exception without waiting for interval
|
86
|
+
- Fixing another bug in cron jobs where an exception were thrown when start_delay were not set
|
87
|
+
- Documentation improvement
|
@@ -16,6 +16,7 @@ class CronRunner
|
|
16
16
|
# @param {String} job_name
|
17
17
|
# @param {Proc} block
|
18
18
|
def start_cron_job_thread(interval, start_delay, job_name, &block)
|
19
|
+
start_delay ||= 0
|
19
20
|
raise "interval can't be <= 0 and start_delay can't be < 0!" if interval <= 0 || start_delay.negative?
|
20
21
|
|
21
22
|
@logger&.info("Starting thread for job #{job_name}")
|
@@ -39,6 +40,7 @@ class CronRunner
|
|
39
40
|
sleep(sleep_time)
|
40
41
|
rescue StandardError => e
|
41
42
|
@logger&.error("Error executing cron job with name #{name}: #{e.message}")
|
43
|
+
sleep(interval)
|
42
44
|
end
|
43
45
|
end
|
44
46
|
sleep(1)
|
data/lib/macaw_framework.rb
CHANGED
@@ -56,7 +56,11 @@ module MacawFramework
|
|
56
56
|
# with the respective path.
|
57
57
|
# @param {String} path
|
58
58
|
# @param {Proc} block
|
59
|
-
# @
|
59
|
+
# @example
|
60
|
+
# macaw = MacawFramework::Macaw.new
|
61
|
+
# macaw.get("/hello") do |context|
|
62
|
+
# return "Hello World!", 200, { "Content-Type" => "text/plain" }
|
63
|
+
# end
|
60
64
|
def get(path, cache: false, &block)
|
61
65
|
map_new_endpoint("get", cache, path, &block)
|
62
66
|
end
|
@@ -67,7 +71,10 @@ module MacawFramework
|
|
67
71
|
# @param {String} path
|
68
72
|
# @param {Boolean} cache
|
69
73
|
# @param {Proc} block
|
70
|
-
#
|
74
|
+
# macaw = MacawFramework::Macaw.new
|
75
|
+
# macaw.post("/hello") do |context|
|
76
|
+
# return "Hello World!", 200, { "Content-Type" => "text/plain" }
|
77
|
+
# end
|
71
78
|
def post(path, cache: false, &block)
|
72
79
|
map_new_endpoint("post", cache, path, &block)
|
73
80
|
end
|
@@ -77,7 +84,10 @@ module MacawFramework
|
|
77
84
|
# with the respective path.
|
78
85
|
# @param {String} path
|
79
86
|
# @param {Proc} block
|
80
|
-
#
|
87
|
+
# macaw = MacawFramework::Macaw.new
|
88
|
+
# macaw.put("/hello") do |context|
|
89
|
+
# return "Hello World!", 200, { "Content-Type" => "text/plain" }
|
90
|
+
# end
|
81
91
|
def put(path, cache: false, &block)
|
82
92
|
map_new_endpoint("put", cache, path, &block)
|
83
93
|
end
|
@@ -87,7 +97,10 @@ module MacawFramework
|
|
87
97
|
# with the respective path.
|
88
98
|
# @param {String} path
|
89
99
|
# @param {Proc} block
|
90
|
-
#
|
100
|
+
# macaw = MacawFramework::Macaw.new
|
101
|
+
# macaw.patch("/hello") do |context|
|
102
|
+
# return "Hello World!", 200, { "Content-Type" => "text/plain" }
|
103
|
+
# end
|
91
104
|
def patch(path, cache: false, &block)
|
92
105
|
map_new_endpoint("patch", cache, path, &block)
|
93
106
|
end
|
@@ -97,7 +110,10 @@ module MacawFramework
|
|
97
110
|
# with the respective path.
|
98
111
|
# @param {String} path
|
99
112
|
# @param {Proc} block
|
100
|
-
#
|
113
|
+
# macaw = MacawFramework::Macaw.new
|
114
|
+
# macaw.delete("/hello") do |context|
|
115
|
+
# return "Hello World!", 200, { "Content-Type" => "text/plain" }
|
116
|
+
# end
|
101
117
|
def delete(path, cache: false, &block)
|
102
118
|
map_new_endpoint("delete", cache, path, &block)
|
103
119
|
end
|
@@ -108,7 +124,12 @@ module MacawFramework
|
|
108
124
|
# @param {Integer?} start_delay
|
109
125
|
# @param {String} job_name
|
110
126
|
# @param {Proc} block
|
111
|
-
|
127
|
+
# @example
|
128
|
+
# macaw = MacawFramework::Macaw.new
|
129
|
+
# macaw.setup_job(interval: 60, start_delay: 60, job_name: "job 1") do
|
130
|
+
# puts "I'm a cron job that runs every minute"
|
131
|
+
# end
|
132
|
+
def setup_job(interval: 60, start_delay: 0, job_name: "job_#{SecureRandom.uuid}", &block)
|
112
133
|
@cron_runner ||= CronRunner.new(self)
|
113
134
|
@jobs ||= []
|
114
135
|
@cron_runner.start_cron_job_thread(interval, start_delay, job_name, &block)
|
@@ -3,6 +3,7 @@ module MacawFramework
|
|
3
3
|
@bind: String
|
4
4
|
@cache: untyped
|
5
5
|
@config: Hash[String, untyped]
|
6
|
+
@cron_runner: CronRunner
|
6
7
|
@endpoints_to_cache: Array[String]
|
7
8
|
@macaw_log: Logger?
|
8
9
|
|
@@ -31,6 +32,8 @@ module MacawFramework
|
|
31
32
|
|
32
33
|
def put: -> nil
|
33
34
|
|
35
|
+
def setup_job: -> nil
|
36
|
+
|
34
37
|
def start!: -> nil
|
35
38
|
|
36
39
|
private
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: macaw_framework
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aria Diniz
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-05-
|
11
|
+
date: 2023-05-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: prometheus-client
|