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!(type, submission_uuid, language, exercise, run_in_background: false, **data) ⇒ Object
- .find(id) ⇒ Object
- .find_for_submission_uuid_and_type(submission_uuid, type) ⇒ 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.
48 49 50 51 |
# File 'lib/exercism/tooling_job.rb', line 48 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
61 62 63 64 65 |
# File 'lib/exercism/tooling_job.rb', line 61 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.
46 47 48 |
# File 'lib/exercism/tooling_job.rb', line 46 def id @id end |
Class Method Details
.create!(type, submission_uuid, language, exercise, run_in_background: false, **data) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/exercism/tooling_job.rb', line 8 def self.create!(type, submission_uuid, language, exercise, run_in_background: false, **data) job_id = SecureRandom.uuid.tr('-', '') data.merge!( id: job_id, submission_uuid:, type:, 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.multi do |transaction| transaction.set( "job:#{job_id}", data.to_json ) transaction.rpush(queue_key, job_id) transaction.set("submission:#{submission_uuid}:#{type}", job_id) end new(job_id, data) end |
.find(id) ⇒ Object
34 35 36 37 |
# File 'lib/exercism/tooling_job.rb', line 34 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
39 40 41 42 43 44 |
# File 'lib/exercism/tooling_job.rb', line 39 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 |
Instance Method Details
#==(other) ⇒ Object
109 110 111 |
# File 'lib/exercism/tooling_job.rb', line 109 def ==(other) id == other.id end |
#cancelled! ⇒ Object
101 102 103 104 105 106 107 |
# File 'lib/exercism/tooling_job.rb', line 101 def cancelled! redis = Exercism.redis_tooling_client redis.multi do |transaction| transaction.lrem(key_for_queued, 1, id) transaction.rpush(key_for_cancelled, id) end end |
#executed!(status, output) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/exercism/tooling_job.rb', line 75 def executed!(status, output) redis = Exercism.redis_tooling_client redis.multi do |transaction| transaction.lrem(key_for_queued, 1, id) transaction.lrem(key_for_locked, 1, id) transaction.rpush(key_for_executed, id) transaction.set( "job:#{id}", data.merge( execution_status: status, execution_output: output ).to_json ) end end |
#locked! ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/exercism/tooling_job.rb', line 67 def locked! redis = Exercism.redis_tooling_client redis.multi do |transaction| transaction.lrem(key_for_queued, 1, id) transaction.rpush(key_for_locked, id) end end |
#metadata ⇒ Object
133 134 135 136 137 |
# File 'lib/exercism/tooling_job.rb', line 133 def JSON.parse(read_s3_file('metadata.json')) rescue JSON::ParserError {} end |
#processed! ⇒ Object
92 93 94 95 96 97 98 99 |
# File 'lib/exercism/tooling_job.rb', line 92 def processed! redis = Exercism.redis_tooling_client redis.multi do |transaction| transaction.lrem(key_for_executed, 1, id) transaction.del("job:#{id}") transaction.del("submission:#{data[:submission_uuid]}:#{data[:type]}") end end |
#respond_to_missing?(meth, include_all = true) ⇒ Boolean
57 58 59 |
# File 'lib/exercism/tooling_job.rb', line 57 def respond_to_missing?(meth, include_all = true) data.key?(meth) || super end |
#stderr ⇒ Object
129 130 131 |
# File 'lib/exercism/tooling_job.rb', line 129 def stderr read_s3_file(:stderr) end |
#stdout ⇒ Object
125 126 127 |
# File 'lib/exercism/tooling_job.rb', line 125 def stdout read_s3_file(:stdout) end |
#store_metadata!(content) ⇒ Object
121 122 123 |
# File 'lib/exercism/tooling_job.rb', line 121 def (content) write_s3_file!('metadata.json', content.to_json) end |
#store_stderr!(content) ⇒ Object
117 118 119 |
# File 'lib/exercism/tooling_job.rb', line 117 def store_stderr!(content) write_s3_file!(:stderr, content) end |
#store_stdout!(content) ⇒ Object
113 114 115 |
# File 'lib/exercism/tooling_job.rb', line 113 def store_stdout!(content) write_s3_file!(:stdout, content) end |
#to_h ⇒ Object
53 54 55 |
# File 'lib/exercism/tooling_job.rb', line 53 def to_h data.to_h end |