jobler 0.0.4 → 0.0.5

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
  SHA1:
3
- metadata.gz: 48611c7dac3539e71c56fd8b94861495e6d42bfd
4
- data.tar.gz: 90ace36fd054d1eb70b55947ace2d5c83a5be55d
3
+ metadata.gz: bc6575214ca69340a22f08224606c5054ede5a4b
4
+ data.tar.gz: 259b5d8e7f71b30eb3d5af07e22bc6f6e6ff47f8
5
5
  SHA512:
6
- metadata.gz: 9d5a976300160f6a0144fd7c5225c0d187023d5b1f259db31bdd385419547fcf7c38fc7e0ed212af39fd41086c05f9eb628aaffb97e76aa7fa05257d2644227c
7
- data.tar.gz: 5620d5fede8a100fa849d98c32df9001573b9aa1c2fb9c5dfc85f481640a6e02cafbf12034aab837f992adaf2ae41e1c2101b1901c3bbc523eeda6eab5ff0acd
6
+ metadata.gz: cc6428a298bf822a8964ca74ab5bf05d36dca9b289e8108841abf8b319263da810aa4d520c09eed02bc7345801c1fd7a9a741caa18dee61c238e676b5470177d
7
+ data.tar.gz: 4c23cfe4bf54bd0102cc543dd3ed27ae4651175bc71e11deed63e8a406c23090db6956972c928fb56912e650a4bbfa2896e6de672d00b8c64b55759d884e45a0
@@ -1,2 +1,3 @@
1
1
  //= require jquery
2
+ //= require jobler/timeago
2
3
  //= require jobler/jobs
@@ -7,23 +7,25 @@ function updateJobProgress() {
7
7
 
8
8
  result = $.parseJSON(data.responseText)
9
9
 
10
- $(".job-progress").text((result.job.progress * 100).toFixed(2) + "%")
10
+ $(".job-headline").text(result.job.state_humanized)
11
+ $(".progress-bar").text((result.job.progress * 100).toFixed(0) + "%")
12
+ $(".progress-bar").css({width: (result.job.progress * 100) + "%"})
11
13
 
12
- if (result.job.state == "completed") {
14
+ if (result.job.state == "completed" || result.job.state == "error") {
13
15
  console.log("Job is completed - reload!")
14
16
  location.reload()
15
17
  }
16
18
  }})
17
19
 
18
20
  if (job.data("state") != "completed") {
19
- setTimeout("updateJobProgress()", 5000)
21
+ setTimeout("updateJobProgress()", 2000)
20
22
  }
21
23
  }
22
24
 
23
25
  $(document).ready(function() {
24
26
  job = $(".job")
25
27
 
26
- if (job.data("state") != "completed") {
27
- updateJobProgress()
28
+ if (job.data("state") != "completed" && job.data("state") != "error") {
29
+ setTimeout("updateJobProgress()", 1000)
28
30
  }
29
31
  })
@@ -0,0 +1,3 @@
1
+ $(document).ready(function() {
2
+ jQuery("time.timeago").timeago()
3
+ })
@@ -1,15 +1,3 @@
1
- /*
2
- * This is a manifest file that'll be compiled into application.css, which will include all the files
3
- * listed below.
4
- *
5
- * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
- * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
- *
8
- * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
- * compiled file so the styles you add here take precedence over styles defined in any styles
10
- * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
- * file per style scope.
12
- *
13
- *= require_tree .
14
- *= require_self
15
- */
1
+ body {
2
+ padding-top: 50px;
3
+ }
@@ -1,6 +1,6 @@
1
1
  class Jobler::DownloadsController < Jobler::ApplicationController
2
2
  def show
3
- @job = Jobler::Job.find(params[:id])
3
+ @job = Jobler::Job.find_by!(slug: params[:id])
4
4
  @result = @job.jobler.result
5
5
 
6
6
  if @result.is_a?(Jobler::FileDownload)
@@ -1,6 +1,6 @@
1
1
  class Jobler::JobsController < Jobler::ApplicationController
2
2
  def show
3
- @job = Jobler::Job.find(params[:id])
3
+ @job = Jobler::Job.find_by!(slug: params[:id])
4
4
  @result = @job.jobler.result if @job.completed?
5
5
 
6
6
  respond_to do |format|
@@ -8,7 +8,8 @@ class Jobler::JobsController < Jobler::ApplicationController
8
8
  render json: {
9
9
  job: {
10
10
  progress: @job.progress,
11
- state: @job.state
11
+ state: @job.state,
12
+ state_humanized: @job.state.humanize
12
13
  }
13
14
  }
14
15
  end
@@ -1,7 +1,9 @@
1
1
  class Jobler::Job < ActiveRecord::Base
2
2
  has_many :results, class_name: "Jobler::Result", dependent: :destroy
3
3
 
4
- validates :jobler_type, :state, presence: true
4
+ validates :jobler_type, :slug, :state, presence: true
5
+
6
+ before_validation :set_slug
5
7
 
6
8
  def jobler
7
9
  user_jobler = jobler_type.constantize.new
@@ -13,4 +15,20 @@ class Jobler::Job < ActiveRecord::Base
13
15
  def completed?
14
16
  state == "completed"
15
17
  end
18
+
19
+ def error?
20
+ state == "error"
21
+ end
22
+
23
+ def to_param
24
+ raise "No slug" unless slug?
25
+ slug
26
+ end
27
+
28
+ private
29
+
30
+ def set_slug
31
+ require "securerandom"
32
+ self.slug ||= SecureRandom.hex
33
+ end
16
34
  end
@@ -1,17 +1,26 @@
1
1
  <div class="job" data-id="<%= @job.id %>" data-path="<%= job_path(@job) %>" data-state="<%= @job.state %>"></div>
2
2
 
3
- <% if @job.completed? %>
4
- <h1>Completed</h1>
3
+ <h1 class="job-headline"><%= @job.state.humanize %></h1>
5
4
 
5
+ <% if @job.completed? %>
6
6
  <% if @result.is_a?(Jobler::FileDownload) %>
7
7
  <%= link_to "Download", download_path(@job) %>
8
8
  <% end %>
9
+ <% elsif @job.error? %>
10
+ <div class="well">
11
+ <%= @job.error_type %>: <%= @job.error_message %>
12
+ </div>
13
+ <pre><%= @job.error_backtrace %></pre>
9
14
  <% else %>
10
- <h1>Waiting</h1>
15
+ Started <time class="timeago" datetime="<%= @job.created_at %>"></time>
11
16
 
12
- <div class="job-progress">
13
- <% if @job.progress? %>
14
- <%= number_with_precision @job.progress, precision: 2 %>%
15
- <% end %>
17
+ <div class="row">
18
+ <div class="col-lg-4 col-md-6 col-sm-8 col-xs-10">
19
+ <div class="progress">
20
+ <div class="progress-bar" role="progressbar" aria-valuenow="60" aria-valuemin="0" aria-valuemax="100" style="width: <%= (@job.progress * 100).to_i %>%;">
21
+ <%= (@job.progress * 100).to_i %>%
22
+ </div>
23
+ </div>
24
+ </div>
16
25
  </div>
17
26
  <% end %>
@@ -2,13 +2,35 @@
2
2
  <html>
3
3
  <head>
4
4
  <title>Jobler</title>
5
+
5
6
  <%= stylesheet_link_tag "jobler/application", media: "all" %>
7
+ <%= stylesheet_link_tag "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css", integrity: "sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u", crossorigin: "anonymous" %>
8
+
6
9
  <%= javascript_include_tag "jobler/application" %>
10
+ <%= javascript_include_tag "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js", integrity: "sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa", crossorigin: "anonymous" %>
11
+ <%= javascript_include_tag "https://use.fontawesome.com/de02b76735.js" %>
12
+ <%= javascript_include_tag "https://cdnjs.cloudflare.com/ajax/libs/jquery-timeago/1.5.4/jquery.timeago.min.js" %>
13
+
7
14
  <%= csrf_meta_tags %>
8
15
  </head>
9
16
  <body class="controller-<%= controller_name %> action-<%= action_name %>">
10
-
11
- <%= yield %>
12
-
17
+ <nav class="navbar navbar-inverse navbar-fixed-top">
18
+ <div class="container">
19
+ <div class="navbar-header">
20
+ <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
21
+ <span class="sr-only">Toggle navigation</span>
22
+ <span class="icon-bar"></span>
23
+ <span class="icon-bar"></span>
24
+ <span class="icon-bar"></span>
25
+ </button>
26
+ <a class="navbar-brand" href="#">Jobler</a>
27
+ </div>
28
+ </div>
29
+ </nav>
30
+ <div class="container">
31
+ <div class="starter-template">
32
+ <%= yield %>
33
+ </div>
34
+ </div>
13
35
  </body>
14
36
  </html>
@@ -0,0 +1,7 @@
1
+ class AddErrorMessageAndErrorBacktraceToJobs < ActiveRecord::Migration
2
+ def change
3
+ add_column :jobler_jobs, :error_message, :text
4
+ add_column :jobler_jobs, :error_type, :string
5
+ add_column :jobler_jobs, :error_backtrace, :text
6
+ end
7
+ end
@@ -0,0 +1,6 @@
1
+ class AddSlugToJobs < ActiveRecord::Migration
2
+ def change
3
+ add_column :jobler_jobs, :slug, :string
4
+ add_index :jobler_jobs, :slug, unique: true
5
+ end
6
+ end
@@ -12,8 +12,13 @@ class Jobler::JobRunner < ActiveJob::Base
12
12
 
13
13
  @job.update_attributes!(ended_at: Time.zone.now, progress: 1.0, state: "completed")
14
14
  rescue Exception => e # rubocop:disable Lint/RescueException
15
- @job.update_attributes!(ended_at: Time.zone.now, state: "error")
16
- raise e
15
+ @job.update_attributes!(
16
+ ended_at: Time.zone.now,
17
+ error_message: e.message,
18
+ error_type: e.class.name,
19
+ error_backtrace: e.backtrace.join("\n"),
20
+ state: "error"
21
+ )
17
22
  end
18
23
  end
19
24
 
@@ -1,3 +1,3 @@
1
1
  module Jobler
2
- VERSION = "0.0.4".freeze
2
+ VERSION = "0.0.5".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.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - kaspernj
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-05 00:00:00.000000000 Z
11
+ date: 2017-02-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -37,6 +37,7 @@ files:
37
37
  - app/assets/javascripts/jobler.js
38
38
  - app/assets/javascripts/jobler/application.js
39
39
  - app/assets/javascripts/jobler/jobs.js
40
+ - app/assets/javascripts/jobler/timeago.js
40
41
  - app/assets/stylesheets/jobler/application.css
41
42
  - app/controllers/jobler/application_controller.rb
42
43
  - app/controllers/jobler/downloads_controller.rb
@@ -50,6 +51,8 @@ files:
50
51
  - db/migrate/20170130220604_create_jobs.rb
51
52
  - db/migrate/20170130220734_create_jobler_results.rb
52
53
  - db/migrate/20170203161045_add_locale_to_jobs.rb
54
+ - db/migrate/20170206100737_add_error_message_and_error_backtrace_to_jobs.rb
55
+ - db/migrate/20170206104246_add_slug_to_jobs.rb
53
56
  - lib/jobler.rb
54
57
  - lib/jobler/base_jobler.rb
55
58
  - lib/jobler/engine.rb