jobler 0.0.2 → 0.0.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
  SHA1:
3
- metadata.gz: aafad76d10d7737cd8b9458cf13659b424f21594
4
- data.tar.gz: 3da5dcf4402b06f26b6a9ca369ee841dbf3b9b16
3
+ metadata.gz: 3623c18e11b1420eb4930ddd2f899e42d814c6c5
4
+ data.tar.gz: fa3ddd60982e1d53745983cce238b4960c49fcba
5
5
  SHA512:
6
- metadata.gz: 8339b8c793caf78adb46aa38cd682bc9be4ccae7109616a2ec5a0e2bfab85bf374d9a3ef66a6296d2f81ff1c84f584cdf8e27c6e7e5c94b95287836dbf653afa
7
- data.tar.gz: e5c18bfea11281552bc2cf41f8ffc035aee510701e56d22799e1e4931cf3ecc3c6ddd00ea14c680ffc0a570c03ee0798adc796052bc837687a6a87337295778e
6
+ metadata.gz: ed1449d9d221793711b4e65f8d2d875b2f554974aeccc8d464e5184852a65a0a6a2149e4f6665d5704c22ce97b026f02c8756846c0c031e8304fdf052336f848
7
+ data.tar.gz: 50e7709172176db511bf87badb9973e0c966560516a52183324eec3441df1cb84331999ebe8d31ea7dc3e3154686e0f87fc764fb02d4522b823716161abec162
@@ -0,0 +1,5 @@
1
+ class AddLocaleToJobs < ActiveRecord::Migration
2
+ def change
3
+ add_column :jobler_jobs, :locale, :string
4
+ end
5
+ end
@@ -29,7 +29,7 @@ class Jobler::BaseJobler
29
29
  end
30
30
 
31
31
  if update
32
- job.update_columns(progress: new_progress)
32
+ job.update_attributes!(progress: new_progress)
33
33
  @_current_progress = new_progress
34
34
  end
35
35
  end
@@ -2,15 +2,30 @@ class Jobler::JobRunner < ActiveJob::Base
2
2
  queue_as :jobler
3
3
 
4
4
  def perform(job_id)
5
- job = Jobler::Job.find(job_id)
6
- job.update_attributes!(started_at: Time.zone.now, state: "started")
5
+ @job = Jobler::Job.find(job_id)
6
+ @job.update_attributes!(started_at: Time.zone.now, state: "started")
7
7
 
8
8
  begin
9
- job.jobler.execute!
10
- job.update_attributes!(ended_at: Time.zone.now, progress: 1.0, state: "completed")
9
+ with_locale do
10
+ @job.jobler.execute!
11
+ end
12
+
13
+ @job.update_attributes!(ended_at: Time.zone.now, progress: 1.0, state: "completed")
11
14
  rescue Exception => e # rubocop:disable Lint/RescueException
12
- job.update_attributes!(ended_at: Time.zone.now, state: "error")
15
+ @job.update_attributes!(ended_at: Time.zone.now, state: "error")
13
16
  raise e
14
17
  end
15
18
  end
19
+
20
+ private
21
+
22
+ def with_locale
23
+ if @job.locale?
24
+ I18n.with_locale(@job.locale) do
25
+ yield
26
+ end
27
+ else
28
+ yield
29
+ end
30
+ end
16
31
  end
@@ -11,10 +11,15 @@ class Jobler::JobScheduler
11
11
  def initialize(args)
12
12
  @jobler_type = args.fetch(:jobler_type)
13
13
  @job_args = args[:job_args]
14
+ @locale = args[:locale]
14
15
  end
15
16
 
16
17
  def create_job
17
- @job = Jobler::Job.create!(jobler_type: @jobler_type, parameters: YAML.dump(@job_args))
18
+ @job = Jobler::Job.create!(
19
+ jobler_type: @jobler_type,
20
+ locale: @locale.presence || I18n.locale,
21
+ parameters: YAML.dump(@job_args)
22
+ )
18
23
  end
19
24
 
20
25
  def perform_job_later
@@ -1,3 +1,3 @@
1
1
  module Jobler
2
- VERSION = "0.0.2".freeze
2
+ VERSION = "0.0.3".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jobler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - kaspernj
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-31 00:00:00.000000000 Z
11
+ date: 2017-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -49,6 +49,7 @@ files:
49
49
  - config/routes.rb
50
50
  - db/migrate/20170130220604_create_jobs.rb
51
51
  - db/migrate/20170130220734_create_jobler_results.rb
52
+ - db/migrate/20170203161045_add_locale_to_jobs.rb
52
53
  - lib/jobler.rb
53
54
  - lib/jobler/base_jobler.rb
54
55
  - lib/jobler/engine.rb