Class: Conflow::Job
- Inherits:
-
Redis::Field
- Object
- Redis::Field
- Conflow::Job
- Includes:
- Redis::Identifier, Redis::Model
- Defined in:
- lib/conflow/job.rb
Overview
Represents conflow job.
Instance Attribute Summary collapse
-
#class_name ⇒ String
Class name of the worker class.
-
#params ⇒ Hash?
Parameters needed to complete job.
-
#status ⇒ Integer
Status of the job.
Attributes included from Redis::Identifier
Attributes inherited from Redis::Field
Instance Method Summary collapse
-
#initialize ⇒ Job
constructor
Returns instance of Job.
-
#outcome ⇒ Conflow::Future
Returns promise of this job’s result.
-
#worker_type ⇒ Class
Convienience method returning Class object of the job.
Methods included from Redis::Identifier
Methods included from Redis::Model
#==, #assign_attributes, #destroy!, included
Constructor Details
#initialize ⇒ Job
Returns instance of Job. It sets status to 0 (pending) for new jobs
24 25 26 27 |
# File 'lib/conflow/job.rb', line 24 def initialize(*) super status.default(0) end |
Instance Attribute Details
#class_name ⇒ String
Returns class name of the worker class.
12 13 14 15 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 |
# File 'lib/conflow/job.rb', line 12 class Job < Conflow::Redis::Field include Conflow::Redis::Model include Conflow::Redis::Identifier has_many :successors, Conflow::Job has_many :promises, Conflow::Promise field :params, :hash field :result, :hash field :class_name, :value field :status, :value # 0 - pending, 1 - finished # Returns instance of Job. It sets status to 0 (pending) for new jobs def initialize(*) super status.default(0) end # Convienience method returning Class object of the job. # It's the class supplied in {Conflow::Flow#run} method # @return [Class] class of the job def worker_type Object.const_get(class_name.to_s) end # Returns promise of this job's result. It assumes result of the job will be a Hash. # @note Passing a {Promise} as a job parameter automatically sets the job # which produces the result as dependency of the new job # @return [Conflow::Future] future object (basis of {Promise}) # @example Running job which depends on result of another # job = run MyJob, params: { key: 400 } # run OtherJob, params: { value: job.outcome[:result] } # # now OtherJob will depend on MyJob and it will use it's :result result as it's own :value parameter def outcome Future.new(self) end end |
#params ⇒ Hash?
Returns parameters needed to complete job.
12 13 14 15 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 |
# File 'lib/conflow/job.rb', line 12 class Job < Conflow::Redis::Field include Conflow::Redis::Model include Conflow::Redis::Identifier has_many :successors, Conflow::Job has_many :promises, Conflow::Promise field :params, :hash field :result, :hash field :class_name, :value field :status, :value # 0 - pending, 1 - finished # Returns instance of Job. It sets status to 0 (pending) for new jobs def initialize(*) super status.default(0) end # Convienience method returning Class object of the job. # It's the class supplied in {Conflow::Flow#run} method # @return [Class] class of the job def worker_type Object.const_get(class_name.to_s) end # Returns promise of this job's result. It assumes result of the job will be a Hash. # @note Passing a {Promise} as a job parameter automatically sets the job # which produces the result as dependency of the new job # @return [Conflow::Future] future object (basis of {Promise}) # @example Running job which depends on result of another # job = run MyJob, params: { key: 400 } # run OtherJob, params: { value: job.outcome[:result] } # # now OtherJob will depend on MyJob and it will use it's :result result as it's own :value parameter def outcome Future.new(self) end end |
#status ⇒ Integer
Status of the job
12 13 14 15 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 |
# File 'lib/conflow/job.rb', line 12 class Job < Conflow::Redis::Field include Conflow::Redis::Model include Conflow::Redis::Identifier has_many :successors, Conflow::Job has_many :promises, Conflow::Promise field :params, :hash field :result, :hash field :class_name, :value field :status, :value # 0 - pending, 1 - finished # Returns instance of Job. It sets status to 0 (pending) for new jobs def initialize(*) super status.default(0) end # Convienience method returning Class object of the job. # It's the class supplied in {Conflow::Flow#run} method # @return [Class] class of the job def worker_type Object.const_get(class_name.to_s) end # Returns promise of this job's result. It assumes result of the job will be a Hash. # @note Passing a {Promise} as a job parameter automatically sets the job # which produces the result as dependency of the new job # @return [Conflow::Future] future object (basis of {Promise}) # @example Running job which depends on result of another # job = run MyJob, params: { key: 400 } # run OtherJob, params: { value: job.outcome[:result] } # # now OtherJob will depend on MyJob and it will use it's :result result as it's own :value parameter def outcome Future.new(self) end end |
Instance Method Details
#outcome ⇒ Conflow::Future
Note:
Passing a Promise as a job parameter automatically sets the job which produces the result as dependency of the new job
Returns promise of this job’s result. It assumes result of the job will be a Hash.
44 45 46 |
# File 'lib/conflow/job.rb', line 44 def outcome Future.new(self) end |
#worker_type ⇒ Class
Convienience method returning Class object of the job. It’s the class supplied in Flow#run method
32 33 34 |
# File 'lib/conflow/job.rb', line 32 def worker_type Object.const_get(class_name.to_s) end |