Class: TinyCI::Scheduler

Inherits:
Object
  • Object
show all
Includes:
GitUtils, Logging, Subprocesses
Defined in:
lib/tinyci/scheduler.rb

Overview

Manages the execution of test jobs. Responsible for deciding which commits need to be built and tested. Also manages the pidfile. This is the main entrypoint for TinyCI.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from GitUtils

#git_cmd, #git_directory_path, #inside_bare_repo?, #inside_git_directory?, #inside_repository?, #inside_work_tree?, #repo_root

Methods included from Subprocesses

#execute, #execute_pipe, #execute_stream

Constructor Details

#initialize(working_dir: nil, logger: nil, commit: nil, runner_class: Runner) ⇒ Scheduler

Constructor, allows injection of configuration and custom Runner class. Config params are passed to Runner instances.

Parameters:

  • working_dir (String) (defaults to: nil)

    The working directory to execute against

  • logger (Logger) (defaults to: nil)

    Logger object

  • commit (String) (defaults to: nil)

    specific git object to run against

  • runner_class (TinyCI::Runner) (defaults to: Runner)

    Injection of Runner dependency



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/tinyci/scheduler.rb', line 26

def initialize(
    working_dir: nil,
    logger: nil,
    commit: nil,
    runner_class: Runner
  )

  @working_dir = working_dir || repo_root
  @logger = logger
  @runner_class = runner_class
  @commit = commit
end

Instance Attribute Details

#working_dirString (readonly)

The working directory to execute against

Returns:

  • (String)

    the current value of working_dir



12
13
14
# File 'lib/tinyci/scheduler.rb', line 12

def working_dir
  @working_dir
end

Instance Method Details

#run!Boolean

Runs the TinyCI system against the relevant commits. Also sets up the pidfile.

Returns:

  • (Boolean)

    true if all commits built and tested successfully, false otherwise



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/tinyci/scheduler.rb', line 42

def run!
  pid = PidFile.new(pidfile: 'tinyci.pid', piddir: @working_dir)
  
  result = if @commit
    run_commit @commit
  else
    run_all_commits
  end
  
  pid.release
  
  result
end