Class: Rosette::Queuing::Commits::FinalizeStage

Inherits:
Stage
  • Object
show all
Defined in:
lib/rosette/queuing/commits/finalize_stage.rb

Overview

Performs cleanup tasks for the given commit as defined by the configured translation management system.

See Also:

  • RepoConfig

Constant Summary collapse

CONSECUTIVE_FINALIZE_DELAY =

The number of seconds to wait in between consecutive pulls. This value will be passed to the queue implementation, as delay is handled at the queue layer.

10 * 60

Constants inherited from Stage

Stage::PhraseStatus

Instance Attribute Summary

Attributes inherited from Stage

#commit_log, #logger, #repo_config, #rosette_config

Instance Method Summary collapse

Methods inherited from Stage

accepts, accepts?, for_commit_log, #initialize

Constructor Details

This class inherits a constructor from Rosette::Queuing::Commits::Stage

Instance Method Details

#execute!void

This method returns an undefined value.

Executes this stage and updates the commit log. If the commit has been fully translated, the commit log will be updated with a FINALIZED status, and the finalize method will be called on the translation management system. If the commit has not been fully translated, the commit log's status won't be updated and finalize will not be called. In both cases, commit log locale entries will be updated to track translation progress.


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/rosette/queuing/commits/finalize_stage.rb', line 28

def execute!
  logger.info("Finalizing commit #{commit_log.commit_id}")

  status = repo_config.tms.status(commit_log.commit_id)

  repo_config.locales.each do |locale|
    locale_code = locale.code

    rosette_config.datastore.add_or_update_commit_log_locale(
      commit_log.commit_id, locale_code, status.locale_count(locale_code)
    )
  end

  if status.fully_translated?
    repo_config.tms.finalize(commit_log.commit_id)
    commit_log.finalize
    save_commit_log
  end

  logger.info("Finished finalizing commit #{commit_log.commit_id}")
end

#to_jobCommitJob

Converts this stage to a job that can be enqueued. This method should be called after #execute!, meaning the commit log has been updated to the next status in the pipeline. If that next status also happens to be PUSHED, this method adds a delay to avoid finalizing too often. If the chosen queue implementation does not support delays, setting this value should be a safe no-op (i.e. have no adverse side-effects).

Returns:


58
59
60
61
62
63
64
# File 'lib/rosette/queuing/commits/finalize_stage.rb', line 58

def to_job
  super.tap do |job|
    if commit_log.status == PhraseStatus::PUSHED
      job.set_delay(CONSECUTIVE_FINALIZE_DELAY)
    end
  end
end