Class: Joblin::BackgroundTask

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
ApiAccess, Attachments, Executor, Options, RetentionPolicy
Defined in:
app/models/joblin/background_task.rb,
app/models/joblin/background_task/options.rb,
app/models/joblin/background_task/executor.rb,
app/models/joblin/background_task/api_access.rb,
app/models/joblin/background_task/attachments.rb,
app/models/joblin/background_task/retention_policy.rb

Defined Under Namespace

Modules: ApiAccess, Attachments, Executor, Options, RetentionPolicy Classes: BackgroundTaskCallbacks, InvalidJobError

Constant Summary

Constants included from Executor

Executor::BACKGROUND_TASK_THREAD_KEY

Instance Method Summary collapse

Methods included from ApiAccess

#api_access_allowed?

Methods included from Attachments

#attach_file, #attachment_path, #load_attachment

Methods included from Concerns::JobWorkingDirs

#working_dir

Methods included from Options

#options

Instance Method Details

#cancel!Object



44
45
46
# File 'app/models/joblin/background_task.rb', line 44

def cancel!
  update!(workflow_state: 'cancelled')
end

#enqueue!Object



32
33
34
35
36
37
38
39
40
41
42
# File 'app/models/joblin/background_task.rb', line 32

def enqueue!
  # Persist the transition here so it isn't lost when enter_batch reuses an
  # existing batch_id (and doesn't otherwise write the record) — e.g. a
  # re-enqueue after failure must not stay `failed`.
  self.workflow_state = 'scheduled'
  save! if changed?

  enter_batch do
    self.class::ExecutorJob.perform_later()
  end
end

#handle_batch_stagnationObject



48
49
50
# File 'app/models/joblin/background_task.rb', line 48

def handle_batch_stagnation
  Joblin::Batching::Batch.cleanup_redis(batch_id)
end