recurrent_tasks 0.0.1
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 +7 -0
- data/lib/recurrent_tasks/base_spec.rb +36 -0
- data/lib/recurrent_tasks/time_frequency_parser.rb +25 -0
- data/lib/recurrent_tasks/version.rb +3 -0
- data/lib/recurrent_tasks.rb +8 -0
- metadata +72 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e6d16e2cec9fcb506c751bf4483ec471cd44325fbcdd7719f60ed54dbd01d673
|
4
|
+
data.tar.gz: b506a3615fc54f07d09369472469f3b00dcd534546117aa6f9f360d945d22d3f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bee20d9ec4b5ba0e11d2b832cddce65d1bfa12ac89d39c6ec76b0d964eae4833a4f6124e0e48dbb96fa87fb8e755034e7dbb486d0bbb8769737d2f30bbfa8a65
|
7
|
+
data.tar.gz: 9830ede8e79eae6dfbae50190bebe92f203911298bedd45c1c266bbc2d0df0e4b206ae046681ce583e07200a8a6dc36aac65b0aa32098bf638e1186c08d65bf9
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# support parsing time frequency from the tasks
|
2
|
+
time_frequency_parser = RecurrentTasks::TimeFrequencyParser.new
|
3
|
+
|
4
|
+
task_files_directory = 'tasks'
|
5
|
+
task_files_paths = Dir["#{task_files_directory}/**/*"]
|
6
|
+
puts "WARNING: no tasks declared in directory '#{task_files_directory}'" if task_files_paths.empty?
|
7
|
+
|
8
|
+
task_files_paths.each do |task_file_path|
|
9
|
+
task_file = File.open task_file_path
|
10
|
+
task_file_json = Oj.load task_file
|
11
|
+
|
12
|
+
title = task_file_json.fetch('title', nil)
|
13
|
+
raise "The task file '#{task_file_path}' is missing a 'title' property" unless title
|
14
|
+
|
15
|
+
describe title do
|
16
|
+
tasks = task_file_json.fetch('tasks', nil)
|
17
|
+
raise "The task file '#{task_file_path}' is missing a 'tasks' list property" unless tasks
|
18
|
+
|
19
|
+
tasks.each_pair do |task_name, task_metadata|
|
20
|
+
documentation_url = task_metadata.fetch('documentation_url', "Missing 'documentation_url' property")
|
21
|
+
|
22
|
+
it "#{task_name} | #{documentation_url}" do
|
23
|
+
frequency_string = task_metadata.fetch('frequency', nil)
|
24
|
+
raise "The task '#{task_name}' inside '#{task_file_path}' is missing a 'frequency' property" unless frequency_string
|
25
|
+
|
26
|
+
frequency = time_frequency_parser.parse_frequency frequency_string
|
27
|
+
last_checked = Time.parse task_metadata['last_checked']
|
28
|
+
|
29
|
+
expect(last_checked + frequency)
|
30
|
+
.to be > Time.now, "The last time this task was done was '#{last_checked}'" \
|
31
|
+
", and given the wanted frequency of '#{frequency_string}'" \
|
32
|
+
', it needs to be done again.'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module RecurrentTasks
|
2
|
+
class TimeFrequencyParser
|
3
|
+
def parse_frequency(frequency)
|
4
|
+
raise ArgumentError, 'Invalid frequency format' unless frequency.match(/(\d+)\s+(\w+)/)
|
5
|
+
|
6
|
+
amount = ::Regexp.last_match(1).to_i
|
7
|
+
unit = ::Regexp.last_match(2).downcase
|
8
|
+
|
9
|
+
get_seconds(unit, amount)
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def get_seconds(unit, amount)
|
15
|
+
case unit
|
16
|
+
when 'day', 'days' then amount * 86_400
|
17
|
+
when 'week', 'weeks' then amount * 604_800
|
18
|
+
when 'month', 'months' then amount * 2_628_000 # Approximate average (30.44 days)
|
19
|
+
when 'year', 'years' then amount * 31_536_000
|
20
|
+
else
|
21
|
+
raise ArgumentError, "Unknown time unit: #{unit}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: recurrent_tasks
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Massimiliano De Vivo
|
8
|
+
bindir: bin
|
9
|
+
cert_chain: []
|
10
|
+
date: 2025-01-08 00:00:00.000000000 Z
|
11
|
+
dependencies:
|
12
|
+
- !ruby/object:Gem::Dependency
|
13
|
+
name: oj
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - "~>"
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '3'
|
19
|
+
type: :runtime
|
20
|
+
prerelease: false
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
requirements:
|
23
|
+
- - "~>"
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: '3'
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: rspec
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - "~>"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '3'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '3'
|
40
|
+
description: A gem that uses that fetches recurrent tasks jsons in "rspec" verify
|
41
|
+
their manual regularity execution
|
42
|
+
email: maxtru2005@gmail.com
|
43
|
+
executables: []
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files: []
|
46
|
+
files:
|
47
|
+
- lib/recurrent_tasks.rb
|
48
|
+
- lib/recurrent_tasks/base_spec.rb
|
49
|
+
- lib/recurrent_tasks/time_frequency_parser.rb
|
50
|
+
- lib/recurrent_tasks/version.rb
|
51
|
+
homepage: https://rubygems.org/gems/recurrent_tasks
|
52
|
+
licenses:
|
53
|
+
- MIT
|
54
|
+
metadata: {}
|
55
|
+
rdoc_options: []
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '3'
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
requirements: []
|
69
|
+
rubygems_version: 3.6.2
|
70
|
+
specification_version: 4
|
71
|
+
summary: Hola!
|
72
|
+
test_files: []
|