async_block 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: edf6ec5cd97396b384affe1e3fe9b20e54e63bc8f25aeb364f0bfe8053e3cd85
4
- data.tar.gz: 333fe7fca486e6ce5bd333009c7c1f963b15712785db67a48000554c36b78577
3
+ metadata.gz: ea3a6e56db84717647f95b697dd3df1d7b70a586a0b91b25012e3a59eaa0a03c
4
+ data.tar.gz: 4e3f8d7d5008271e2a2e5a945d032b5267190dccaff29f53b08b7b7213f6042d
5
5
  SHA512:
6
- metadata.gz: ecacd457ba31dc5fdc76e04526f25087a2b637b36172411fb335a07cacad8b30c6df22ea43dbc505cd612ad0a412f56c7aab78aab40654558dd7010bdae0aca0
7
- data.tar.gz: c057869a25f1725b9046452dcb11ac5906b57eeb2b754753b2d7476acac939168d54559bad2b7f9d340035124d656cec97ca15dc9f1bfb5271086f4b2fff730c
6
+ metadata.gz: 53625548312d7a9d4254bcccd77b0839471d705129ce0ddcfbba848aa794a4137d35d5751256d6494a716fbf1885fe391bbe57dcf4bbe88c2e60f76dc58917b2
7
+ data.tar.gz: d19e25f430c30a68b9db9a30c0f41c626d5df1a221dbc51b3fb2754a8098ecdeb3358fa711583c27810ab30d1c530a0174cc692357e3f9e1a204c1943d41f12f
@@ -13,19 +13,21 @@ module AsyncBlock
13
13
  end
14
14
 
15
15
  def perform(source, on_error_source)
16
- @block = str_to_block(source)
17
- @on_error = str_to_block(on_error_source)
18
- execute_block!
16
+ # Converts source code to callable block
17
+ block = source_to_block(source)
18
+ # Puts :on_error method in instance
19
+ source_to_block(on_error_source).call
20
+ execute_block!(block)
19
21
  end
20
22
 
21
23
  private
22
24
 
23
- def str_to_block(source)
25
+ def source_to_block(source)
24
26
  SourceToBlock.new(source).convert
25
27
  end
26
28
 
27
- def execute_block!(_block)
28
- @block.call
29
+ def execute_block!(block)
30
+ block.call
29
31
  end
30
32
 
31
33
  def send_error_message(job, error)
@@ -33,7 +35,7 @@ module AsyncBlock
33
35
  with #{job.arguments.join(', ')} due to
34
36
  '#{error.class} - #{error.message}'.
35
37
  This job was retried for #{job.executions} times.".squish
36
- @on_error.call(error_message)
38
+ on_error(error_message)
37
39
  end
38
40
  end
39
41
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AsyncBlock
4
- VERSION = '0.2.2'
4
+ VERSION = '0.2.3'
5
5
  end
data/lib/async_block.rb CHANGED
@@ -10,16 +10,18 @@ require_relative 'async_block/async_wrapper_job'
10
10
  module AsyncBlock
11
11
  class Error < StandardError; end
12
12
 
13
- def self.perform(queue: nil, delay: nil, on_error: default_on_error, &block)
13
+ def self.perform(queue: nil, delay: nil, on_error: nil, &block)
14
14
  source = BlockToSource.new(block).convert
15
- on_error_source = BlockToSource.new(on_error).convert
15
+ on_error_source = BlockToSource.new(on_error || default_on_error).convert
16
16
  queue ||= DEFAULT_QUEUE_NAME
17
- if delay.nil?
18
- AsyncWrapperJob.set(queue: queue.to_sym).perform_later(source, on_error_source)
19
- else
17
+ if delay.instance_of?(ActiveSupport::Duration)
20
18
  AsyncWrapperJob.set(wait: delay, queue: queue.to_sym).perform_later(source, on_error_source)
19
+ else
20
+ AsyncWrapperJob.set(queue: queue.to_sym).perform_later(source, on_error_source)
21
21
  end
22
22
  end
23
23
 
24
- def self.default_on_error; end
24
+ def self.default_on_error(error_message)
25
+ puts('AsyncBlockError', error_message)
26
+ end
25
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: async_block
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adittya Dey
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-03-11 00:00:00.000000000 Z
11
+ date: 2023-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport