Module: TallyJobs
- Defined in:
- lib/tally_jobs.rb,
lib/tally_jobs/engine.rb,
lib/tally_jobs/configs.rb,
lib/tally_jobs/version.rb,
lib/tally_jobs/tally_data.rb,
lib/tally_jobs/jobs_counter.rb,
lib/tally_jobs/configured_job.rb,
lib/generators/tally_jobs/install_generator.rb
Defined Under Namespace
Modules: ConfiguredJob, CounterStore, Generators, TallyData
Classes: Configs, Engine, Error, JobsCounter
Constant Summary
collapse
- MUTEX =
start a thread to flush in-memory enqueued jobs each interval time
Mutex.new
- VERSION =
"0.0.1"
Class Method Summary
collapse
Class Method Details
.restart ⇒ Object
60
61
62
63
64
|
# File 'lib/tally_jobs.rb', line 60
def restart
stop
TallyJobs.runnable = true
start
end
|
.setup {|configs| ... } ⇒ Object
16
17
18
19
20
|
# File 'lib/tally_jobs.rb', line 16
def setup
yield configs
TallyJobs.start
end
|
.start ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/tally_jobs.rb', line 28
def start
MUTEX.synchronize do
@tally_thread = nil if !@tally_thread&.alive?
@tally_thread ||= Thread.new do
TallyJobs.configs.logger&.info("[TallyJobs] started ...")
while true
break unless TallyJobs.runnable
sleep(TallyJobs.configs.interval || 300)
JobsCounter.collect_then_perform_later
end
end
end
end
|
.stop ⇒ Object
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/tally_jobs.rb', line 49
def stop
flush
TallyJobs.runnable = false
if @tally_thread && @tally_thread.alive?
@tally_thread.wakeup
@tally_thread.join
end
TallyJobs.configs.logger&.info("[TallyJobs] stop ...")
end
|