arask 1.1.3 → 1.2.0

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
  SHA1:
3
- metadata.gz: bbc371d18529aa76cdb47358c395712a623f95c6
4
- data.tar.gz: c48f5ddda64e71cafac940cb3ce4af81691ae2ba
3
+ metadata.gz: e2055444d486251702ec8f09cc6944742f4ef45e
4
+ data.tar.gz: 3215c191aab13ce67fec68d09ec02962314f528b
5
5
  SHA512:
6
- metadata.gz: 2061665d541fc6bc7758b0a595161b18820f267ea90e3bb56edead27f7bc666fe78d765405c2f86e69d11d744052a918a11a98bdfd76463a745a3f81c34a68d5
7
- data.tar.gz: 1338c50d342cd77ff4d26bc273f518c276e1174369fcc5db0a27938573302dfd148dafd6243dcdb7126027f29682dd1c50902aab20122c603cbba5183d58b87f
6
+ metadata.gz: ba226a137d88675b7375f5bc59cdd780437a5f9bd218c7523ec8ad149823d03511b96a358acb3ca8b2d2a26d9b36a3577bb134925b03ee0f9a8c75721cf53cc0
7
+ data.tar.gz: af1ab2f4a7933407c0361e4f14fc09a8c00f974db29859a3532fabe374a25f28db8cfca5fc7c252af539f17f28f632c51b77ea3c1cd5bc4709aa88eae6fce408
data/README.md CHANGED
@@ -49,6 +49,11 @@ arask.create script: 'Attachment.process_new', interval: 5.hours, run_first_time
49
49
 
50
50
  # On exceptions, send email with details
51
51
  arask.on_exception email: 'errors@example.com'
52
+
53
+ # Run code on exceptions
54
+ arask.on_exception do |exception, arask_job|
55
+ Honeybadger.notify(exception)
56
+ end
52
57
  ```
53
58
 
54
59
  ### About cron
@@ -61,10 +66,9 @@ The interval starts when the task has started running. If a task with the interv
61
66
 
62
67
  ## Todos
63
68
  * Have a "try again" feature. For instance `arask.create script: 'raise "I failed"', interval: :daily, fail_retry: 5.minutes, retry_at_most: 2`
64
- * Be able to run a block when an exception occurs. `arask.on_exception do <code> end`
65
69
  * Be able to specify line and number that failed for an exception:
66
70
  ```ruby
67
- file,line,_ = caller.first.split(' ')[0].split(':')
71
+ file,line,_ = caller.first.split(':')
68
72
  fileline = File.readlines(file)[line.to_i - 1].strip
69
73
  ```
70
74
 
data/lib/arask.rb CHANGED
@@ -5,11 +5,14 @@ require "arask/setup"
5
5
  require 'fugit' # To parse cron
6
6
 
7
7
  module Arask
8
- class << self; attr_accessor :jobs_touched, :exception_email, :exception_email_from; end
8
+ class << self; attr_accessor :jobs_touched, :exception_email, :exception_email_from, :exception_block; end
9
9
 
10
10
  def self.setup
11
11
  # Make sure we only run setup if Rails is actually run as a server or testing.
12
12
  return unless defined?(Rails::Server) or Rails.env.test?
13
+ # If we don't wait and rails is setup to use another language, ActiveJob
14
+ # saves what is now (usually :en) and reloads that when trying to run the
15
+ # job. Renderering an I18n error of unsupported language.
13
16
  ActiveSupport.on_load :after_initialize, yield: true do
14
17
  Arask.jobs_touched = []
15
18
  yield Setup
@@ -16,6 +16,9 @@ module Arask
16
16
  p self
17
17
  puts e.message
18
18
 
19
+ unless Arask.exception_block.nil?
20
+ Arask.exception_block.call(e, self)
21
+ end
19
22
  unless Arask.exception_email.nil?
20
23
  ActionMailer::Base.mail(
21
24
  from: Arask.exception_email_from,
@@ -21,4 +21,9 @@ Arask.setup do |arask|
21
21
 
22
22
  # On exceptions, send email with details
23
23
  #arask.on_exception email: 'errors@example.com'
24
+
25
+ # Run code on exceptions
26
+ #arask.on_exception do |exception, arask_job|
27
+ # Honeybadger.notify(exception)
28
+ #end
24
29
  end
data/lib/arask/setup.rb CHANGED
@@ -1,9 +1,12 @@
1
1
  module Arask
2
2
  class Setup
3
- def self.on_exception(email: nil, from: 'robot@server')
4
- Arask.exception_email = email
5
- Arask.exception_email_from = from
6
- puts "Arask could not parse parameter for on_exception!" unless email.class == String
3
+ def self.on_exception(email: nil, from: 'robot@server', &block)
4
+ Arask.exception_email = email unless email.nil?
5
+ Arask.exception_email_from = from unless from.nil?
6
+ puts "Arask could not parse parameter for on_exception!" unless email.nil? or email.class == String
7
+ if block_given?
8
+ Arask.exception_block = block
9
+ end
7
10
  end
8
11
 
9
12
  def self.create(script: nil, task: nil, job: nil, interval: nil, cron: nil, run_first_time: false)
data/lib/arask/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Arask
2
- VERSION = '1.1.3'
2
+ VERSION = '1.2.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arask
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Esben Damgaard
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-02 00:00:00.000000000 Z
11
+ date: 2018-07-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails