Class: Rosette::Queuing::Commits::CommitJob
- Defined in:
- lib/rosette/queuing/commits/commit_job.rb
Overview
Encapsulates processing a commit at a specific stage in the process.
Constant Summary
Constants inherited from Job
Job::DEFAULT_DELAY, Job::DEFAULT_QUEUE_NAME
Instance Attribute Summary collapse
-
#commit_id ⇒ String
readonly
The commit id to process.
-
#repo_name ⇒ String
readonly
The name of the repo the commit belongs to.
-
#status ⇒ String
readonly
The current status of the commit (mostly for display and tracking purposes).
Class Method Summary collapse
-
.from_stage(stage) ⇒ CommitJob
Creates a new [CommitJob] object from a [Stage].
Instance Method Summary collapse
-
#initialize(repo_name, commit_id, status = nil) ⇒ CommitJob
constructor
Creates a new instance of [CommitJob].
-
#to_args ⇒ Array
Converts this job into a list of arguments that should be able to be easily serialized for placement into a queue.
-
#work(rosette_config, logger) ⇒ void
Fetches the commit log, instantiates a new [CommitConductor] and advances the commit to the next stage.
Methods inherited from Job
#delay, queue_name, #set_delay, set_queue_name
Constructor Details
#initialize(repo_name, commit_id, status = nil) ⇒ CommitJob
Creates a new instance of [CommitJob].
40 41 42 43 44 |
# File 'lib/rosette/queuing/commits/commit_job.rb', line 40 def initialize(repo_name, commit_id, status = nil) @repo_name = repo_name @commit_id = commit_id @status = status end |
Instance Attribute Details
#commit_id ⇒ String (readonly)
Returns the commit id to process.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/rosette/queuing/commits/commit_job.rb', line 16 class CommitJob < Job attr_reader :repo_name, :commit_id, :status set_queue_name 'commits' # Creates a new [CommitJob] object from a [Stage]. # # @param [Stage] stage The stage to get parameters from. # @return [CommitJob] def self.from_stage(stage) new( stage.repo_config.name, stage.commit_log.commit_id, stage.commit_log.status ) end # Creates a new instance of [CommitJob]. # # @param [String] repo_name The name of the repo the commit belongs to. # @param [String] commit_id The commit id to process. # @param [String] status The current status of the commit (mostly for # display and tracking purposes). # @return [CommitJob] def initialize(repo_name, commit_id, status = nil) @repo_name = repo_name @commit_id = commit_id @status = status end # Converts this job into a list of arguments that should be able to be # easily serialized for placement into a queue. These should be the # same values the constructor accepts, since +CommitJob+s will be # re-instantiated with these arguments when executed. # # @return [Array] def to_args [repo_name, commit_id, status] end # Fetches the commit log, instantiates a new [CommitConductor] and # advances the commit to the next stage. If the commit log does not # exist in the database, one will be created. # # @param [Configurator] rosette_config # @param [Logger] logger # @return [void] def work(rosette_config, logger) commit_log = find_or_create_commit_log(rosette_config) conductor = CommitConductor.new(rosette_config, repo_name, logger) conductor.advance(commit_log) end protected def find_or_create_commit_log(rosette_config) # god this is cumbersome... the datastore could really use a refactor if commit_log = lookup_commit_log(rosette_config) commit_log else rosette_config.datastore.add_or_update_commit_log( repo_name, commit_id, nil, Rosette::DataStores::PhraseStatus::NOT_SEEN ) lookup_commit_log(rosette_config) end end def lookup_commit_log(rosette_config) rosette_config.datastore.lookup_commit_log( repo_name, commit_id ) end end |
#repo_name ⇒ String (readonly)
Returns the name of the repo the commit belongs to.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/rosette/queuing/commits/commit_job.rb', line 16 class CommitJob < Job attr_reader :repo_name, :commit_id, :status set_queue_name 'commits' # Creates a new [CommitJob] object from a [Stage]. # # @param [Stage] stage The stage to get parameters from. # @return [CommitJob] def self.from_stage(stage) new( stage.repo_config.name, stage.commit_log.commit_id, stage.commit_log.status ) end # Creates a new instance of [CommitJob]. # # @param [String] repo_name The name of the repo the commit belongs to. # @param [String] commit_id The commit id to process. # @param [String] status The current status of the commit (mostly for # display and tracking purposes). # @return [CommitJob] def initialize(repo_name, commit_id, status = nil) @repo_name = repo_name @commit_id = commit_id @status = status end # Converts this job into a list of arguments that should be able to be # easily serialized for placement into a queue. These should be the # same values the constructor accepts, since +CommitJob+s will be # re-instantiated with these arguments when executed. # # @return [Array] def to_args [repo_name, commit_id, status] end # Fetches the commit log, instantiates a new [CommitConductor] and # advances the commit to the next stage. If the commit log does not # exist in the database, one will be created. # # @param [Configurator] rosette_config # @param [Logger] logger # @return [void] def work(rosette_config, logger) commit_log = find_or_create_commit_log(rosette_config) conductor = CommitConductor.new(rosette_config, repo_name, logger) conductor.advance(commit_log) end protected def find_or_create_commit_log(rosette_config) # god this is cumbersome... the datastore could really use a refactor if commit_log = lookup_commit_log(rosette_config) commit_log else rosette_config.datastore.add_or_update_commit_log( repo_name, commit_id, nil, Rosette::DataStores::PhraseStatus::NOT_SEEN ) lookup_commit_log(rosette_config) end end def lookup_commit_log(rosette_config) rosette_config.datastore.lookup_commit_log( repo_name, commit_id ) end end |
#status ⇒ String (readonly)
Returns the current status of the commit (mostly for display and tracking purposes).
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/rosette/queuing/commits/commit_job.rb', line 16 class CommitJob < Job attr_reader :repo_name, :commit_id, :status set_queue_name 'commits' # Creates a new [CommitJob] object from a [Stage]. # # @param [Stage] stage The stage to get parameters from. # @return [CommitJob] def self.from_stage(stage) new( stage.repo_config.name, stage.commit_log.commit_id, stage.commit_log.status ) end # Creates a new instance of [CommitJob]. # # @param [String] repo_name The name of the repo the commit belongs to. # @param [String] commit_id The commit id to process. # @param [String] status The current status of the commit (mostly for # display and tracking purposes). # @return [CommitJob] def initialize(repo_name, commit_id, status = nil) @repo_name = repo_name @commit_id = commit_id @status = status end # Converts this job into a list of arguments that should be able to be # easily serialized for placement into a queue. These should be the # same values the constructor accepts, since +CommitJob+s will be # re-instantiated with these arguments when executed. # # @return [Array] def to_args [repo_name, commit_id, status] end # Fetches the commit log, instantiates a new [CommitConductor] and # advances the commit to the next stage. If the commit log does not # exist in the database, one will be created. # # @param [Configurator] rosette_config # @param [Logger] logger # @return [void] def work(rosette_config, logger) commit_log = find_or_create_commit_log(rosette_config) conductor = CommitConductor.new(rosette_config, repo_name, logger) conductor.advance(commit_log) end protected def find_or_create_commit_log(rosette_config) # god this is cumbersome... the datastore could really use a refactor if commit_log = lookup_commit_log(rosette_config) commit_log else rosette_config.datastore.add_or_update_commit_log( repo_name, commit_id, nil, Rosette::DataStores::PhraseStatus::NOT_SEEN ) lookup_commit_log(rosette_config) end end def lookup_commit_log(rosette_config) rosette_config.datastore.lookup_commit_log( repo_name, commit_id ) end end |
Class Method Details
.from_stage(stage) ⇒ CommitJob
Creates a new [CommitJob] object from a [Stage].
25 26 27 28 29 30 31 |
# File 'lib/rosette/queuing/commits/commit_job.rb', line 25 def self.from_stage(stage) new( stage.repo_config.name, stage.commit_log.commit_id, stage.commit_log.status ) end |
Instance Method Details
#to_args ⇒ Array
Converts this job into a list of arguments that should be able to be easily serialized for placement into a queue. These should be the same values the constructor accepts, since CommitJobs will be re-instantiated with these arguments when executed.
52 53 54 |
# File 'lib/rosette/queuing/commits/commit_job.rb', line 52 def to_args [repo_name, commit_id, status] end |
#work(rosette_config, logger) ⇒ void
This method returns an undefined value.
Fetches the commit log, instantiates a new [CommitConductor] and advances the commit to the next stage. If the commit log does not exist in the database, one will be created.
63 64 65 66 67 |
# File 'lib/rosette/queuing/commits/commit_job.rb', line 63 def work(rosette_config, logger) commit_log = find_or_create_commit_log(rosette_config) conductor = CommitConductor.new(rosette_config, repo_name, logger) conductor.advance(commit_log) end |