Skip to content

Commit

Permalink
Disable automated pipelines (#825)
Browse files Browse the repository at this point in the history
* adding migration to create new disabled column for automated workflow executions table

* adding new status column to automated workflow executions table

* attempting to enable/disable automated workflows after pipeline initialization

* trying to fix tests

* updating enable/disable automated workflow based on pipeline automatable and exectuable

* trying to fix ci tests

* trying to fix ci tests

* trying to fix ci tests

* trying to fix ci tests

* trying to fix ci tests

* trying to fix ci tests

* trying to fix ci tests

* trying to fix ci tests

* trying to fix ci tests

* adding translations

* adding a test

* checking the table exists

* checking the table exists

* iterating through automated workflow executions instead of pipelines

* adding a new test

* disabling the edit link for disabled automated workflows

* updating LaunchJob to only call LaunchService for enabled automated workflows

* removing edit link if disabled
  • Loading branch information
ksierks authored Nov 1, 2024
1 parent cdb1d48 commit 4b40c22
Show file tree
Hide file tree
Showing 15 changed files with 256 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,25 @@ def new
end
end

def edit
def edit # rubocop:disable Metrics/MethodLength
authorize! @namespace, to: :update_automated_workflow_executions?
@workflow = Irida::Pipelines.instance.find_pipeline_by(@automated_workflow_execution.metadata['workflow_name'],
@automated_workflow_execution.metadata['workflow_version'],
'available')
render turbo_stream: turbo_stream.update('automated_workflow_execution_modal',
partial: 'edit_dialog',
locals: {
open: true
}), status: :ok

respond_to do |format|
format.turbo_stream do
if @automated_workflow_execution.disabled
render status: :unprocessable_entity,
locals: {
type: 'alert', message: t('.error',
workflow_name: @automated_workflow_execution.id)
}
else
render status: :ok
end
end
end
end

def create # rubocop:disable Metrics/MethodLength
Expand Down
2 changes: 1 addition & 1 deletion app/jobs/automated_workflow_executions/launch_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class LaunchJob < ApplicationJob
queue_as :default

def perform(sample, pe_attachment_pair)
sample.project.namespace.automated_workflow_executions.each do |awe|
sample.project.namespace.automated_workflow_executions.where(disabled: false).find_each do |awe|
AutomatedWorkflowExecutions::LaunchService.new(awe, sample, pe_attachment_pair,
sample.project.namespace.automation_bot).execute
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
<td class="px-6 py-4 whitespace-nowrap">
<%= local_time_ago(automated_workflow_execution["updated_at"]) %>
</td>
<td class="px-6 py-4 whitespace-nowrap">
<% if automated_workflow_execution["disabled"] %>
<%= viral_pill(text: t(:".disabled"), color: "red") %>
<% else %>
<%= viral_pill(text: t(:".enabled"), color: "green") %>
<% end %>
</td>
<td
class="
px-6 py-4 space-x-2 whitespace-nowrap sticky right-0 bg-white dark:bg-slate-800
Expand All @@ -48,17 +55,20 @@
class:
"font-medium text-blue-600 underline dark:text-blue-500 hover:no-underline cursor-pointer",
) %>
<%= link_to t(:"projects.automated_workflow_executions.actions.edit_button"),
edit_namespace_project_automated_workflow_execution_path(
@project.parent,
@project,
automated_workflow_execution,
),
data: {
turbo_stream: true,
},
class:
"font-medium text-blue-600 underline dark:text-blue-500 hover:no-underline cursor-pointer" %>

<% unless automated_workflow_execution.disabled %>
<%= link_to(
t(:"projects.automated_workflow_executions.actions.edit_button"),
edit_namespace_project_automated_workflow_execution_path(
@project.parent,
@project,
automated_workflow_execution,
),
data: {
turbo_stream: true,
},
class:
"font-medium text-blue-600 underline dark:text-blue-500 hover:no-underline cursor-pointer",
) %>
<% end %>
</td>
</tr>
99 changes: 46 additions & 53 deletions app/views/projects/automated_workflow_executions/_table.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,70 +2,63 @@
<table
id="automated_workflow_executions"
class="
w-full
text-sm
text-left
rtl:text-right
text-slate-500
dark:text-slate-400
dark:divide-slate-600
whitespace-nowrap
"
w-full text-sm text-left rtl:text-right text-slate-500 dark:text-slate-400
dark:divide-slate-600 whitespace-nowrap
"
>
<thead
class="
text-slate-700
uppercase
bg-slate-50
dark:bg-slate-700
dark:text-slate-400
whitespace-nowrap
"
text-slate-700 uppercase bg-slate-50 dark:bg-slate-700 dark:text-slate-400
whitespace-nowrap
"
>
<tr>
<th scope="col" class="px-6 py-3 whitespace-nowrap text-left sticky left-0
bg-slate-50
dark:bg-slate-700">
<%= t(:".headers.id") %>
</th>
<th scope="col" class="px-6 py-3 whitespace-nowrap text-left">
<%= t(:".headers.name") %>
</th>
<th scope="col" class="px-6 py-3 whitespace-nowrap text-left">
<%= t(:".headers.workflow_name") %>
</th>
<th scope="col" class="px-6 py-3 whitespace-nowrap text-left">
<%= t(:".headers.workflow_version") %>
</th>
<th scope="col" class="px-6 py-3 whitespace-nowrap text-left">
<%= t(:".headers.created_at") %>
</th>
<th scope="col" class="px-6 py-3 whitespace-nowrap text-left">
<%= t(:".headers.updated_at") %>
</th>
<th scope="col" class="px-6 py-3 whitespace-nowrap text-left sticky right-0">
<%= t(:".headers.actions") %>
</th>
</tr>
<tr>
<th
scope="col"
class="
px-6 py-3 whitespace-nowrap text-left sticky left-0 bg-slate-50
dark:bg-slate-700
"
>
<%= t(:".headers.id") %>
</th>
<th scope="col" class="px-6 py-3 whitespace-nowrap text-left">
<%= t(:".headers.name") %>
</th>
<th scope="col" class="px-6 py-3 whitespace-nowrap text-left">
<%= t(:".headers.workflow_name") %>
</th>
<th scope="col" class="px-6 py-3 whitespace-nowrap text-left">
<%= t(:".headers.workflow_version") %>
</th>
<th scope="col" class="px-6 py-3 whitespace-nowrap text-left">
<%= t(:".headers.created_at") %>
</th>
<th scope="col" class="px-6 py-3 whitespace-nowrap text-left">
<%= t(:".headers.updated_at") %>
</th>
<th scope="col" class="px-6 py-3 whitespace-nowrap text-left">
<%= t(:".headers.status") %>
</th>
<th scope="col" class="px-6 py-3 whitespace-nowrap text-left sticky right-0">
<%= t(:".headers.actions") %>
</th>
</tr>
</thead>
<tbody
class="
bg-white
divide-y
divide-slate-200
dark:bg-slate-800
dark:divide-slate-700
"
bg-white divide-y divide-slate-200 dark:bg-slate-800 dark:divide-slate-700
"
>
<%= render partial: "automated_workflow_execution",
collection: @automated_workflow_executions %>
<%= render partial: "automated_workflow_execution",
collection: @automated_workflow_executions %>
</tbody>
</table>
<div class="empty_state_message">
<%= viral_empty(
title: t(:".empty.title"),
description: t(:".empty.description"),
icon_name: :document_text
) %>
title: t(:".empty.title"),
description: t(:".empty.description"),
icon_name: :document_text,
) %>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<% if @automated_workflow_execution.disabled %>
<%= turbo_stream.append "flashes" do %>
<%= viral_flash(type:, data: message) %>
<% end %>
<% else %>
<%= turbo_stream.update(
"automated_workflow_execution_modal",
partial: "edit_dialog",
locals: {
open: true,
},
) %>
<% end %>
14 changes: 14 additions & 0 deletions config/initializers/pipelines.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,17 @@
Rails.application.config.to_prepare do
Irida::Pipelines.instance = Irida::Pipelines.new if Irida::Pipelines.instance.nil?
end

Rails.application.config.after_initialize do
if defined?(Rails::Server) ||
(Rails.env.test? && ActiveRecord::Base.connection.table_exists?('automated_workflow_executions'))

AutomatedWorkflowExecution.find_each do |automated_workflow_exectuion|
pipeline = Irida::Pipelines.instance.find_pipeline_by(automated_workflow_exectuion.metadata['workflow_name'],
automated_workflow_exectuion.metadata['workflow_version'],
'automatable')
automated_workflow_exectuion.disabled = pipeline ? !pipeline.executable : true
automated_workflow_exectuion.save
end
end
end
6 changes: 6 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1019,12 +1019,17 @@ en:
delete_button: Delete
delete_confirm: Are you sure that you want to delete this automated pipeline?
edit_button: Edit
automated_workflow_execution:
disabled: DISABLED
enabled: ENABLED
create:
error: Could not create an automated pipeline for %{workflow_name}
success: Automated pipeline for %{workflow_name} was successfully created
destroy:
error: Could not delete automated pipeline for %{workflow_name}
success: Automated pipeline for %{workflow_name} was successfully deleted
edit:
error: Cannot edit automated pipeline %{workflow_name}
edit_dialog:
title: 'Editing Automated Pipeline: %{workflow_name}'
index:
Expand All @@ -1044,6 +1049,7 @@ en:
created_at: Created
id: ID
name: Name
status: Status
updated_at: Updated
workflow_name: Workflow Name
workflow_version: Workflow Version
Expand Down
6 changes: 6 additions & 0 deletions config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1019,12 +1019,17 @@ fr:
delete_button: Delete
delete_confirm: Are you sure that you want to delete this automated pipeline?
edit_button: Edit
automated_workflow_execution:
disabled: DISABLED
enabled: ENABLED
create:
error: Could not create an automated pipeline for %{workflow_name}
success: Automated pipeline for %{workflow_name} was successfully created
destroy:
error: Could not delete automated pipeline for %{workflow_name}
success: Automated pipeline for %{workflow_name} was successfully deleted
edit:
error: Cannot edit automated pipeline %{workflow_name}
edit_dialog:
title: 'Editing Automated Pipeline: %{workflow_name}'
index:
Expand All @@ -1044,6 +1049,7 @@ fr:
created_at: Created
id: ID
name: Name
status: Status
updated_at: Updated
workflow_name: Workflow Name
workflow_version: Workflow Version
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

# Migration to add a new disabled column to the automated workflow executions table
class AddDisabledToAutomatedWorkflowExecutions < ActiveRecord::Migration[7.2]
def change
add_column :automated_workflow_executions, :disabled, :boolean, default: false, null: false
end
end
3 changes: 2 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions test/config/pipelines_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# frozen_string_literal: true

require 'test_helper'

class PipelinesTest < ActiveSupport::TestCase
test 'disable automated workflow executions after pipeline registration' do
assert_not Irida::Pipelines.instance.available_pipelines.empty?
pipeline = Irida::Pipelines.instance.available_pipelines['phac-nml/iridanextexample_1.0.0']
assert_not_nil pipeline
assert_not pipeline.executable

automated_workflow_execution = AutomatedWorkflowExecution.find_by(
"metadata ->> 'workflow_name' = ? and metadata ->> 'workflow_version' = ?", pipeline.name, pipeline.version
)
assert_not_nil automated_workflow_execution
assert_not automated_workflow_execution.disabled

load Rails.root.join('config/initializers/pipelines.rb')

assert automated_workflow_execution.reload.disabled
end

test 'disable automated workflow executions after pipeline registration when the pipeline has been removed' do
pipeline_name = 'phac-nml/iridanextexample'
pipeline_version = '1.0.4'
assert_not Irida::Pipelines.instance.available_pipelines.empty?
assert_nil Irida::Pipelines.instance.available_pipelines["#{pipeline_name}_#{pipeline_version}"]

automated_workflow_execution = AutomatedWorkflowExecution.find_by(
"metadata ->> 'workflow_name' = ? and metadata ->> 'workflow_version' = ?", pipeline_name, pipeline_version
)
assert_not_nil automated_workflow_execution
assert_not automated_workflow_execution.disabled

load Rails.root.join('config/initializers/pipelines.rb')

assert automated_workflow_execution.reload.disabled
end
end
Loading

0 comments on commit 4b40c22

Please sign in to comment.