Sha256: 2641b334b3855c44f187dfbad366884a9f61e9889b307de77a9b66b96e1aaa9f

Contents?: true

Size: 1.04 KB

Versions: 6

Compression:

Stored size: 1.04 KB

Contents

module RailsExecution
  module Services
    class TaskScheduler

      def self.call(task_id)
        self.new(task_id).call
      end

      def initialize(task_id)
        @task = Task.find(task_id)
      end

      def call
        task.with_lock do
          next unless task.is_approved? || task.is_processing? && task.scheduled_at.present?
          execute_service = ::RailsExecution::Services::Execution.new(task)
          if execute_service.call
            task.update(status: :completed) unless task.repeatable?
            task.activities.create(owner: task.owner, message: 'Execute: Task completed successfully')
            ::RailsExecution.configuration.notifier.new(task).after_execute_success(task.owner)
            ::RailsExecution::Services::CreateScheduledJob.new(task).call if task.repeatable?
          else
            task.update(status: :failed)
            ::RailsExecution.configuration.notifier.new(task).after_execute_fail(task.owner)
          end
        end
      end

      private

      attr_reader :task

    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rails_execution-0.1.12 lib/rails_execution/services/task_scheduler.rb
rails_execution-0.1.11 lib/rails_execution/services/task_scheduler.rb
rails_execution-0.1.10 lib/rails_execution/services/task_scheduler.rb
rails_execution-0.1.9 lib/rails_execution/services/task_scheduler.rb
rails_execution-0.1.8 lib/rails_execution/services/task_scheduler.rb
rails_execution-0.1.7 lib/rails_execution/services/task_scheduler.rb