Class: Exercism::ToolingJob
- Inherits:
-
Object
- Object
- Exercism::ToolingJob
- Extended by:
- Mandate::Memoize
- Defined in:
- lib/exercism/tooling_job.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Class Method Summary collapse
- .create!(job_id, type, submission_uuid, efs_dir, language, exercise, run_in_background: false, **data) ⇒ Object
- .find(id) ⇒ Object
- .find_for_submission_uuid_and_type(submission_uuid, type) ⇒ Object
- .git_cache_key(repo, sha, dir, filepath) ⇒ Object
Instance Method Summary collapse
- #==(other) ⇒ Object
- #cancelled! ⇒ Object
- #executed!(status, output) ⇒ Object
-
#initialize(id, data) ⇒ ToolingJob
constructor
A new instance of ToolingJob.
- #locked! ⇒ Object
- #metadata ⇒ Object
- #method_missing(meth, *args) ⇒ Object
- #processed! ⇒ Object
- #respond_to_missing?(meth, include_all = true) ⇒ Boolean
- #stderr ⇒ Object
- #stdout ⇒ Object
- #store_metadata!(content) ⇒ Object
- #store_stderr!(content) ⇒ Object
- #store_stdout!(content) ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(id, data) ⇒ ToolingJob
Returns a new instance of ToolingJob.
49 50 51 52 |
# File 'lib/exercism/tooling_job.rb', line 49 def initialize(id, data) @id = id @data = data.transform_keys(&:to_sym).freeze end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args) ⇒ Object
62 63 64 65 66 |
# File 'lib/exercism/tooling_job.rb', line 62 def method_missing(meth, *args) super unless respond_to_missing?(meth) data[meth] end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
47 48 49 |
# File 'lib/exercism/tooling_job.rb', line 47 def id @id end |
Class Method Details
.create!(job_id, type, submission_uuid, efs_dir, language, exercise, run_in_background: false, **data) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/exercism/tooling_job.rb', line 11 def self.create!( job_id, type, submission_uuid, efs_dir, language, exercise, run_in_background: false, **data ) data.merge!( id: job_id, type:, submission_uuid:, efs_dir:, language:, exercise:, created_at: Time.now.utc.to_i ) queue_key = run_in_background ? key_for_queued_for_background_processing : key_for_queued redis = Exercism.redis_tooling_client redis.set("job:#{job_id}", data.to_json) redis.set("submission:#{submission_uuid}:#{type}", job_id) redis.rpush(queue_key, job_id) new(job_id, data) end |
.find(id) ⇒ Object
35 36 37 38 |
# File 'lib/exercism/tooling_job.rb', line 35 def self.find(id) json = Exercism.redis_tooling_client.get("job:#{id}") new(id, JSON.parse(json)) end |
.find_for_submission_uuid_and_type(submission_uuid, type) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/exercism/tooling_job.rb', line 40 def self.find_for_submission_uuid_and_type(submission_uuid, type) redis = Exercism.redis_tooling_client job_id = redis.get("submission:#{submission_uuid}:#{type}") json = redis.get("job:#{job_id}") new(job_id, JSON.parse(json)) end |
.git_cache_key(repo, sha, dir, filepath) ⇒ Object
7 8 9 |
# File 'lib/exercism/tooling_job.rb', line 7 def self.git_cache_key(repo, sha, dir, filepath) "#{repo}:#{sha}:#{dir}/#{filepath}" end |
Instance Method Details
#==(other) ⇒ Object
102 103 104 |
# File 'lib/exercism/tooling_job.rb', line 102 def ==(other) id == other.id end |
#cancelled! ⇒ Object
96 97 98 99 100 |
# File 'lib/exercism/tooling_job.rb', line 96 def cancelled! redis = Exercism.redis_tooling_client redis.lrem(key_for_queued, 1, id) redis.rpush(key_for_cancelled, id) end |
#executed!(status, output) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/exercism/tooling_job.rb', line 74 def executed!(status, output) redis = Exercism.redis_tooling_client redis.lrem(key_for_queued, 1, id) redis.lrem(key_for_locked, 1, id) redis.rpush(key_for_executed, id) redis.set( "job:#{id}", data.merge( execution_status: status, execution_output: output ).to_json ) end |
#locked! ⇒ Object
68 69 70 71 72 |
# File 'lib/exercism/tooling_job.rb', line 68 def locked! redis = Exercism.redis_tooling_client redis.lrem(key_for_queued, 1, id) redis.rpush(key_for_locked, id) end |
#metadata ⇒ Object
126 127 128 129 130 |
# File 'lib/exercism/tooling_job.rb', line 126 def JSON.parse(read_s3_file('metadata.json')) rescue JSON::ParserError {} end |
#processed! ⇒ Object
89 90 91 92 93 94 |
# File 'lib/exercism/tooling_job.rb', line 89 def processed! redis = Exercism.redis_tooling_client redis.lrem(key_for_executed, 1, id) redis.del("job:#{id}") redis.del("submission:#{data[:submission_uuid]}:#{data[:type]}") end |
#respond_to_missing?(meth, include_all = true) ⇒ Boolean
58 59 60 |
# File 'lib/exercism/tooling_job.rb', line 58 def respond_to_missing?(meth, include_all = true) data.key?(meth) || super end |
#stderr ⇒ Object
122 123 124 |
# File 'lib/exercism/tooling_job.rb', line 122 def stderr read_s3_file(:stderr) end |
#stdout ⇒ Object
118 119 120 |
# File 'lib/exercism/tooling_job.rb', line 118 def stdout read_s3_file(:stdout) end |
#store_metadata!(content) ⇒ Object
114 115 116 |
# File 'lib/exercism/tooling_job.rb', line 114 def (content) write_s3_file!('metadata.json', content.to_json) end |
#store_stderr!(content) ⇒ Object
110 111 112 |
# File 'lib/exercism/tooling_job.rb', line 110 def store_stderr!(content) write_s3_file!(:stderr, content) end |
#store_stdout!(content) ⇒ Object
106 107 108 |
# File 'lib/exercism/tooling_job.rb', line 106 def store_stdout!(content) write_s3_file!(:stdout, content) end |
#to_h ⇒ Object
54 55 56 |
# File 'lib/exercism/tooling_job.rb', line 54 def to_h data.to_h end |