Class: OpenWFE::Job

Inherits:
Object
  • Object
show all
Defined in:
lib/openwfe/util/scheduler.rb

Overview

The parent class for scheduled jobs.

Direct Known Subclasses

AtJob, CronJob

Constant Summary collapse

@@last_given_id =
0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scheduler, job_id, params, &block) ⇒ Job

Returns a new instance of Job.



923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
# File 'lib/openwfe/util/scheduler.rb', line 923

def initialize (scheduler, job_id, params, &block)

    @scheduler = scheduler
    @block = block

    if job_id
        @job_id = job_id
    else
        JOB_ID_LOCK.synchronize do
            @job_id = @@last_given_id
            @@last_given_id = @job_id + 1
        end
    end

    @params = params

    #@tags = Array(tags).collect { |tag| tag.to_s }
        # making sure we have an array of String tags

    @tags = Array(params[:tags])
        # any tag is OK
end

Instance Attribute Details

#blockObject

The block to execute at trigger time



910
911
912
# File 'lib/openwfe/util/scheduler.rb', line 910

def block
  @block
end

#job_idObject

The identifier for the job



900
901
902
# File 'lib/openwfe/util/scheduler.rb', line 900

def job_id
  @job_id
end

#paramsObject (readonly)

Keeping a copy of the initialization params of the job.



920
921
922
# File 'lib/openwfe/util/scheduler.rb', line 920

def params
  @params
end

#schedulerObject (readonly)

A reference to the scheduler



915
916
917
# File 'lib/openwfe/util/scheduler.rb', line 915

def scheduler
  @scheduler
end

#tagsObject

An array of tags



905
906
907
# File 'lib/openwfe/util/scheduler.rb', line 905

def tags
  @tags
end

Instance Method Details

#has_tag?(tag) ⇒ Boolean

Returns true if this job sports the given tag

Returns:

  • (Boolean)


949
950
951
952
# File 'lib/openwfe/util/scheduler.rb', line 949

def has_tag? (tag)

    @tags.include?(tag)
end

#unscheduleObject

Removes (cancels) this job from its scheduler.



957
958
959
960
# File 'lib/openwfe/util/scheduler.rb', line 957

def unschedule

    @scheduler.unschedule(@job_id)
end