Class: Aeternitas::Pollable::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/aeternitas/pollable/configuration.rb

Overview

Holds the configuration of a pollable class

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Creates a new Configuration with default options



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/aeternitas/pollable/configuration.rb', line 34

def initialize
  @polling_frequency = Aeternitas::PollingFrequency::DAILY
  @before_polling = []
  @after_polling = []
  @guard_options = {
    key: ->(obj) { return obj.class.name.to_s },
    timeout: 10.minutes,
    cooldown: 5.seconds
  }
  @deactivation_errors = []
  @ignored_errors = []
  @queue = 'polling'
  @sleep_on_guard_locked = true
end

Instance Attribute Details

#after_pollingObject

Methods to be run after each successful poll



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/aeternitas/pollable/configuration.rb', line 23

class Configuration
  attr_accessor :deactivation_errors,
                :before_polling,
                :queue,
                :polling_frequency,
                :after_polling,
                :guard_options,
                :ignored_errors,
                :sleep_on_guard_locked

  # Creates a new Configuration with default options
  def initialize
    @polling_frequency = Aeternitas::PollingFrequency::DAILY
    @before_polling = []
    @after_polling = []
    @guard_options = {
      key: ->(obj) { return obj.class.name.to_s },
      timeout: 10.minutes,
      cooldown: 5.seconds
    }
    @deactivation_errors = []
    @ignored_errors = []
    @queue = 'polling'
    @sleep_on_guard_locked = true
  end

  def copy
    config = Configuration.new
    config.polling_frequency = self.polling_frequency
    config.before_polling = self.before_polling.deep_dup
    config.after_polling = self.after_polling.deep_dup
    config.guard_options = self.guard_options.deep_dup
    config.deactivation_errors = self.deactivation_errors.deep_dup
    config.ignored_errors = self.ignored_errors.deep_dup
    config.queue = self.queue
    config.sleep_on_guard_locked = self.sleep_on_guard_locked
    config
  end
end

#before_pollingObject

Methods to be run before each poll



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/aeternitas/pollable/configuration.rb', line 23

class Configuration
  attr_accessor :deactivation_errors,
                :before_polling,
                :queue,
                :polling_frequency,
                :after_polling,
                :guard_options,
                :ignored_errors,
                :sleep_on_guard_locked

  # Creates a new Configuration with default options
  def initialize
    @polling_frequency = Aeternitas::PollingFrequency::DAILY
    @before_polling = []
    @after_polling = []
    @guard_options = {
      key: ->(obj) { return obj.class.name.to_s },
      timeout: 10.minutes,
      cooldown: 5.seconds
    }
    @deactivation_errors = []
    @ignored_errors = []
    @queue = 'polling'
    @sleep_on_guard_locked = true
  end

  def copy
    config = Configuration.new
    config.polling_frequency = self.polling_frequency
    config.before_polling = self.before_polling.deep_dup
    config.after_polling = self.after_polling.deep_dup
    config.guard_options = self.guard_options.deep_dup
    config.deactivation_errors = self.deactivation_errors.deep_dup
    config.ignored_errors = self.ignored_errors.deep_dup
    config.queue = self.queue
    config.sleep_on_guard_locked = self.sleep_on_guard_locked
    config
  end
end

#deactivation_errorsObject

The pollable instance will be deactivated if any of these errors occur while polling



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/aeternitas/pollable/configuration.rb', line 23

class Configuration
  attr_accessor :deactivation_errors,
                :before_polling,
                :queue,
                :polling_frequency,
                :after_polling,
                :guard_options,
                :ignored_errors,
                :sleep_on_guard_locked

  # Creates a new Configuration with default options
  def initialize
    @polling_frequency = Aeternitas::PollingFrequency::DAILY
    @before_polling = []
    @after_polling = []
    @guard_options = {
      key: ->(obj) { return obj.class.name.to_s },
      timeout: 10.minutes,
      cooldown: 5.seconds
    }
    @deactivation_errors = []
    @ignored_errors = []
    @queue = 'polling'
    @sleep_on_guard_locked = true
  end

  def copy
    config = Configuration.new
    config.polling_frequency = self.polling_frequency
    config.before_polling = self.before_polling.deep_dup
    config.after_polling = self.after_polling.deep_dup
    config.guard_options = self.guard_options.deep_dup
    config.deactivation_errors = self.deactivation_errors.deep_dup
    config.ignored_errors = self.ignored_errors.deep_dup
    config.queue = self.queue
    config.sleep_on_guard_locked = self.sleep_on_guard_locked
    config
  end
end

#guard_optionsObject

Configuration of the pollables lock (Default: key => class+id, cooldown => 5.seconds, timeout => 10.minutes)



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/aeternitas/pollable/configuration.rb', line 23

class Configuration
  attr_accessor :deactivation_errors,
                :before_polling,
                :queue,
                :polling_frequency,
                :after_polling,
                :guard_options,
                :ignored_errors,
                :sleep_on_guard_locked

  # Creates a new Configuration with default options
  def initialize
    @polling_frequency = Aeternitas::PollingFrequency::DAILY
    @before_polling = []
    @after_polling = []
    @guard_options = {
      key: ->(obj) { return obj.class.name.to_s },
      timeout: 10.minutes,
      cooldown: 5.seconds
    }
    @deactivation_errors = []
    @ignored_errors = []
    @queue = 'polling'
    @sleep_on_guard_locked = true
  end

  def copy
    config = Configuration.new
    config.polling_frequency = self.polling_frequency
    config.before_polling = self.before_polling.deep_dup
    config.after_polling = self.after_polling.deep_dup
    config.guard_options = self.guard_options.deep_dup
    config.deactivation_errors = self.deactivation_errors.deep_dup
    config.ignored_errors = self.ignored_errors.deep_dup
    config.queue = self.queue
    config.sleep_on_guard_locked = self.sleep_on_guard_locked
    config
  end
end

#ignored_errorsObject

Errors in this list will be wrapped by Error::Ignored if they occur while polling (i.e. ignore in your exception tracker)



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/aeternitas/pollable/configuration.rb', line 23

class Configuration
  attr_accessor :deactivation_errors,
                :before_polling,
                :queue,
                :polling_frequency,
                :after_polling,
                :guard_options,
                :ignored_errors,
                :sleep_on_guard_locked

  # Creates a new Configuration with default options
  def initialize
    @polling_frequency = Aeternitas::PollingFrequency::DAILY
    @before_polling = []
    @after_polling = []
    @guard_options = {
      key: ->(obj) { return obj.class.name.to_s },
      timeout: 10.minutes,
      cooldown: 5.seconds
    }
    @deactivation_errors = []
    @ignored_errors = []
    @queue = 'polling'
    @sleep_on_guard_locked = true
  end

  def copy
    config = Configuration.new
    config.polling_frequency = self.polling_frequency
    config.before_polling = self.before_polling.deep_dup
    config.after_polling = self.after_polling.deep_dup
    config.guard_options = self.guard_options.deep_dup
    config.deactivation_errors = self.deactivation_errors.deep_dup
    config.ignored_errors = self.ignored_errors.deep_dup
    config.queue = self.queue
    config.sleep_on_guard_locked = self.sleep_on_guard_locked
    config
  end
end

#polling_frequencyObject

Method that calculates the next polling time after a successful poll. (Default: Aeternitas::PollingFrequency::DAILY)



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/aeternitas/pollable/configuration.rb', line 23

class Configuration
  attr_accessor :deactivation_errors,
                :before_polling,
                :queue,
                :polling_frequency,
                :after_polling,
                :guard_options,
                :ignored_errors,
                :sleep_on_guard_locked

  # Creates a new Configuration with default options
  def initialize
    @polling_frequency = Aeternitas::PollingFrequency::DAILY
    @before_polling = []
    @after_polling = []
    @guard_options = {
      key: ->(obj) { return obj.class.name.to_s },
      timeout: 10.minutes,
      cooldown: 5.seconds
    }
    @deactivation_errors = []
    @ignored_errors = []
    @queue = 'polling'
    @sleep_on_guard_locked = true
  end

  def copy
    config = Configuration.new
    config.polling_frequency = self.polling_frequency
    config.before_polling = self.before_polling.deep_dup
    config.after_polling = self.after_polling.deep_dup
    config.guard_options = self.guard_options.deep_dup
    config.deactivation_errors = self.deactivation_errors.deep_dup
    config.ignored_errors = self.ignored_errors.deep_dup
    config.queue = self.queue
    config.sleep_on_guard_locked = self.sleep_on_guard_locked
    config
  end
end

#queueObject

Sidekiq queue the poll job will be enqueued in (Default: ‘polling’)



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/aeternitas/pollable/configuration.rb', line 23

class Configuration
  attr_accessor :deactivation_errors,
                :before_polling,
                :queue,
                :polling_frequency,
                :after_polling,
                :guard_options,
                :ignored_errors,
                :sleep_on_guard_locked

  # Creates a new Configuration with default options
  def initialize
    @polling_frequency = Aeternitas::PollingFrequency::DAILY
    @before_polling = []
    @after_polling = []
    @guard_options = {
      key: ->(obj) { return obj.class.name.to_s },
      timeout: 10.minutes,
      cooldown: 5.seconds
    }
    @deactivation_errors = []
    @ignored_errors = []
    @queue = 'polling'
    @sleep_on_guard_locked = true
  end

  def copy
    config = Configuration.new
    config.polling_frequency = self.polling_frequency
    config.before_polling = self.before_polling.deep_dup
    config.after_polling = self.after_polling.deep_dup
    config.guard_options = self.guard_options.deep_dup
    config.deactivation_errors = self.deactivation_errors.deep_dup
    config.ignored_errors = self.ignored_errors.deep_dup
    config.queue = self.queue
    config.sleep_on_guard_locked = self.sleep_on_guard_locked
    config
  end
end

#sleep_on_guard_lockedObject

When set to true poll jobs (and effectively the Sidekiq worker thread) will sleep until the lock is released if the lock could not be acquired. (Default: true)



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/aeternitas/pollable/configuration.rb', line 23

class Configuration
  attr_accessor :deactivation_errors,
                :before_polling,
                :queue,
                :polling_frequency,
                :after_polling,
                :guard_options,
                :ignored_errors,
                :sleep_on_guard_locked

  # Creates a new Configuration with default options
  def initialize
    @polling_frequency = Aeternitas::PollingFrequency::DAILY
    @before_polling = []
    @after_polling = []
    @guard_options = {
      key: ->(obj) { return obj.class.name.to_s },
      timeout: 10.minutes,
      cooldown: 5.seconds
    }
    @deactivation_errors = []
    @ignored_errors = []
    @queue = 'polling'
    @sleep_on_guard_locked = true
  end

  def copy
    config = Configuration.new
    config.polling_frequency = self.polling_frequency
    config.before_polling = self.before_polling.deep_dup
    config.after_polling = self.after_polling.deep_dup
    config.guard_options = self.guard_options.deep_dup
    config.deactivation_errors = self.deactivation_errors.deep_dup
    config.ignored_errors = self.ignored_errors.deep_dup
    config.queue = self.queue
    config.sleep_on_guard_locked = self.sleep_on_guard_locked
    config
  end
end

Instance Method Details

#copyObject



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/aeternitas/pollable/configuration.rb', line 49

def copy
  config = Configuration.new
  config.polling_frequency = self.polling_frequency
  config.before_polling = self.before_polling.deep_dup
  config.after_polling = self.after_polling.deep_dup
  config.guard_options = self.guard_options.deep_dup
  config.deactivation_errors = self.deactivation_errors.deep_dup
  config.ignored_errors = self.ignored_errors.deep_dup
  config.queue = self.queue
  config.sleep_on_guard_locked = self.sleep_on_guard_locked
  config
end