macaw_framework 1.1.1 → 1.1.2

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: 7be8f35960be882dfd7d36d929a06a2ee46416e077532d6cb08809b39db41eed
4
- data.tar.gz: 4ea88706237b89a02b64a7f6c73848d2b64c4ec04643e641ad6ac2711985f57d
3
+ metadata.gz: 684896888c97d23fc4763ddbf106a7248ca22acedb7550371cdc912a34e4e9ef
4
+ data.tar.gz: 8188e16ee9193d334360de46c66e7fadbb054e1ffd10183d8967cbc2fb1b763f
5
5
  SHA512:
6
- metadata.gz: 9a91371c336e35ad1207be16504767676ef1e2125cd40ea4caba201da704d2006a7bd538b77122502c90f85550142d11fc8d1c78c7a0426dd776f8e0b57a1b90
7
- data.tar.gz: 67383dfb8aecb709167d5ab92af4cc9ed821e5898b92b2f06910ed8ccc2390af6afd7cc5325b7d1acf73fe3e731edf47afbbaa760e859fb3da92cae62103d8fd
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)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MacawFramework
4
- VERSION = "1.1.1"
4
+ VERSION = "1.1.2"
5
5
  end
@@ -56,7 +56,11 @@ module MacawFramework
56
56
  # with the respective path.
57
57
  # @param {String} path
58
58
  # @param {Proc} block
59
- # @return {Integer, String}
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
- # @return {String, Integer}
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
- # @return {String, Integer}
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
- # @return {String, Integer}
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
- # @return {String, Integer}
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
- def setup_job(interval: 60, start_delay: nil, job_name: "job_#{SecureRandom.uuid}", &block)
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.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-28 00:00:00.000000000 Z
11
+ date: 2023-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: prometheus-client