Sha256: fbd974c7f89d0dfc483647cd7ef0d23be07e02fbc4cc428dcadc9a4cfa0d6d72

Contents?: true

Size: 1.18 KB

Versions: 27

Compression:

Stored size: 1.18 KB

Contents

module Shipit
  class CommitChecks < EphemeralCommitChecks
    OUTPUT_TTL = 10.minutes.to_i
    FINAL_STATUSES = %w(failed error success).freeze

    def initialize(commit)
      @commit = commit
    end

    def synchronize(&block)
      @lock ||= Redis::Lock.new('lock', redis, expiration: 1, timeout: 2)
      @lock.lock(&block)
    end

    def schedule
      return false if redis.get('status').present?
      synchronize do
        return false if redis.get('status').present?

        initialize_redis_state
      end
      PerformCommitChecksJob.perform_later(commit: commit)
      true
    end

    def initialize_redis_state
      redis.pipelined do
        redis.set('output', '', ex: OUTPUT_TTL)
        redis.set('status', 'scheduled', ex: OUTPUT_TTL)
      end
      @status = 'scheduled'
    end

    def status
      @status ||= redis.get('status')
    end

    def status=(status)
      redis.set('status', status)
      @status = status
    end

    def output(since: 0)
      redis.getrange('output', since, -1)
    end

    def write(output)
      redis.append('output', output)
    end

    private

    def redis
      @redis ||= Shipit.redis("commit:#{commit.id}:checks")
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
shipit-engine-0.31.0 app/models/shipit/commit_checks.rb
shipit-engine-0.30.0 app/models/shipit/commit_checks.rb
shipit-engine-0.29.0 app/models/shipit/commit_checks.rb
shipit-engine-0.28.1 app/models/shipit/commit_checks.rb
shipit-engine-0.28.0 app/models/shipit/commit_checks.rb
shipit-engine-0.27.1 app/models/shipit/commit_checks.rb
shipit-engine-0.27.0 app/models/shipit/commit_checks.rb
shipit-engine-0.26.0 app/models/shipit/commit_checks.rb
shipit-engine-0.25.1 app/models/shipit/commit_checks.rb
shipit-engine-0.25.0 app/models/shipit/commit_checks.rb
shipit-engine-0.24.0 app/models/shipit/commit_checks.rb
shipit-engine-0.23.1 app/models/shipit/commit_checks.rb
shipit-engine-0.23.0 app/models/shipit/commit_checks.rb
shipit-engine-0.22.0 app/models/shipit/commit_checks.rb
shipit-engine-0.21.0 app/models/shipit/commit_checks.rb
shipit-engine-0.20.1 app/models/shipit/commit_checks.rb
shipit-engine-0.20.0 app/models/shipit/commit_checks.rb
shipit-engine-0.19.0 app/models/shipit/commit_checks.rb
shipit-engine-0.18.1 app/models/shipit/commit_checks.rb
shipit-engine-0.18.0 app/models/shipit/commit_checks.rb