Class: Bitferry::Task
Constant Summary
collapse
- ROUTE =
{
copy: Rclone::Copy,
update: Rclone::Update,
synchronize: Rclone::Synchronize,
equalize: Rclone::Equalize,
backup: Restic::Backup,
restore: Restic::Restore
}
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Logging
log, log, log=
Constructor Details
#initialize(tag: Bitferry.tag, modified: nil, include: [], exclude: []) ⇒ Task
Returns a new instance of Task.
569
570
571
572
573
574
575
576
577
578
579
580
|
# File 'lib/bitferry.rb', line 569
def initialize(tag: Bitferry.tag, modified: nil, include: [], exclude: [])
@tag = tag
@generation = 0
@include = include
@exclude = exclude
@modified = case modified
when nil then DateTime.now
when DateTime then modified
else DateTime.parse(modified)
end
end
|
Instance Attribute Details
#exclude ⇒ Object
Returns the value of attribute exclude.
534
535
536
|
# File 'lib/bitferry.rb', line 534
def exclude
@exclude
end
|
#generation ⇒ Object
Returns the value of attribute generation.
528
529
530
|
# File 'lib/bitferry.rb', line 528
def generation
@generation
end
|
#include ⇒ Object
Returns the value of attribute include.
534
535
536
|
# File 'lib/bitferry.rb', line 534
def include
@include
end
|
#modified ⇒ Object
Returns the value of attribute modified.
531
532
533
|
# File 'lib/bitferry.rb', line 531
def modified
@modified
end
|
#tag ⇒ Object
Returns the value of attribute tag.
525
526
527
|
# File 'lib/bitferry.rb', line 525
def tag
@tag
end
|
Class Method Details
.[](tag) ⇒ Object
641
|
# File 'lib/bitferry.rb', line 641
def self.[](tag) = @@registry[tag]
|
.delete(*tags) ⇒ Object
554
555
556
557
558
559
560
561
562
563
564
565
566
|
# File 'lib/bitferry.rb', line 554
def self.delete(*tags)
process = []
tags.each do |tag|
case (tasks = Task.lookup(tag)).size
when 0 then log.warn("no tasks matching (partial) tag #{tag}")
when 1 then process += tasks
else
tags = tasks.collect { |v| v.tag }.join(', ')
raise ArgumentError, "multiple tasks matching (partial) tag #{tag}: #{tags}"
end
end
process.each { |task| task.delete }
end
|
.intact ⇒ Object
677
|
# File 'lib/bitferry.rb', line 677
def self.intact = live.filter { |task| task.intact? }
|
.live ⇒ Object
660
|
# File 'lib/bitferry.rb', line 660
def self.live = registered.filter { |task| task.live? }
|
.lookup(*tags) ⇒ Object
Return list of registered tasks whose tags match at least one of specified partial tags
645
|
# File 'lib/bitferry.rb', line 645
def self.lookup(*tags) = match(tags, registered)
|
.match(tags, tasks) ⇒ Object
Return list of specified tasks whose tags match at least one of specified partial tags
649
650
651
652
653
654
|
# File 'lib/bitferry.rb', line 649
def self.match(tags, tasks)
rxs = tags.collect { |x| Regexp.new(x) }
tasks.filter do |task|
rxs.any? { |rx| !(rx =~ task.tag).nil? }
end
end
|
.new(*args, **opts) ⇒ Object
540
541
542
543
544
|
# File 'lib/bitferry.rb', line 540
def self.new(*args, **opts)
task = allocate
task.send(:create, *args, **opts)
register(task)
end
|
.register(task) ⇒ Object
666
667
668
669
670
671
672
673
674
675
|
# File 'lib/bitferry.rb', line 666
def self.register(task)
if (xtag = @@registry[task.tag]).nil?
@@registry[task.tag] = task
elsif xtag.modified < task.modified
@@registry[task.tag] = task
else
xtag
end
end
|
.registered ⇒ Object
657
|
# File 'lib/bitferry.rb', line 657
def self.registered = @@registry.values
|
.reset ⇒ Object
663
|
# File 'lib/bitferry.rb', line 663
def self.reset = @@registry = {}
|
.restore(hash) ⇒ Object
547
548
549
550
551
|
# File 'lib/bitferry.rb', line 547
def self.restore(hash)
task = allocate
task.send(:restore, hash)
register(task)
end
|
.stale ⇒ Object
680
|
# File 'lib/bitferry.rb', line 680
def self.stale = live.filter { |task| !task.intact? }
|
Instance Method Details
#commit ⇒ Object
625
626
627
628
629
630
|
# File 'lib/bitferry.rb', line 625
def commit
case @state
when :pristine then format
when :removing then @state = nil
end
end
|
#create(*args, **opts) ⇒ Object
583
584
585
586
587
|
# File 'lib/bitferry.rb', line 583
def create(*args, **opts)
initialize(*args, **opts)
@state = :pristine
touch
end
|
#delete ⇒ Object
618
619
620
621
622
|
# File 'lib/bitferry.rb', line 618
def delete
touch
@state = :removing
log.info("marked task #{tag} for removal")
end
|
#externalize ⇒ Object
602
603
604
605
606
607
608
609
|
# File 'lib/bitferry.rb', line 602
def externalize
{
task: tag,
modified: modified,
include: include.empty? ? nil : include,
exclude: exclude.empty? ? nil : exclude
}.compact
end
|
#live? ⇒ Boolean
612
|
# File 'lib/bitferry.rb', line 612
def live? = !@state.nil? && @state != :removing
|
#process_options ⇒ Object
As a mandatory option it should never be nil
537
|
# File 'lib/bitferry.rb', line 537
def process_options = @process_options.nil? ? [] : @process_options
|
#restore(hash) ⇒ Object
590
591
592
593
594
595
|
# File 'lib/bitferry.rb', line 590
def restore(hash)
@include = hash.fetch(:include, [])
@exclude = hash.fetch(:exclude, [])
@state = :intact
log.info("restored task #{tag}")
end
|
#restore_endpoint(x) ⇒ Object
FIXME move to Endpoint#restore
599
|
# File 'lib/bitferry.rb', line 599
def restore_endpoint(x) = Endpoint::ROUTE.fetch(x.fetch(:endpoint).intern).restore(x)
|
#show_filters ⇒ Object
633
634
635
636
637
638
|
# File 'lib/bitferry.rb', line 633
def show_filters
xs = []
xs << 'include: ' + include.join(',') unless include.empty?
xs << 'exclude: ' + exclude.join(',') unless exclude.empty?
xs.join(' ').to_s
end
|
#touch ⇒ Object
615
|
# File 'lib/bitferry.rb', line 615
def touch = @modified = DateTime.now
|