Add CLI command to run all GC jobs

This commit is contained in:
Saku Laesvuori 2023-09-28 22:03:18 +03:00
parent 1ca82b4907
commit aa7d4826b3
Signed by: slaesvuo
GPG Key ID: 257D284A2A1D3A32
1 changed files with 8 additions and 0 deletions

View File

@ -27,6 +27,7 @@ main = do
(AddUser addUserOpts) -> addUserMain addUserOpts (AddUser addUserOpts) -> addUserMain addUserOpts
GCEmails -> gcEmailsMain GCEmails -> gcEmailsMain
GCApplications -> gcApplicationsMain GCApplications -> gcApplicationsMain
GCAll -> gcAllMain
addUserMain :: AddUserOpts -> CLIM () addUserMain :: AddUserOpts -> CLIM ()
addUserMain AddUserOpts {..} = do addUserMain AddUserOpts {..} = do
@ -62,6 +63,11 @@ gcApplicationsMain :: CLIM ()
gcApplicationsMain = do gcApplicationsMain = do
deleteUsersWithoutEmail deleteUsersWithoutEmail
gcAllMain :: CLIM ()
gcAllMain = do
gcEmailsMain
gcApplicationsMain
cliOptions :: Parser CLIOptions cliOptions :: Parser CLIOptions
cliOptions = CLIOptions cliOptions = CLIOptions
<$> strOption (short 'u' <> long "db-url" <> metavar "URL" <> value "postgres:///datarekisteri-backend") <$> strOption (short 'u' <> long "db-url" <> metavar "URL" <> value "postgres:///datarekisteri-backend")
@ -72,6 +78,7 @@ cliCommandParser = hsubparser
$ command "add-user" (info addUserCommand (progDesc "Add a user to datarekisteri")) $ command "add-user" (info addUserCommand (progDesc "Add a user to datarekisteri"))
<> command "gc-expired-emails" (info (pure GCEmails) (progDesc "Delete emails that have not been verified in time.")) <> command "gc-expired-emails" (info (pure GCEmails) (progDesc "Delete emails that have not been verified in time."))
<> command "gc-applications" (info (pure GCApplications) (progDesc "Delete users without an email address")) <> command "gc-applications" (info (pure GCApplications) (progDesc "Delete users without an email address"))
<> command "gc" (info (pure GCAll) (progDesc "Run all garbage collection jobs."))
addUserCommand :: Parser CLISubCommand addUserCommand :: Parser CLISubCommand
addUserCommand = fmap AddUser $ AddUserOpts addUserCommand = fmap AddUser $ AddUserOpts
@ -97,6 +104,7 @@ data CLIOptions = CLIOptions
data CLISubCommand = AddUser AddUserOpts data CLISubCommand = AddUser AddUserOpts
| GCEmails | GCEmails
| GCApplications | GCApplications
| GCAll
data AddUserOpts = AddUserOpts data AddUserOpts = AddUserOpts
{ addUserNickname :: Maybe Text { addUserNickname :: Maybe Text