add git job for queuing

This commit is contained in:
Donovan Daniels 2024-10-21 01:32:17 -05:00
parent 42ec01d2f5
commit e61efff10a
Signed by: Donovan_DMC
GPG Key ID: 907D29CBFD6157BA
9 changed files with 32 additions and 13 deletions

20
app/jobs/git_job.rb Normal file
View File

@ -0,0 +1,20 @@
# frozen_string_literal: true
class GitJob < ApplicationJob
queue_as :git
good_job_control_concurrency_with(perform_limit: 1)
# used for locking
def perform(_identifier, *commands)
commands.each do |command|
system!(command)
end
end
private
def system!(*)
system(*, exception: true, chdir: base_path)
end
end

View File

@ -97,7 +97,7 @@ module DiscordInteractions
when 1
base = options.find { |o| o["name"] == sub[0] && o["type"] == DiscordConstants::ApplicationCommandOptionTypes::SUB_COMMAND }.try(:[], "options")
when 2
base = options.find { |o| o["name"] == sub[0] && o["type"] == DiscordConstants::ApplicationCommandOptionTypes::SUB_COMMAND_GROUP }.try(:[], "options").try(:find, &(->(o) { o["name"] == sub[1] && o["type"] == DiscordConstants::ApplicationCommandOptionTypes::SUB_COMMAND })).try(:[], "options")
base = options.find { |o| o["name"] == sub[0] && o["type"] == DiscordConstants::ApplicationCommandOptionTypes::SUB_COMMAND_GROUP }.try(:[], "options").try(:find, &->(o) { o["name"] == sub[1] && o["type"] == DiscordConstants::ApplicationCommandOptionTypes::SUB_COMMAND }).try(:[], "options")
else
base = nil
end

View File

@ -457,7 +457,7 @@ module DiscordInteractions
hash.each_with_object({}) do |(k, v), h|
if v.is_a?(Hash)
flatten_hash(v).map do |h_k, h_v|
h["#{k}.#{h_k}".to_sym] = h_v
h[:"#{k}.#{h_k}"] = h_v
end
else
h[k] = v

View File

@ -39,7 +39,7 @@ class RateLimiter::InMemory < RateLimiter
private
def consume(key, window, limit)
(list[key] || { count: 0, expiry: nil }) => { count:, expiry: }
list[key] || { count: 0, expiry: nil } => { count:, expiry: }
if expiry && expiry < Time.now.to_i
list.delete(key)

View File

@ -5,17 +5,13 @@ module StorageManager
def delete(path)
return unless exists?(path)
super
system!("git add #{base_path}#{path}")
system!("git commit -m \"Remove #{path[1..]}\"")
system!("git push")
GitJob.perform_later("#{base_path}#{path}", "git add #{base_path}#{path}", "git commit -m \"Remove #{path[1..]}\"", "git push")
end
def put(path, io)
super
if exists?(path)
system!("git add #{base_path}#{path}")
system!("git commit -m \"Add #{path[1..]}\"")
system!("git push")
if exists?(path) # rubocop:disable Style/IfUnlessModifier
GitJob.perform_later("#{base_path}#{path}", "git add #{base_path}#{path}", "git commit -m \"Add #{path[1..]}\"", "git push")
end
end

View File

@ -14,11 +14,11 @@ class ApplicationRecord < ActiveRecord::Base
options[:methods] ||= []
options[:methods] += method_attributes
super(options)
super
end
def serializable_hash(*args)
hash = super(*args)
def serializable_hash(*)
hash = super
hash.transform_keys { |key| key.delete("?") }
end

View File

@ -1,4 +1,5 @@
# frozen_string_literal: true
# Be sure to restart your server when you modify this file.
# Define an application-wide content security policy.

View File

@ -1,4 +1,5 @@
# frozen_string_literal: true
# Be sure to restart your server when you modify this file.
# Define an application-wide HTTP permissions policy. For further

View File

@ -1,4 +1,5 @@
# frozen_string_literal: true
# This file should ensure the existence of records required to run the application in every environment (production,
# development, test). The code here should be idempotent so that it can be executed at any point in every environment.
# The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup).