Class: OpenWFE::Job
- Inherits:
-
Object
- Object
- OpenWFE::Job
- Defined in:
- lib/openwfe/util/scheduler.rb
Overview
The parent class for scheduled jobs.
Constant Summary collapse
- @@last_given_id =
0
Instance Attribute Summary collapse
-
#block ⇒ Object
The block to execute at trigger time.
-
#job_id ⇒ Object
The identifier for the job.
-
#params ⇒ Object
readonly
Keeping a copy of the initialization params of the job.
-
#scheduler ⇒ Object
readonly
A reference to the scheduler.
-
#tags ⇒ Object
An array of tags.
Instance Method Summary collapse
-
#has_tag?(tag) ⇒ Boolean
Returns true if this job sports the given tag.
-
#initialize(scheduler, job_id, params, &block) ⇒ Job
constructor
A new instance of Job.
-
#unschedule ⇒ Object
Removes (cancels) this job from its scheduler.
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
#block ⇒ Object
The block to execute at trigger time
910 911 912 |
# File 'lib/openwfe/util/scheduler.rb', line 910 def block @block end |
#job_id ⇒ Object
The identifier for the job
900 901 902 |
# File 'lib/openwfe/util/scheduler.rb', line 900 def job_id @job_id end |
#params ⇒ Object (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 |
#scheduler ⇒ Object (readonly)
A reference to the scheduler
915 916 917 |
# File 'lib/openwfe/util/scheduler.rb', line 915 def scheduler @scheduler end |
#tags ⇒ Object
An array of tags
905 906 907 |
# File 'lib/openwfe/util/scheduler.rb', line 905 def @tags end |
Instance Method Details
#has_tag?(tag) ⇒ Boolean
Returns true if this job sports the given tag
949 950 951 952 |
# File 'lib/openwfe/util/scheduler.rb', line 949 def has_tag? (tag) @tags.include?(tag) end |
#unschedule ⇒ Object
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 |