joblin 0.1.5 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6cb0e0c2038030615d4e6a50e08aac0166f022a6af89f2a5d157d977e2f03f58
4
- data.tar.gz: f25744584d54054fe566770b10870159ac9c2a422c8e44cb609aca67116f4c03
3
+ metadata.gz: 23c16a1c4a23f6ad9d6f254c0d0ee5aea54fa3e4501222c2e93ccf2bdf8f94b6
4
+ data.tar.gz: 22785e30a3229741a3daa125c89f93ba17ab285f614d1e9546eeb491a5296ac3
5
5
  SHA512:
6
- metadata.gz: 726db8abb51ae0697aa6299df1179c7ef7a5e7de96681b6da9341d97242d4a39928ca4a274a26d58b35ba519f29c3b7d18b8d19dc4cf66bbdd7f25f0c5f83a2b
7
- data.tar.gz: 83ca76bd6c338207259f08e4115920613c525c5bbe3be431a6a1299bfc0b79282f69a986ce3c04fa17078b0c2dce24f1de1e8556e8d371bda03bcb7231c5ba15
6
+ metadata.gz: aa29ff4cb1af77eb546f1d5b0963c4b7b22145d067b991a82912bd8d071cbd8829e64b748d75c031d8c67d849ea7c36047a85b5fcd3d1e5454239b0593926f2d
7
+ data.tar.gz: c08af787c49c3ecfba70c675534c26174de20e97c742952652696428aae5290b79fcbb6b63391504d02acc2ad413909e7d9aa721f05242cf571eb0f52cf93162
@@ -3,6 +3,8 @@ module Joblin
3
3
  module Executor
4
4
  extend ActiveSupport::Concern
5
5
 
6
+ BACKGROUND_TASK_THREAD_KEY = :joblin_current_background_task
7
+
6
8
  class_methods do
7
9
  def inherited(subclass)
8
10
  subclass.const_set(:ExecutorJob, Class.new(self::ExecutorJob))
@@ -48,6 +50,10 @@ module Joblin
48
50
 
49
51
  # delegate :before_perform, :around_perform, :after_perform, to: :job_executor_class
50
52
  # delegate :before_enqueue, :around_enqueue, :after_enqueue, to: :job_executor_class
53
+
54
+ def current
55
+ Thread.current[BACKGROUND_TASK_THREAD_KEY] || BackgroundTask.find(Batch.current_context[:background_task_id])
56
+ end
51
57
  end
52
58
 
53
59
  included do
@@ -61,6 +67,14 @@ module Joblin
61
67
  end
62
68
 
63
69
  class ExecutorJob < ActiveJob::Base
70
+ around_perform do |job, block|
71
+ pretask = Thread.current[BACKGROUND_TASK_THREAD_KEY]
72
+ Thread.current[BACKGROUND_TASK_THREAD_KEY] = job.the_task
73
+ block.call
74
+ ensure
75
+ Thread.current[BACKGROUND_TASK_THREAD_KEY] = pretask
76
+ end
77
+
64
78
  def perform
65
79
  the_task.update(workflow_state: "started") if the_task.workflow_state == "scheduled"
66
80
  the_task.perform
@@ -1,4 +1,4 @@
1
- class CreateJoblinBackgroundTasks < ActiveRecord::Migration[5.2]
1
+ class CreateJoblinBackgroundTasks < Joblin::MiscHelper::MigrationClass
2
2
  def change
3
3
  create_table :joblin_background_tasks do |t|
4
4
  t.references :creator, polymorphic: true
@@ -1,4 +1,4 @@
1
- class AddResultsToJoblinBackgroundTasks < ActiveRecord::Migration[5.2]
1
+ class AddResultsToJoblinBackgroundTasks < Joblin::MiscHelper::MigrationClass
2
2
  def change
3
3
  add_column :joblin_background_tasks, :results, :jsonb
4
4
  add_column :joblin_background_tasks, :error_message, :text
@@ -0,0 +1,15 @@
1
+ require 'active_record'
2
+
3
+ module Joblin
4
+ module MiscHelper
5
+ MigrationClass = Rails.version < '5.0' ? ActiveRecord::Migration : ActiveRecord::Migration[5.2]
6
+
7
+ def self.to_boolean(v)
8
+ if Rails.version < '5.0'
9
+ ActiveRecord::Type::Boolean.new.type_cast_from_user(v)
10
+ else
11
+ ActiveRecord::Type::Boolean.new.deserialize(v)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,3 +1,3 @@
1
1
  module Joblin
2
- VERSION = "0.1.5".freeze
2
+ VERSION = "0.1.7".freeze
3
3
  end
data/lib/joblin.rb CHANGED
@@ -6,6 +6,7 @@ require "active_support/lazy_load_hooks"
6
6
  require "rediconn"
7
7
 
8
8
  require "joblin/engine"
9
+ require "joblin/misc_helper"
9
10
 
10
11
  require "joblin/lazy_access"
11
12
  require "joblin/batching/batch"