Class: Conflow::Job

Inherits:
Redis::Field show all
Includes:
Redis::Identifier, Redis::Model
Defined in:
lib/conflow/job.rb

Overview

Represents conflow job.

Instance Attribute Summary collapse

Attributes included from Redis::Identifier

#id

Attributes inherited from Redis::Field

#key

Instance Method Summary collapse

Methods included from Redis::Identifier

included

Methods included from Redis::Model

#==, #assign_attributes, #destroy!, included

Constructor Details

#initializeJob

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_nameString

Returns class name of the worker class.

Returns:

  • (String)

    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

#paramsHash?

Returns parameters needed to complete job.

Returns:

  • (Hash, nil)

    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

#statusInteger

Status of the job

Returns:

  • (Integer)

    0 - pending, 1 - finished



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

#outcomeConflow::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.

Examples:

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

Returns:



44
45
46
# File 'lib/conflow/job.rb', line 44

def outcome
  Future.new(self)
end

#worker_typeClass

Convienience method returning Class object of the job. It’s the class supplied in Flow#run method

Returns:

  • (Class)

    class of the job



32
33
34
# File 'lib/conflow/job.rb', line 32

def worker_type
  Object.const_get(class_name.to_s)
end