Class: Job

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Jobs::States
Defined in:
app/models/job.rb

Constant Summary collapse

Scheduled =
'scheduled'
Processing =
'processing'
OnHold =
'on_hold'
Success =
'success'
Failed =
'failed'

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Jobs::States

#create_state_change, #enter, included, #initial_state

Class Method Details

.from_api(options) ⇒ Object


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/models/job.rb', line 34

def from_api(options)
  options = options[:job] if options[:job]

  args = {}
  options['arguments'].split(',').each do |arg|
    k, v = arg.split('=')
    args.merge!(k.to_sym => v)
  end if options['arguments']

  job = new(source_file: options['input'],
            destination_file: options['output'],
            preset: Preset.find_by_name(options['preset']),
            priority: options['priority'],
            notifications: Notification.from_api(options[:notify]),
            arguments: args)

  job.enter(Job::Scheduled) if job.save

  job
end

.recents(opts = {}) ⇒ Object


55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/models/job.rb', line 55

def recents(opts = {})
  jobs = all

  jobs = Job.search(opts[:query]) if opts[:query]

  jobs = jobs.recent.page(opts[:page])

  if opts[:sort] && opts[:dir]
    jobs = jobs.order('jobs.' + opts[:sort] + ' ' + opts[:dir])
  end

  jobs
end

.search(query) ⇒ Object


69
70
71
# File 'app/models/job.rb', line 69

def search(query)
  JobSearch.search(all, query)
end

Instance Method Details

#finished?Boolean

Returns:

  • (Boolean)

78
79
80
# File 'app/models/job.rb', line 78

def finished?
  state == Success || state == Failed
end

#needs_update?Boolean

Returns:

  • (Boolean)

74
75
76
# File 'app/models/job.rb', line 74

def needs_update?
  state == Processing || state == OnHold
end

#unfinished?Boolean

Returns:

  • (Boolean)

82
83
84
# File 'app/models/job.rb', line 82

def unfinished?
  state == Scheduled || state == Processing || state == OnHold
end