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
Constructor Details
#initialize(tag: Bitferry.tag, modified: DateTime.now) ⇒ Task
Returns a new instance of Task.
534
535
536
537
538
539
|
# File 'lib/bitferry.rb', line 534
def initialize(tag: Bitferry.tag, modified: DateTime.now)
@tag = tag
@generation = 0
@modified = modified
end
|
Instance Attribute Details
#generation ⇒ Object
Returns the value of attribute generation.
496
497
498
|
# File 'lib/bitferry.rb', line 496
def generation
@generation
end
|
#modified ⇒ Object
Returns the value of attribute modified.
499
500
501
|
# File 'lib/bitferry.rb', line 499
def modified
@modified
end
|
#tag ⇒ Object
Returns the value of attribute tag.
493
494
495
|
# File 'lib/bitferry.rb', line 493
def tag
@tag
end
|
Class Method Details
.[](tag) ⇒ Object
588
|
# File 'lib/bitferry.rb', line 588
def self.[](tag) = @@registry[tag]
|
.delete(*tags) ⇒ Object
519
520
521
522
523
524
525
526
527
528
529
530
531
|
# File 'lib/bitferry.rb', line 519
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
616
|
# File 'lib/bitferry.rb', line 616
def self.intact = live.filter { |task| task.intact? }
|
.live ⇒ Object
607
|
# File 'lib/bitferry.rb', line 607
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
592
|
# File 'lib/bitferry.rb', line 592
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
596
597
598
599
600
601
|
# File 'lib/bitferry.rb', line 596
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
505
506
507
508
509
|
# File 'lib/bitferry.rb', line 505
def self.new(*args, **opts)
task = allocate
task.send(:create, *args, **opts)
register(task)
end
|
.register(task) ⇒ Object
TODO settle on task with the latest timestamp
613
|
# File 'lib/bitferry.rb', line 613
def self.register(task) = @@registry[task.tag] = task
|
.registered ⇒ Object
604
|
# File 'lib/bitferry.rb', line 604
def self.registered = @@registry.values
|
.reset ⇒ Object
610
|
# File 'lib/bitferry.rb', line 610
def self.reset = @@registry = {}
|
.restore(hash) ⇒ Object
512
513
514
515
516
|
# File 'lib/bitferry.rb', line 512
def self.restore(hash)
task = allocate
task.send(:restore, hash)
register(task)
end
|
.stale ⇒ Object
619
|
# File 'lib/bitferry.rb', line 619
def self.stale = live.filter { |task| !task.intact? }
|
Instance Method Details
#commit ⇒ Object
580
581
582
583
584
585
|
# File 'lib/bitferry.rb', line 580
def commit
case @state
when :pristine then format
when :removing then @state = nil
end
end
|
#create(*args, **opts) ⇒ Object
542
543
544
545
546
|
# File 'lib/bitferry.rb', line 542
def create(*args, **opts)
initialize(*args, **opts)
@state = :pristine
touch
end
|
#delete ⇒ Object
573
574
575
576
577
|
# File 'lib/bitferry.rb', line 573
def delete
touch
@state = :removing
log.info("marked task #{tag} for removal")
end
|
#externalize ⇒ Object
559
560
561
562
563
564
|
# File 'lib/bitferry.rb', line 559
def externalize
{
task: tag,
modified: @modified
}.compact
end
|
#live? ⇒ Boolean
567
|
# File 'lib/bitferry.rb', line 567
def live? = !@state.nil? && @state != :removing
|
#process_options ⇒ Object
As a mandatory option it should never be nil
502
|
# File 'lib/bitferry.rb', line 502
def process_options = @process_options.nil? ? [] : @process_options
|
#restore(hash) ⇒ Object
549
550
551
552
|
# File 'lib/bitferry.rb', line 549
def restore(hash)
@state = :intact
log.info("restored task #{tag}")
end
|
#restore_endpoint(x) ⇒ Object
FIXME move to Endpoint#restore
556
|
# File 'lib/bitferry.rb', line 556
def restore_endpoint(x) = Endpoint::ROUTE.fetch(x.fetch(:endpoint).intern).restore(x)
|
#touch ⇒ Object
570
|
# File 'lib/bitferry.rb', line 570
def touch = @modified = DateTime.now
|