Class: ActiveCanvas::CompileTailwindJob

Inherits:
ApplicationJob
  • Object
show all
Defined in:
app/jobs/active_canvas/compile_tailwind_job.rb

Constant Summary collapse

LOG_PREFIX =
"[ActiveCanvas::CompileTailwindJob]".freeze

Instance Method Summary collapse

Instance Method Details

#perform(page_id) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/jobs/active_canvas/compile_tailwind_job.rb', line 9

def perform(page_id)
  log_info "Job started for page ##{page_id}"

  page = Page.find_by(id: page_id)
  unless page
    log_warn "Page ##{page_id} not found, skipping"
    return
  end

  unless ActiveCanvas::TailwindCompiler.available?
    log_info "Skipping: tailwindcss-ruby gem not available"
    return
  end

  unless Setting.css_framework == "tailwind"
    log_info "Skipping: Tailwind not selected as framework (current: #{Setting.css_framework})"
    return
  end

  log_info "Compiling Tailwind CSS for page ##{page.id} (#{page.title})"
  start_time = Time.current

  compiled_css = ActiveCanvas::TailwindCompiler.compile_for_page(page)

  page.update_columns(
    compiled_tailwind_css: compiled_css,
    tailwind_compiled_at: Time.current
  )

  elapsed = ((Time.current - start_time) * 1000).round(2)
  log_info "Job completed for page ##{page.id} in #{elapsed}ms (CSS size: #{compiled_css.bytesize} bytes)"

rescue ActiveCanvas::TailwindCompiler::CompilationError => e
  log_error "Compilation failed for page ##{page_id}: #{e.message}"
  raise
rescue => e
  log_error "Unexpected error for page ##{page_id}: #{e.class.name}: #{e.message}"
  log_error e.backtrace.first(5).join("\n")
  raise
end