ductr 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +3 -0
  3. data/.rubocop.yml +14 -0
  4. data/.vscode/settings.json +18 -0
  5. data/COPYING +674 -0
  6. data/COPYING.LESSER +165 -0
  7. data/Gemfile +6 -0
  8. data/Gemfile.lock +121 -0
  9. data/README.md +37 -0
  10. data/Rakefile +37 -0
  11. data/bin/console +15 -0
  12. data/bin/setup +8 -0
  13. data/ductr.gemspec +50 -0
  14. data/exe/ductr +24 -0
  15. data/lib/ductr/adapter.rb +94 -0
  16. data/lib/ductr/cli/default.rb +25 -0
  17. data/lib/ductr/cli/main.rb +60 -0
  18. data/lib/ductr/cli/new_project_generator.rb +72 -0
  19. data/lib/ductr/cli/templates/project/bin_ductr.rb +7 -0
  20. data/lib/ductr/cli/templates/project/config_app.rb +5 -0
  21. data/lib/ductr/cli/templates/project/config_development.yml +8 -0
  22. data/lib/ductr/cli/templates/project/config_environment_development.rb +18 -0
  23. data/lib/ductr/cli/templates/project/gemfile.rb +6 -0
  24. data/lib/ductr/cli/templates/project/rubocop.yml +14 -0
  25. data/lib/ductr/cli/templates/project/tool-versions +1 -0
  26. data/lib/ductr/configuration.rb +145 -0
  27. data/lib/ductr/etl/controls/buffered_destination.rb +65 -0
  28. data/lib/ductr/etl/controls/buffered_transform.rb +76 -0
  29. data/lib/ductr/etl/controls/control.rb +46 -0
  30. data/lib/ductr/etl/controls/destination.rb +28 -0
  31. data/lib/ductr/etl/controls/paginated_source.rb +47 -0
  32. data/lib/ductr/etl/controls/source.rb +21 -0
  33. data/lib/ductr/etl/controls/transform.rb +28 -0
  34. data/lib/ductr/etl/fiber_control.rb +136 -0
  35. data/lib/ductr/etl/fiber_runner.rb +68 -0
  36. data/lib/ductr/etl/kiba_runner.rb +26 -0
  37. data/lib/ductr/etl/parser.rb +115 -0
  38. data/lib/ductr/etl/runner.rb +37 -0
  39. data/lib/ductr/etl_job.rb +161 -0
  40. data/lib/ductr/job.rb +58 -0
  41. data/lib/ductr/job_etl_runner.rb +37 -0
  42. data/lib/ductr/job_status.rb +56 -0
  43. data/lib/ductr/kiba_job.rb +130 -0
  44. data/lib/ductr/log/formatters/color_formatter.rb +48 -0
  45. data/lib/ductr/log/logger.rb +169 -0
  46. data/lib/ductr/log/outputs/file_output.rb +30 -0
  47. data/lib/ductr/log/outputs/standard_output.rb +39 -0
  48. data/lib/ductr/pipeline.rb +133 -0
  49. data/lib/ductr/pipeline_runner.rb +95 -0
  50. data/lib/ductr/pipeline_step.rb +92 -0
  51. data/lib/ductr/registry.rb +55 -0
  52. data/lib/ductr/rufus_trigger.rb +106 -0
  53. data/lib/ductr/scheduler.rb +117 -0
  54. data/lib/ductr/store/job_serializer.rb +59 -0
  55. data/lib/ductr/store/job_store.rb +59 -0
  56. data/lib/ductr/store/pipeline_serializer.rb +106 -0
  57. data/lib/ductr/store/pipeline_store.rb +48 -0
  58. data/lib/ductr/store.rb +81 -0
  59. data/lib/ductr/trigger.rb +49 -0
  60. data/lib/ductr/version.rb +6 -0
  61. data/lib/ductr.rb +143 -0
  62. data/sig/ductr.rbs +1107 -0
  63. metadata +292 -0
data/COPYING.LESSER ADDED
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in ductr.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,121 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ductr (0.1.0)
5
+ activejob (~> 7.0)
6
+ annotable (~> 0.1)
7
+ colorize (~> 0.8)
8
+ kiba (~> 4.0)
9
+ rufus-scheduler (~> 3.8)
10
+ thor (~> 1.2)
11
+ zeitwerk (~> 2.6)
12
+
13
+ GEM
14
+ remote: https://rubygems.org/
15
+ specs:
16
+ activejob (7.0.4)
17
+ activesupport (= 7.0.4)
18
+ globalid (>= 0.3.6)
19
+ activesupport (7.0.4)
20
+ concurrent-ruby (~> 1.0, >= 1.0.2)
21
+ i18n (>= 1.6, < 2)
22
+ minitest (>= 5.1)
23
+ tzinfo (~> 2.0)
24
+ annotable (0.1.2)
25
+ ast (2.4.2)
26
+ colorize (0.8.1)
27
+ commander (4.6.0)
28
+ highline (~> 2.0.0)
29
+ concurrent-ruby (1.1.10)
30
+ debug (1.6.3)
31
+ irb (>= 1.3.6)
32
+ reline (>= 0.3.1)
33
+ diff-lcs (1.5.0)
34
+ et-orbi (1.2.7)
35
+ tzinfo
36
+ fugit (1.7.1)
37
+ et-orbi (~> 1, >= 1.2.7)
38
+ raabro (~> 1.4)
39
+ globalid (1.0.0)
40
+ activesupport (>= 5.0)
41
+ highline (2.0.3)
42
+ i18n (1.12.0)
43
+ concurrent-ruby (~> 1.0)
44
+ io-console (0.5.11)
45
+ irb (1.4.2)
46
+ reline (>= 0.3.0)
47
+ json (2.6.2)
48
+ kiba (4.0.0)
49
+ minitest (5.16.3)
50
+ parallel (1.22.1)
51
+ parlour (5.0.0)
52
+ commander (~> 4.5)
53
+ parser
54
+ rainbow (~> 3.0)
55
+ sorbet-runtime (>= 0.5)
56
+ parser (3.1.2.1)
57
+ ast (~> 2.4.1)
58
+ raabro (1.4.0)
59
+ rainbow (3.1.1)
60
+ rake (13.0.6)
61
+ regexp_parser (2.6.0)
62
+ reline (0.3.1)
63
+ io-console (~> 0.5)
64
+ rexml (3.2.5)
65
+ rspec (3.12.0)
66
+ rspec-core (~> 3.12.0)
67
+ rspec-expectations (~> 3.12.0)
68
+ rspec-mocks (~> 3.12.0)
69
+ rspec-core (3.12.0)
70
+ rspec-support (~> 3.12.0)
71
+ rspec-expectations (3.12.0)
72
+ diff-lcs (>= 1.2.0, < 2.0)
73
+ rspec-support (~> 3.12.0)
74
+ rspec-mocks (3.12.0)
75
+ diff-lcs (>= 1.2.0, < 2.0)
76
+ rspec-support (~> 3.12.0)
77
+ rspec-support (3.12.0)
78
+ rubocop (1.38.0)
79
+ json (~> 2.3)
80
+ parallel (~> 1.10)
81
+ parser (>= 3.1.2.1)
82
+ rainbow (>= 2.2.2, < 4.0)
83
+ regexp_parser (>= 1.8, < 3.0)
84
+ rexml (>= 3.2.5, < 4.0)
85
+ rubocop-ast (>= 1.23.0, < 2.0)
86
+ ruby-progressbar (~> 1.7)
87
+ unicode-display_width (>= 1.4.0, < 3.0)
88
+ rubocop-ast (1.23.0)
89
+ parser (>= 3.1.1.0)
90
+ ruby-progressbar (1.11.0)
91
+ rufus-scheduler (3.8.2)
92
+ fugit (~> 1.1, >= 1.1.6)
93
+ sorbet-runtime (0.5.10712)
94
+ sord (4.0.0)
95
+ commander (~> 4.5)
96
+ parlour (~> 5.0)
97
+ sorbet-runtime
98
+ yard
99
+ thor (1.2.1)
100
+ tzinfo (2.0.5)
101
+ concurrent-ruby (~> 1.0)
102
+ unicode-display_width (2.3.0)
103
+ webrick (1.7.0)
104
+ yard (0.9.28)
105
+ webrick (~> 1.7.0)
106
+ zeitwerk (2.6.4)
107
+
108
+ PLATFORMS
109
+ x86_64-linux
110
+
111
+ DEPENDENCIES
112
+ debug (~> 1.6)
113
+ ductr!
114
+ rake (~> 13.0)
115
+ rspec (~> 3.0)
116
+ rubocop (~> 1.21)
117
+ sord (~> 4.0)
118
+ yard (~> 0.9)
119
+
120
+ BUNDLED WITH
121
+ 2.3.7
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # Ductr
2
+
3
+ Ductr is a data pipeline and ETL framework built with efficiency, simplicity and testability in mind.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem "ductr"
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install ductr
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Development
26
+
27
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
28
+
29
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ductr-io/ductr.
34
+
35
+ ## License
36
+
37
+ The gem is available as open source under the terms of the [LGPLv3 or later](https://opensource.org/license/lgpl-3-0/).
data/Rakefile ADDED
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+ require "sord"
6
+
7
+ RSpec::Core::RakeTask.new(:spec)
8
+
9
+ require "rubocop/rake_task"
10
+
11
+ RuboCop::RakeTask.new
12
+
13
+ task default: %i[spec rubocop]
14
+
15
+ desc "Generates RBS file from the yard documentation"
16
+ task :sord do
17
+ options = {
18
+ rbs: true,
19
+ sord_comments: true,
20
+ regenerate: true,
21
+ break_params: 4,
22
+ replace_errors_with_untyped: false,
23
+ replace_unresolved_with_untyped: false,
24
+ exclude_messages: nil,
25
+ include_messages: nil,
26
+ keep_original_comments: false,
27
+ skip_constants: false,
28
+ use_original_initialize_return: false,
29
+ exclude_untyped: false
30
+ }
31
+
32
+ plugin = Sord::ParlourPlugin.new(options)
33
+ plugin.parlour = Parlour::RbsGenerator.new(break_params: options[:break_params])
34
+ plugin.generate(plugin.parlour.root)
35
+
36
+ File.write("sig/ductr.rbs", plugin.parlour.send(:rbs))
37
+ end
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "ductr"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/ductr.gemspec ADDED
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/ductr/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "ductr"
7
+ spec.version = Ductr::VERSION
8
+ spec.authors = ["Mathieu Morel"]
9
+ spec.email = ["mathieu@lamanufacture.dev"]
10
+ spec.license = "LGPL-3.0-or-later"
11
+
12
+ spec.summary = "Data pipeline and ETL framework."
13
+ spec.description = "A data pipeline and ETL framework for ruby."
14
+ spec.homepage = "https://github.com/ductr-io/ductr"
15
+ spec.required_ruby_version = ">= 3.1.0"
16
+ # TODO: Change gem server URL for a real one
17
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
18
+ spec.metadata["rubygems_mfa_required"] = "true"
19
+
20
+ spec.metadata["homepage_uri"] = spec.homepage
21
+ spec.metadata["source_code_uri"] = spec.homepage
22
+ spec.metadata["changelog_uri"] = "#{spec.homepage}/releases"
23
+
24
+ # Specify which files should be added to the gem when it is released.
25
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
26
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
27
+ `git ls-files -z`.split("\x0").reject do |f|
28
+ (f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis)|appveyor)})
29
+ end
30
+ end
31
+
32
+ spec.bindir = "exe"
33
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
34
+ spec.require_paths = ["lib"]
35
+
36
+ spec.add_development_dependency "debug", "~> 1.6"
37
+ spec.add_development_dependency "rake", "~> 13.0"
38
+ spec.add_development_dependency "rspec", "~> 3.0"
39
+ spec.add_development_dependency "rubocop", "~> 1.21"
40
+ spec.add_development_dependency "sord", "~> 4.0"
41
+ spec.add_development_dependency "yard", "~> 0.9"
42
+
43
+ spec.add_dependency "activejob", "~> 7.0"
44
+ spec.add_dependency "annotable", "~> 0.1"
45
+ spec.add_dependency "colorize", "~> 0.8"
46
+ spec.add_dependency "kiba", "~> 4.0"
47
+ spec.add_dependency "rufus-scheduler", "~> 3.8"
48
+ spec.add_dependency "thor", "~> 1.2"
49
+ spec.add_dependency "zeitwerk", "~> 2.6"
50
+ end
data/exe/ductr ADDED
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "pathname"
5
+
6
+ EXEC_PATH = "bin/ductr"
7
+ CURRENT_DIR = Dir.pwd.freeze
8
+
9
+ loop do
10
+ if File.file?(EXEC_PATH)
11
+ exec Gem.ruby, EXEC_PATH, *ARGV
12
+ break
13
+ end
14
+
15
+ if Pathname.new(Dir.pwd).root?
16
+ Dir.chdir(CURRENT_DIR)
17
+ break
18
+ end
19
+
20
+ Dir.chdir("..")
21
+ end
22
+
23
+ require_relative "../lib/ductr"
24
+ Ductr::CLI::Default.start
@@ -0,0 +1,94 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ductr
4
+ #
5
+ # Base adapter class, your adapter should inherit of this class.
6
+ #
7
+ class Adapter
8
+ class << self
9
+ #
10
+ # All the sources declared for this adapter goes here.
11
+ #
12
+ # @return [Registry] The registry instance
13
+ #
14
+ def source_registry
15
+ @source_registry ||= Registry.new(:source)
16
+ end
17
+
18
+ #
19
+ # All the lookups declared for this adapter goes here.
20
+ #
21
+ # @return [Registry] The registry instance
22
+ #
23
+ def lookup_registry
24
+ @lookup_registry ||= Registry.new(:lookup)
25
+ end
26
+
27
+ #
28
+ # All the destinations declared for this adapter goes here.
29
+ #
30
+ # @return [Registry] The registry instance
31
+ #
32
+ def destination_registry
33
+ @destination_registry ||= Registry.new(:destination)
34
+ end
35
+
36
+ #
37
+ # All the triggers declared for this adapter goes here.
38
+ #
39
+ # @return [Registry] The registry instance
40
+ #
41
+ def trigger_registry
42
+ @trigger_registry ||= Registry.new(:trigger)
43
+ end
44
+ end
45
+
46
+ # @return [Symbol] the adapter instance name
47
+ attr_reader :name
48
+
49
+ # @return [Hash<Symbol: Object>] the adapter configuration hash
50
+ attr_reader :config
51
+
52
+ #
53
+ # Creates a new adapter instance.
54
+ #
55
+ # @param [Symbol] name The adapter instance name, mandatory, must be unique
56
+ # @param [Hash<Symbol: Object>] **config The adapter configuration hash
57
+ #
58
+ def initialize(name, **config)
59
+ @name = name
60
+ @config = config
61
+ end
62
+
63
+ #
64
+ # Allow use of adapter with block syntax, automatically closes on block exit.
65
+ #
66
+ # @yield a block to execute when the adapter is opened
67
+ # @return [void]
68
+ #
69
+ def open(&)
70
+ yield(open!)
71
+ ensure
72
+ close!
73
+ end
74
+
75
+ #
76
+ # Opens the adapter before using it e.g. open connection, authenticate to http endpoint, open file...
77
+ # This method may return something, as a connection object.
78
+ #
79
+ # @return [void]
80
+ #
81
+ def open!
82
+ raise NotImplementedError, "An adapter must implement the #open! method"
83
+ end
84
+
85
+ #
86
+ # Closes the adapter when finished e.g. close connection, drop http session, close file...
87
+ #
88
+ # @return [void]
89
+ #
90
+ def close!
91
+ raise NotImplementedError, "An adapter must implement the #close! method"
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "thor"
4
+
5
+ module Ductr
6
+ module CLI
7
+ #
8
+ # The default CLI is started when no project folder was found.
9
+ # It expose project and adapter generation tasks.
10
+ #
11
+ class Default < Thor
12
+ desc "new", "Generates a new project"
13
+ #
14
+ # Generates a new project
15
+ #
16
+ # @param name [String] The project's name
17
+ #
18
+ # @return [void]
19
+ #
20
+ def new(name = nil)
21
+ NewProjectGenerator.start([name])
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "thor"
4
+
5
+ module Ductr
6
+ module CLI
7
+ #
8
+ # The main CLI is started when used inside a ductr project folder.
9
+ # It exposes scheduling and monitoring tasks.
10
+ #
11
+ class Main < Thor
12
+ desc "perform, p [JOB]", "Queues the given job"
13
+ method_option :sync, type: :boolean, default: false, aliases: "-s",
14
+ desc: "Runs the job synchronously instead of queueing it"
15
+ method_option :params, type: :array, aliases: "-p", desc: "Running the job with parameters"
16
+ def perform(job_name)
17
+ job = job_name.camelize.constantize.new(*options[:params])
18
+
19
+ job.is_a?(Pipeline) ? Store.register_pipeline(job) : Store.register_job(job)
20
+ return job.perform_now if options[:sync]
21
+
22
+ job.enqueue
23
+ return unless ActiveJob::Base.queue_adapter.is_a? ActiveJob::QueueAdapters::AsyncAdapter
24
+
25
+ sleep(0.1) until Store.all_done?
26
+ end
27
+
28
+ desc "schedule, s [SCHEDULERS]", "Run the given schedulers"
29
+ def schedule(*scheduler_names)
30
+ scheduler_names.each { |name| name.camelize.constantize.new }
31
+ Scheduler.start
32
+
33
+ sleep_until_interrupt do
34
+ Scheduler.stop
35
+ end
36
+ end
37
+
38
+ private
39
+
40
+ #
41
+ # Keeps the thread alive until Ctrl-C is pressed.
42
+ #
43
+ # @yield The block to execute when Ctrl-C is pressed
44
+ #
45
+ # @return [void]
46
+ #
47
+ def sleep_until_interrupt(&)
48
+ say "use Ctrl-C to stop"
49
+
50
+ trap "SIGINT" do
51
+ say "Exiting"
52
+ yield
53
+ exit 130
54
+ end
55
+
56
+ sleep
57
+ end
58
+ end
59
+ end
60
+ end