Skip to content

Commit

Permalink
Merge pull request #18 from chonla/main
Browse files Browse the repository at this point in the history
Add purging
  • Loading branch information
chonla authored Oct 24, 2024
2 parents 4391c92 + e0540ad commit e0ee77d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/purgedraft.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: "Purge obsolete draft"

on:
schedule:
- cron: "0 0 * * *"

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: curl
uses: enflo/curl-action@master
with:
curl: ${{ env.CURL_ARGUMENTS }}
21 changes: 17 additions & 4 deletions cdmm/app/controllers/cdmm_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,16 @@ class CdmmController < ApplicationController
# draft form will be purged regularly

def purge
Evaluation.where(:form_status => :draft).destroy_all
render_empty
deleted_rows = Evaluation.where(:form_status => :draft, :created_at => ...6.hours.ago)
deleted_count = deleted_rows.count
deleted_rows.destroy_all
headers = [
{
:key => "X-Rows-Affected",
:value => "#{deleted_count}"
}
]
render_empty headers
end

def index
Expand Down Expand Up @@ -699,9 +707,14 @@ def generate_unique_form_key
end
end

def render_empty
def render_empty(headers = [])
respond_to do |format|
format.any { head :ok }
format.any do
headers.each do |header|
response.headers[header[:key]] = header[:value]
end
head :ok
end
end
end

Expand Down

0 comments on commit e0ee77d

Please sign in to comment.