seam 1.1.2 → 2.0.0a1
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 +5 -5
- data/Gemfile +4 -2
- data/Gemfile.lock +105 -0
- data/LICENSE.txt +16 -18
- data/README.md +115 -115
- data/Rakefile +23 -0
- data/lib/seam/todo.rb +9 -0
- data/lib/seam/version.rb +3 -1
- data/lib/seam.rb +5 -13
- metadata +61 -91
- data/.gitignore +0 -18
- data/lib/seam/effort.rb +0 -86
- data/lib/seam/flow.rb +0 -53
- data/lib/seam/in_memory.rb +0 -13
- data/lib/seam/persistence.rb +0 -43
- data/lib/seam/step.rb +0 -33
- data/lib/seam/wait_worker.rb +0 -30
- data/lib/seam/worker.rb +0 -166
- data/seam.gemspec +0 -30
- data/spec/seam/effort_spec.rb +0 -43
- data/spec/seam/flow_spec.rb +0 -173
- data/spec/seam/step_spec.rb +0 -34
- data/spec/seam/wait_worker_spec.rb +0 -179
- data/spec/seam/worker_spec.rb +0 -959
- data/spec/spec_helper.rb +0 -8
    
        metadata
    CHANGED
    
    | @@ -1,197 +1,167 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: seam
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version:  | 
| 4 | 
            +
              version: 2.0.0a1
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 | 
            -
            -  | 
| 7 | 
            +
            - Seam Labs, Inc.
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date:  | 
| 11 | 
            +
            date: 2024-04-18 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 | 
            -
              name:  | 
| 15 | 
            -
              requirement: !ruby/object:Gem::Requirement
         | 
| 16 | 
            -
                requirements:
         | 
| 17 | 
            -
                - - '>='
         | 
| 18 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 19 | 
            -
                    version: '0'
         | 
| 20 | 
            -
              type: :runtime
         | 
| 21 | 
            -
              prerelease: false
         | 
| 22 | 
            -
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 23 | 
            -
                requirements:
         | 
| 24 | 
            -
                - - '>='
         | 
| 25 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 26 | 
            -
                    version: '0'
         | 
| 27 | 
            -
            - !ruby/object:Gem::Dependency
         | 
| 28 | 
            -
              name: i18n
         | 
| 14 | 
            +
              name: bundler
         | 
| 29 15 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 30 16 | 
             
                requirements:
         | 
| 31 | 
            -
                - -  | 
| 17 | 
            +
                - - "~>"
         | 
| 32 18 | 
             
                  - !ruby/object:Gem::Version
         | 
| 33 | 
            -
                    version: '0'
         | 
| 34 | 
            -
              type: : | 
| 19 | 
            +
                    version: '2.0'
         | 
| 20 | 
            +
              type: :development
         | 
| 35 21 | 
             
              prerelease: false
         | 
| 36 22 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 37 23 | 
             
                requirements:
         | 
| 38 | 
            -
                - -  | 
| 24 | 
            +
                - - "~>"
         | 
| 39 25 | 
             
                  - !ruby/object:Gem::Version
         | 
| 40 | 
            -
                    version: '0'
         | 
| 26 | 
            +
                    version: '2.0'
         | 
| 41 27 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 42 | 
            -
              name:  | 
| 28 | 
            +
              name: gem-release
         | 
| 43 29 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 44 30 | 
             
                requirements:
         | 
| 45 | 
            -
                - -  | 
| 31 | 
            +
                - - "~>"
         | 
| 46 32 | 
             
                  - !ruby/object:Gem::Version
         | 
| 47 | 
            -
                    version: ' | 
| 48 | 
            -
              type: : | 
| 33 | 
            +
                    version: '2.2'
         | 
| 34 | 
            +
              type: :development
         | 
| 49 35 | 
             
              prerelease: false
         | 
| 50 36 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 51 37 | 
             
                requirements:
         | 
| 52 | 
            -
                - -  | 
| 38 | 
            +
                - - "~>"
         | 
| 53 39 | 
             
                  - !ruby/object:Gem::Version
         | 
| 54 | 
            -
                    version: ' | 
| 40 | 
            +
                    version: '2.2'
         | 
| 55 41 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 56 | 
            -
              name:  | 
| 42 | 
            +
              name: parse_gemspec-cli
         | 
| 57 43 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 58 44 | 
             
                requirements:
         | 
| 59 | 
            -
                - - ~>
         | 
| 45 | 
            +
                - - "~>"
         | 
| 60 46 | 
             
                  - !ruby/object:Gem::Version
         | 
| 61 | 
            -
                    version: '1. | 
| 47 | 
            +
                    version: '1.0'
         | 
| 62 48 | 
             
              type: :development
         | 
| 63 49 | 
             
              prerelease: false
         | 
| 64 50 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 65 51 | 
             
                requirements:
         | 
| 66 | 
            -
                - - ~>
         | 
| 52 | 
            +
                - - "~>"
         | 
| 67 53 | 
             
                  - !ruby/object:Gem::Version
         | 
| 68 | 
            -
                    version: '1. | 
| 54 | 
            +
                    version: '1.0'
         | 
| 69 55 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 70 56 | 
             
              name: rake
         | 
| 71 57 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 72 58 | 
             
                requirements:
         | 
| 73 | 
            -
                - -  | 
| 59 | 
            +
                - - "~>"
         | 
| 74 60 | 
             
                  - !ruby/object:Gem::Version
         | 
| 75 | 
            -
                    version: '0'
         | 
| 61 | 
            +
                    version: '13.0'
         | 
| 76 62 | 
             
              type: :development
         | 
| 77 63 | 
             
              prerelease: false
         | 
| 78 64 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 79 65 | 
             
                requirements:
         | 
| 80 | 
            -
                - -  | 
| 66 | 
            +
                - - "~>"
         | 
| 81 67 | 
             
                  - !ruby/object:Gem::Version
         | 
| 82 | 
            -
                    version: '0'
         | 
| 68 | 
            +
                    version: '13.0'
         | 
| 83 69 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 84 | 
            -
              name:  | 
| 70 | 
            +
              name: rspec
         | 
| 85 71 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 86 72 | 
             
                requirements:
         | 
| 87 | 
            -
                - -  | 
| 73 | 
            +
                - - "~>"
         | 
| 88 74 | 
             
                  - !ruby/object:Gem::Version
         | 
| 89 | 
            -
                    version: '0'
         | 
| 75 | 
            +
                    version: '3.0'
         | 
| 90 76 | 
             
              type: :development
         | 
| 91 77 | 
             
              prerelease: false
         | 
| 92 78 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 93 79 | 
             
                requirements:
         | 
| 94 | 
            -
                - -  | 
| 80 | 
            +
                - - "~>"
         | 
| 95 81 | 
             
                  - !ruby/object:Gem::Version
         | 
| 96 | 
            -
                    version: '0'
         | 
| 82 | 
            +
                    version: '3.0'
         | 
| 97 83 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 98 | 
            -
              name:  | 
| 84 | 
            +
              name: simplecov
         | 
| 99 85 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 100 86 | 
             
                requirements:
         | 
| 101 | 
            -
                - -  | 
| 87 | 
            +
                - - "~>"
         | 
| 102 88 | 
             
                  - !ruby/object:Gem::Version
         | 
| 103 | 
            -
                    version: '0'
         | 
| 89 | 
            +
                    version: '0.21'
         | 
| 104 90 | 
             
              type: :development
         | 
| 105 91 | 
             
              prerelease: false
         | 
| 106 92 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 107 93 | 
             
                requirements:
         | 
| 108 | 
            -
                - -  | 
| 94 | 
            +
                - - "~>"
         | 
| 109 95 | 
             
                  - !ruby/object:Gem::Version
         | 
| 110 | 
            -
                    version: '0'
         | 
| 96 | 
            +
                    version: '0.21'
         | 
| 111 97 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 112 | 
            -
              name:  | 
| 98 | 
            +
              name: simplecov-console
         | 
| 113 99 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 114 100 | 
             
                requirements:
         | 
| 115 | 
            -
                - -  | 
| 101 | 
            +
                - - "~>"
         | 
| 116 102 | 
             
                  - !ruby/object:Gem::Version
         | 
| 117 | 
            -
                    version: '0'
         | 
| 103 | 
            +
                    version: '0.9'
         | 
| 118 104 | 
             
              type: :development
         | 
| 119 105 | 
             
              prerelease: false
         | 
| 120 106 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 121 107 | 
             
                requirements:
         | 
| 122 | 
            -
                - -  | 
| 108 | 
            +
                - - "~>"
         | 
| 123 109 | 
             
                  - !ruby/object:Gem::Version
         | 
| 124 | 
            -
                    version: '0'
         | 
| 110 | 
            +
                    version: '0.9'
         | 
| 125 111 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 126 | 
            -
              name:  | 
| 112 | 
            +
              name: standard
         | 
| 127 113 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 128 114 | 
             
                requirements:
         | 
| 129 | 
            -
                - -  | 
| 115 | 
            +
                - - "~>"
         | 
| 130 116 | 
             
                  - !ruby/object:Gem::Version
         | 
| 131 | 
            -
                    version: ' | 
| 117 | 
            +
                    version: '1.3'
         | 
| 132 118 | 
             
              type: :development
         | 
| 133 119 | 
             
              prerelease: false
         | 
| 134 120 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 135 121 | 
             
                requirements:
         | 
| 136 | 
            -
                - -  | 
| 122 | 
            +
                - - "~>"
         | 
| 137 123 | 
             
                  - !ruby/object:Gem::Version
         | 
| 138 | 
            -
                    version: ' | 
| 139 | 
            -
            description:  | 
| 140 | 
            -
            email:
         | 
| 141 | 
            -
            - darren@cauthon.com
         | 
| 124 | 
            +
                    version: '1.3'
         | 
| 125 | 
            +
            description: SDK for the Seam API written in Ruby.
         | 
| 126 | 
            +
            email: engineering@getseam.com
         | 
| 142 127 | 
             
            executables: []
         | 
| 143 128 | 
             
            extensions: []
         | 
| 144 129 | 
             
            extra_rdoc_files: []
         | 
| 145 130 | 
             
            files:
         | 
| 146 | 
            -
            - .gitignore
         | 
| 147 131 | 
             
            - Gemfile
         | 
| 132 | 
            +
            - Gemfile.lock
         | 
| 148 133 | 
             
            - LICENSE.txt
         | 
| 149 134 | 
             
            - README.md
         | 
| 150 135 | 
             
            - Rakefile
         | 
| 151 136 | 
             
            - lib/seam.rb
         | 
| 152 | 
            -
            - lib/seam/ | 
| 153 | 
            -
            - lib/seam/flow.rb
         | 
| 154 | 
            -
            - lib/seam/in_memory.rb
         | 
| 155 | 
            -
            - lib/seam/persistence.rb
         | 
| 156 | 
            -
            - lib/seam/step.rb
         | 
| 137 | 
            +
            - lib/seam/todo.rb
         | 
| 157 138 | 
             
            - lib/seam/version.rb
         | 
| 158 | 
            -
             | 
| 159 | 
            -
            - lib/seam/worker.rb
         | 
| 160 | 
            -
            - seam.gemspec
         | 
| 161 | 
            -
            - spec/seam/effort_spec.rb
         | 
| 162 | 
            -
            - spec/seam/flow_spec.rb
         | 
| 163 | 
            -
            - spec/seam/step_spec.rb
         | 
| 164 | 
            -
            - spec/seam/wait_worker_spec.rb
         | 
| 165 | 
            -
            - spec/seam/worker_spec.rb
         | 
| 166 | 
            -
            - spec/spec_helper.rb
         | 
| 167 | 
            -
            homepage: ''
         | 
| 139 | 
            +
            homepage: https://github.com/seamapi/ruby-next
         | 
| 168 140 | 
             
            licenses:
         | 
| 169 141 | 
             
            - MIT
         | 
| 170 | 
            -
            metadata: | 
| 142 | 
            +
            metadata:
         | 
| 143 | 
            +
              homepage_uri: https://github.com/seamapi/ruby-next
         | 
| 144 | 
            +
              source_code_uri: https://github.com/seamapi/ruby-next
         | 
| 145 | 
            +
              bug_tracker_uri: https://github.com/seamapi/ruby-next/issues
         | 
| 146 | 
            +
              changelog_uri: https://github.com/seamapi/ruby-next/blob/main/CHANGELOG.md
         | 
| 147 | 
            +
              github_repo: git@github.com:seamapi/ruby-next.git
         | 
| 171 148 | 
             
            post_install_message: 
         | 
| 172 149 | 
             
            rdoc_options: []
         | 
| 173 150 | 
             
            require_paths:
         | 
| 174 151 | 
             
            - lib
         | 
| 175 152 | 
             
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 176 153 | 
             
              requirements:
         | 
| 177 | 
            -
              - -  | 
| 154 | 
            +
              - - ">="
         | 
| 178 155 | 
             
                - !ruby/object:Gem::Version
         | 
| 179 | 
            -
                  version:  | 
| 156 | 
            +
                  version: 3.1.0
         | 
| 180 157 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 181 158 | 
             
              requirements:
         | 
| 182 | 
            -
              - -  | 
| 159 | 
            +
              - - ">="
         | 
| 183 160 | 
             
                - !ruby/object:Gem::Version
         | 
| 184 161 | 
             
                  version: '0'
         | 
| 185 162 | 
             
            requirements: []
         | 
| 186 | 
            -
             | 
| 187 | 
            -
            rubygems_version: 2.2.2
         | 
| 163 | 
            +
            rubygems_version: 3.5.3
         | 
| 188 164 | 
             
            signing_key: 
         | 
| 189 165 | 
             
            specification_version: 4
         | 
| 190 | 
            -
            summary:  | 
| 191 | 
            -
            test_files:
         | 
| 192 | 
            -
            - spec/seam/effort_spec.rb
         | 
| 193 | 
            -
            - spec/seam/flow_spec.rb
         | 
| 194 | 
            -
            - spec/seam/step_spec.rb
         | 
| 195 | 
            -
            - spec/seam/wait_worker_spec.rb
         | 
| 196 | 
            -
            - spec/seam/worker_spec.rb
         | 
| 197 | 
            -
            - spec/spec_helper.rb
         | 
| 166 | 
            +
            summary: Seam Ruby SDK
         | 
| 167 | 
            +
            test_files: []
         | 
    
        data/.gitignore
    DELETED
    
    
    
        data/lib/seam/effort.rb
    DELETED
    
    | @@ -1,86 +0,0 @@ | |
| 1 | 
            -
            module Seam
         | 
| 2 | 
            -
              class Effort
         | 
| 3 | 
            -
                attr_accessor :completed_steps
         | 
| 4 | 
            -
                attr_accessor :created_at
         | 
| 5 | 
            -
                attr_accessor :complete
         | 
| 6 | 
            -
                attr_accessor :completed_at
         | 
| 7 | 
            -
                attr_accessor :id
         | 
| 8 | 
            -
                attr_accessor :next_execute_at
         | 
| 9 | 
            -
                attr_accessor :next_step
         | 
| 10 | 
            -
                attr_accessor :flow
         | 
| 11 | 
            -
                attr_accessor :data
         | 
| 12 | 
            -
                attr_accessor :history
         | 
| 13 | 
            -
             | 
| 14 | 
            -
                class << self
         | 
| 15 | 
            -
             | 
| 16 | 
            -
                  def find effort_id
         | 
| 17 | 
            -
                    Seam::Persistence.find_by_effort_id effort_id
         | 
| 18 | 
            -
                  end
         | 
| 19 | 
            -
             | 
| 20 | 
            -
                  def find_all_by_step step
         | 
| 21 | 
            -
                    Seam::Persistence.find_all_pending_executions_by_step step
         | 
| 22 | 
            -
                  end
         | 
| 23 | 
            -
             | 
| 24 | 
            -
                  def parse document
         | 
| 25 | 
            -
                    Effort.new( {
         | 
| 26 | 
            -
                                  id:              document['id'],
         | 
| 27 | 
            -
                                  created_at:      Time.parse(document['created_at'].to_s),
         | 
| 28 | 
            -
                                  next_execute_at: document['next_execute_at'],
         | 
| 29 | 
            -
                                  next_step:       document['next_step'],
         | 
| 30 | 
            -
                                  flow:            HashWithIndifferentAccess.new(document['flow']),
         | 
| 31 | 
            -
                                  data:            HashWithIndifferentAccess.new(document['data']),
         | 
| 32 | 
            -
                                  history:         document['history'].map { |x| HashWithIndifferentAccess.new x },
         | 
| 33 | 
            -
                                  completed_steps: document['completed_steps'],
         | 
| 34 | 
            -
                                  complete:        document['complete'],
         | 
| 35 | 
            -
                                  completed_at:    document['completed_at']
         | 
| 36 | 
            -
                                } )
         | 
| 37 | 
            -
                  end
         | 
| 38 | 
            -
             | 
| 39 | 
            -
                end
         | 
| 40 | 
            -
                
         | 
| 41 | 
            -
                def initialize(args = {})
         | 
| 42 | 
            -
                  @completed_steps = []
         | 
| 43 | 
            -
                  @history         = []
         | 
| 44 | 
            -
                  @complete        = false
         | 
| 45 | 
            -
                  args.each { |k, v| self.send "#{k}=".to_sym, v }
         | 
| 46 | 
            -
                end
         | 
| 47 | 
            -
             | 
| 48 | 
            -
                def self.create args
         | 
| 49 | 
            -
                  effort = Seam::Effort.new args
         | 
| 50 | 
            -
                  effort.save
         | 
| 51 | 
            -
                  effort
         | 
| 52 | 
            -
                end
         | 
| 53 | 
            -
             | 
| 54 | 
            -
                def save
         | 
| 55 | 
            -
                  existing_record = Seam::Effort.find self.id
         | 
| 56 | 
            -
                  if existing_record
         | 
| 57 | 
            -
                    Seam::Persistence.save self
         | 
| 58 | 
            -
                  else
         | 
| 59 | 
            -
                    Seam::Persistence.create self
         | 
| 60 | 
            -
                  end
         | 
| 61 | 
            -
                end
         | 
| 62 | 
            -
             | 
| 63 | 
            -
                def complete?
         | 
| 64 | 
            -
                  complete
         | 
| 65 | 
            -
                end
         | 
| 66 | 
            -
             | 
| 67 | 
            -
                def to_hash
         | 
| 68 | 
            -
                  {
         | 
| 69 | 
            -
                    id:              self.id,
         | 
| 70 | 
            -
                    created_at:      self.created_at,
         | 
| 71 | 
            -
                    completed_steps: self.completed_steps,
         | 
| 72 | 
            -
                    completed_at:    self.completed_at,
         | 
| 73 | 
            -
                    next_execute_at: self.next_execute_at,
         | 
| 74 | 
            -
                    next_step:       self.next_step,
         | 
| 75 | 
            -
                    flow:            self.flow,
         | 
| 76 | 
            -
                    data:            self.data,
         | 
| 77 | 
            -
                    history:         self.history,
         | 
| 78 | 
            -
                    complete:        self.complete,
         | 
| 79 | 
            -
                  }
         | 
| 80 | 
            -
                end
         | 
| 81 | 
            -
             | 
| 82 | 
            -
                def clone
         | 
| 83 | 
            -
                  Seam::Effort.parse HashWithIndifferentAccess.new(self.to_hash)
         | 
| 84 | 
            -
                end
         | 
| 85 | 
            -
              end
         | 
| 86 | 
            -
            end
         | 
    
        data/lib/seam/flow.rb
    DELETED
    
    | @@ -1,53 +0,0 @@ | |
| 1 | 
            -
            module Seam
         | 
| 2 | 
            -
              class Flow
         | 
| 3 | 
            -
             | 
| 4 | 
            -
                attr_accessor :stamp_data_history
         | 
| 5 | 
            -
             | 
| 6 | 
            -
                def initialize
         | 
| 7 | 
            -
                  @steps = []
         | 
| 8 | 
            -
                  @stamp_data_history = false
         | 
| 9 | 
            -
                end
         | 
| 10 | 
            -
             | 
| 11 | 
            -
                def method_missing(meth, *args, &blk)
         | 
| 12 | 
            -
                  meth = meth.to_s
         | 
| 13 | 
            -
                  @steps << { name: meth, arguments: args }
         | 
| 14 | 
            -
                  true
         | 
| 15 | 
            -
                end
         | 
| 16 | 
            -
             | 
| 17 | 
            -
                def start(data = {})
         | 
| 18 | 
            -
                  Seam::Effort.create( {
         | 
| 19 | 
            -
                                         id:              SecureRandom.uuid.to_s,
         | 
| 20 | 
            -
                                         created_at:      Time.parse(Time.now.to_s),
         | 
| 21 | 
            -
                                         next_execute_at: Time.parse(Time.now.to_s),
         | 
| 22 | 
            -
                                         next_step:       self.steps.first.name.to_s,
         | 
| 23 | 
            -
                                         flow:            the_flow_from,
         | 
| 24 | 
            -
                                         data:            ActiveSupport::HashWithIndifferentAccess.new(data)
         | 
| 25 | 
            -
                                       } )
         | 
| 26 | 
            -
                end
         | 
| 27 | 
            -
             | 
| 28 | 
            -
                def the_flow_from
         | 
| 29 | 
            -
                  hash = self.to_hash
         | 
| 30 | 
            -
                  flow = ActiveSupport::HashWithIndifferentAccess.new hash
         | 
| 31 | 
            -
                  flow['steps'].each do |step|
         | 
| 32 | 
            -
                    step['id'] = SecureRandom.uuid.to_s
         | 
| 33 | 
            -
                  end
         | 
| 34 | 
            -
                  flow
         | 
| 35 | 
            -
                end
         | 
| 36 | 
            -
             | 
| 37 | 
            -
                def to_hash
         | 
| 38 | 
            -
                  { 
         | 
| 39 | 
            -
                    steps: self.steps.map { |x| x.to_hash },
         | 
| 40 | 
            -
                    stamp_data_history: @stamp_data_history
         | 
| 41 | 
            -
                  }
         | 
| 42 | 
            -
                end
         | 
| 43 | 
            -
             | 
| 44 | 
            -
                def steps
         | 
| 45 | 
            -
                  @steps.each.map do |step|
         | 
| 46 | 
            -
                    Seam::Step.new( { name:      step[:name],
         | 
| 47 | 
            -
                                      type:      'do',
         | 
| 48 | 
            -
                                      arguments: step[:arguments] } )
         | 
| 49 | 
            -
             | 
| 50 | 
            -
                  end
         | 
| 51 | 
            -
                end
         | 
| 52 | 
            -
              end
         | 
| 53 | 
            -
            end
         | 
    
        data/lib/seam/in_memory.rb
    DELETED
    
    
    
        data/lib/seam/persistence.rb
    DELETED
    
    | @@ -1,43 +0,0 @@ | |
| 1 | 
            -
            module Seam
         | 
| 2 | 
            -
              module Persistence
         | 
| 3 | 
            -
                def self.find_by_effort_id effort_id
         | 
| 4 | 
            -
                  effort = Seam::InMemory.records.select { |x| x.id == effort_id }.first
         | 
| 5 | 
            -
                  return nil unless effort
         | 
| 6 | 
            -
                  effort.clone
         | 
| 7 | 
            -
                end
         | 
| 8 | 
            -
             | 
| 9 | 
            -
                def self.find_all_pending_executions_by_step step
         | 
| 10 | 
            -
                  Seam::InMemory.records
         | 
| 11 | 
            -
                    .select { |x| x.next_step == step && x.next_execute_at <= Time.now }
         | 
| 12 | 
            -
                    .map { |x| x.clone }
         | 
| 13 | 
            -
                end
         | 
| 14 | 
            -
             | 
| 15 | 
            -
                def self.find_something_to_do
         | 
| 16 | 
            -
                  Seam::InMemory.records
         | 
| 17 | 
            -
                    .select { |x| x.complete.nil? || x.complete == false }
         | 
| 18 | 
            -
                    .select { |x| x.next_execute_at <= Time.now }
         | 
| 19 | 
            -
                    .select { |x| x.next_step != nil }
         | 
| 20 | 
            -
                    .map    { |x| x.clone }
         | 
| 21 | 
            -
                end
         | 
| 22 | 
            -
             | 
| 23 | 
            -
                def self.save effort
         | 
| 24 | 
            -
                  old_record = find_by_effort_id effort.id
         | 
| 25 | 
            -
                  if old_record
         | 
| 26 | 
            -
                    Seam::InMemory.records = Seam::InMemory.records.select { |x| x.id != effort.id }.to_a
         | 
| 27 | 
            -
                  end
         | 
| 28 | 
            -
                  create effort
         | 
| 29 | 
            -
                end
         | 
| 30 | 
            -
             | 
| 31 | 
            -
                def self.create effort
         | 
| 32 | 
            -
                  Seam::InMemory.records = [Seam::InMemory.records, effort].flatten
         | 
| 33 | 
            -
                end
         | 
| 34 | 
            -
             | 
| 35 | 
            -
                def self.all
         | 
| 36 | 
            -
                  Seam::InMemory.records.to_a
         | 
| 37 | 
            -
                end
         | 
| 38 | 
            -
             | 
| 39 | 
            -
                def self.destroy
         | 
| 40 | 
            -
                  Seam::InMemory.records = []
         | 
| 41 | 
            -
                end
         | 
| 42 | 
            -
              end
         | 
| 43 | 
            -
            end
         | 
    
        data/lib/seam/step.rb
    DELETED
    
    | @@ -1,33 +0,0 @@ | |
| 1 | 
            -
            module Seam
         | 
| 2 | 
            -
              class Step
         | 
| 3 | 
            -
                attr_accessor :id
         | 
| 4 | 
            -
                attr_accessor :name
         | 
| 5 | 
            -
                attr_accessor :type
         | 
| 6 | 
            -
                attr_accessor :arguments
         | 
| 7 | 
            -
             | 
| 8 | 
            -
                def initialize(args = {})
         | 
| 9 | 
            -
                  args.each { |k, v| self.send "#{k}=".to_sym, v }
         | 
| 10 | 
            -
                end
         | 
| 11 | 
            -
             | 
| 12 | 
            -
                def to_hash
         | 
| 13 | 
            -
                  {
         | 
| 14 | 
            -
                    id:        id,
         | 
| 15 | 
            -
                    name:      name,
         | 
| 16 | 
            -
                    type:      type,
         | 
| 17 | 
            -
                    arguments: get_arguments
         | 
| 18 | 
            -
                  }
         | 
| 19 | 
            -
                end
         | 
| 20 | 
            -
             | 
| 21 | 
            -
                private
         | 
| 22 | 
            -
             | 
| 23 | 
            -
                def get_arguments
         | 
| 24 | 
            -
                  arguments.map do |x|
         | 
| 25 | 
            -
                    if x.is_a? Hash
         | 
| 26 | 
            -
                      HashWithIndifferentAccess.new(x)
         | 
| 27 | 
            -
                    else
         | 
| 28 | 
            -
                      x
         | 
| 29 | 
            -
                    end
         | 
| 30 | 
            -
                  end
         | 
| 31 | 
            -
                end
         | 
| 32 | 
            -
              end
         | 
| 33 | 
            -
            end
         | 
    
        data/lib/seam/wait_worker.rb
    DELETED
    
    | @@ -1,30 +0,0 @@ | |
| 1 | 
            -
            module Seam
         | 
| 2 | 
            -
             | 
| 3 | 
            -
              class WaitWorker < ::Seam::Worker
         | 
| 4 | 
            -
             | 
| 5 | 
            -
                def initialize
         | 
| 6 | 
            -
                  handles :wait
         | 
| 7 | 
            -
                end
         | 
| 8 | 
            -
             | 
| 9 | 
            -
                def process
         | 
| 10 | 
            -
                  move_to_next_step( { on: the_time_to_move_on } )
         | 
| 11 | 
            -
                end
         | 
| 12 | 
            -
             | 
| 13 | 
            -
                private
         | 
| 14 | 
            -
             | 
| 15 | 
            -
                def the_time_to_move_on
         | 
| 16 | 
            -
                  time_of_last_execution + the_amount_of_time_to_wait
         | 
| 17 | 
            -
                end
         | 
| 18 | 
            -
             | 
| 19 | 
            -
                def the_amount_of_time_to_wait
         | 
| 20 | 
            -
                  current_step[:arguments][0]
         | 
| 21 | 
            -
                end
         | 
| 22 | 
            -
             | 
| 23 | 
            -
                def time_of_last_execution
         | 
| 24 | 
            -
                  return effort.created_at if effort.history.count == 0
         | 
| 25 | 
            -
                  effort.history.last[:stopped_at]
         | 
| 26 | 
            -
                end
         | 
| 27 | 
            -
             | 
| 28 | 
            -
              end
         | 
| 29 | 
            -
             | 
| 30 | 
            -
            end
         | 
    
        data/lib/seam/worker.rb
    DELETED
    
    | @@ -1,166 +0,0 @@ | |
| 1 | 
            -
            module Seam
         | 
| 2 | 
            -
             | 
| 3 | 
            -
              class Worker
         | 
| 4 | 
            -
             | 
| 5 | 
            -
                def handles step
         | 
| 6 | 
            -
                  @step = step
         | 
| 7 | 
            -
                end
         | 
| 8 | 
            -
             | 
| 9 | 
            -
                def execute effort
         | 
| 10 | 
            -
                  set_current_effort effort
         | 
| 11 | 
            -
                  before_process
         | 
| 12 | 
            -
                  process
         | 
| 13 | 
            -
                  after_process
         | 
| 14 | 
            -
                end
         | 
| 15 | 
            -
             | 
| 16 | 
            -
                def self.inherited handler
         | 
| 17 | 
            -
                  @handlers ||= []
         | 
| 18 | 
            -
                  @handlers << handler
         | 
| 19 | 
            -
                end
         | 
| 20 | 
            -
             | 
| 21 | 
            -
                def self.handler_for step
         | 
| 22 | 
            -
                  @handlers.each do |handler|
         | 
| 23 | 
            -
                    instance = handler.new
         | 
| 24 | 
            -
                    return instance if instance.step == step
         | 
| 25 | 
            -
                  end
         | 
| 26 | 
            -
                  nil
         | 
| 27 | 
            -
                end
         | 
| 28 | 
            -
             | 
| 29 | 
            -
                def self.all
         | 
| 30 | 
            -
                  (@handlers || []).map { |x| x.new }
         | 
| 31 | 
            -
                end
         | 
| 32 | 
            -
             | 
| 33 | 
            -
                def execute_all
         | 
| 34 | 
            -
                  efforts_to_execute.each { |e| execute e }
         | 
| 35 | 
            -
                end
         | 
| 36 | 
            -
             | 
| 37 | 
            -
                def eject
         | 
| 38 | 
            -
                  @operation_to_execute = :eject
         | 
| 39 | 
            -
                end
         | 
| 40 | 
            -
             | 
| 41 | 
            -
                def move_to_next_step(options = {})
         | 
| 42 | 
            -
                  @operation_to_execute = :move_to_next_step
         | 
| 43 | 
            -
                  operation_args[:next_execute_at] = (options[:on] || Time.now)
         | 
| 44 | 
            -
                end
         | 
| 45 | 
            -
             | 
| 46 | 
            -
                def try_again_in seconds
         | 
| 47 | 
            -
                  @operation_to_execute    = :try_again_in
         | 
| 48 | 
            -
                  operation_args[:seconds] = seconds
         | 
| 49 | 
            -
                end
         | 
| 50 | 
            -
             | 
| 51 | 
            -
                def try_again_on time
         | 
| 52 | 
            -
                  @operation_to_execute = :try_again_on
         | 
| 53 | 
            -
                  operation_args[:time] = time
         | 
| 54 | 
            -
                end
         | 
| 55 | 
            -
             | 
| 56 | 
            -
                attr_accessor :operation_args
         | 
| 57 | 
            -
                def operation_args
         | 
| 58 | 
            -
                  @operation_args ||= {}
         | 
| 59 | 
            -
                end
         | 
| 60 | 
            -
             | 
| 61 | 
            -
                def operations
         | 
| 62 | 
            -
                  {
         | 
| 63 | 
            -
                    try_again_in:      -> do
         | 
| 64 | 
            -
                                            seconds = operation_args[:seconds]
         | 
| 65 | 
            -
                                            try_again_on = Time.now + seconds
         | 
| 66 | 
            -
             | 
| 67 | 
            -
                                            history[:try_again_on] = try_again_on
         | 
| 68 | 
            -
             | 
| 69 | 
            -
                                            effort.next_execute_at = try_again_on
         | 
| 70 | 
            -
                                          end,
         | 
| 71 | 
            -
                    try_again_on:      -> do
         | 
| 72 | 
            -
                                            history[:try_again_on] = operation_args[:time]
         | 
| 73 | 
            -
                                            effort.next_execute_at = operation_args[:time]
         | 
| 74 | 
            -
                                          end,
         | 
| 75 | 
            -
                    move_to_next_step: -> do
         | 
| 76 | 
            -
                                            effort.next_execute_at = operation_args[:next_execute_at] if operation_args[:next_execute_at]
         | 
| 77 | 
            -
             | 
| 78 | 
            -
                                            effort.completed_steps << effort.next_step
         | 
| 79 | 
            -
             | 
| 80 | 
            -
                                            steps = effort.flow['steps'].map { |x| x['name'] }
         | 
| 81 | 
            -
                                            next_step = steps[effort.completed_steps.count]
         | 
| 82 | 
            -
             | 
| 83 | 
            -
                                            effort.next_step = next_step
         | 
| 84 | 
            -
                                            mark_effort_as_complete if next_step.nil?
         | 
| 85 | 
            -
             | 
| 86 | 
            -
                                          end,
         | 
| 87 | 
            -
                    eject:             -> { mark_effort_as_complete }
         | 
| 88 | 
            -
                  }
         | 
| 89 | 
            -
                end
         | 
| 90 | 
            -
             | 
| 91 | 
            -
                def effort
         | 
| 92 | 
            -
                  @current_effort
         | 
| 93 | 
            -
                end
         | 
| 94 | 
            -
             | 
| 95 | 
            -
                def history
         | 
| 96 | 
            -
                  @current_run
         | 
| 97 | 
            -
                end
         | 
| 98 | 
            -
             | 
| 99 | 
            -
                def step
         | 
| 100 | 
            -
                  s = @step || self.class.name.underscore.gsub('_worker', '')
         | 
| 101 | 
            -
                  s.to_s
         | 
| 102 | 
            -
                end
         | 
| 103 | 
            -
             | 
| 104 | 
            -
                def current_step
         | 
| 105 | 
            -
                  effort.flow["steps"][effort.completed_steps.count]
         | 
| 106 | 
            -
                end
         | 
| 107 | 
            -
             | 
| 108 | 
            -
                private
         | 
| 109 | 
            -
             | 
| 110 | 
            -
                def mark_effort_as_complete
         | 
| 111 | 
            -
                  effort.next_step    = nil
         | 
| 112 | 
            -
                  effort.complete     = true
         | 
| 113 | 
            -
                  effort.completed_at = Time.now
         | 
| 114 | 
            -
                end
         | 
| 115 | 
            -
             | 
| 116 | 
            -
                def set_current_effort effort
         | 
| 117 | 
            -
                  @current_effort = effort
         | 
| 118 | 
            -
                end
         | 
| 119 | 
            -
             | 
| 120 | 
            -
                def before_process
         | 
| 121 | 
            -
                  run = { 
         | 
| 122 | 
            -
                          started_at:  Time.now,
         | 
| 123 | 
            -
                          step:        step, 
         | 
| 124 | 
            -
                          step_id:     current_step['id'],
         | 
| 125 | 
            -
                          data_before: stamping_the_history? ? effort.data.clone : nil
         | 
| 126 | 
            -
                        }
         | 
| 127 | 
            -
                  @current_run = HashWithIndifferentAccess.new run
         | 
| 128 | 
            -
                end
         | 
| 129 | 
            -
             | 
| 130 | 
            -
                def after_process
         | 
| 131 | 
            -
                  execute_the_appropriate_operation
         | 
| 132 | 
            -
                  stamp_the_new_history_record
         | 
| 133 | 
            -
                  save_the_effort
         | 
| 134 | 
            -
                end
         | 
| 135 | 
            -
             | 
| 136 | 
            -
                def efforts_to_execute
         | 
| 137 | 
            -
                  Seam::Effort.find_all_by_step step
         | 
| 138 | 
            -
                end
         | 
| 139 | 
            -
             | 
| 140 | 
            -
                def execute_the_appropriate_operation
         | 
| 141 | 
            -
                  @operation_to_execute ||= :move_to_next_step
         | 
| 142 | 
            -
                  operations[@operation_to_execute].call
         | 
| 143 | 
            -
                end
         | 
| 144 | 
            -
             | 
| 145 | 
            -
                def stamp_the_new_history_record
         | 
| 146 | 
            -
                  history[:result]     = @operation_to_execute
         | 
| 147 | 
            -
                  history[:stopped_at] = Time.now
         | 
| 148 | 
            -
             | 
| 149 | 
            -
                  if stamping_the_history?
         | 
| 150 | 
            -
                    history[:data_after] = effort.data.clone
         | 
| 151 | 
            -
                  end
         | 
| 152 | 
            -
             | 
| 153 | 
            -
                  effort.history << history
         | 
| 154 | 
            -
                end
         | 
| 155 | 
            -
             | 
| 156 | 
            -
                def stamping_the_history?
         | 
| 157 | 
            -
                  effort.flow['stamp_data_history']
         | 
| 158 | 
            -
                end
         | 
| 159 | 
            -
             | 
| 160 | 
            -
                def save_the_effort
         | 
| 161 | 
            -
                  effort.save
         | 
| 162 | 
            -
                end
         | 
| 163 | 
            -
             | 
| 164 | 
            -
              end
         | 
| 165 | 
            -
             | 
| 166 | 
            -
            end
         |