Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
Example backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Thomas SAUVAGE
Example backend
Commits
8cbf08ac
Unverified
Commit
8cbf08ac
authored
1 year ago
by
Thomas SAUVAGE
Browse files
Options
Downloads
Patches
Plain Diff
Better cron
parent
22f5d852
No related branches found
No related tags found
1 merge request
!4
Trying to implement openid
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/Controllers/cron.ts
+18
-5
18 additions, 5 deletions
app/Controllers/cron.ts
with
18 additions
and
5 deletions
app/Controllers/cron.ts
+
18
−
5
View file @
8cbf08ac
import
AuthCodeVerifier
from
'
App/Models/AuthCodeVerifier
'
import
AuthCodeVerifier
from
'
App/Models/AuthCodeVerifier
'
// TODO: Fix this
const
sqlRequest
=
"
created_at > current_date - interval '1' hour
"
export
const
cronRemoveOldCodeVerifiers
=
async
()
=>
{
console
.
log
(
'
Before:
'
,
await
AuthCodeVerifier
.
all
())
/** Remove old code verifiers from the database `AuthCodeVerifier`
await
AuthCodeVerifier
.
query
().
delete
().
whereRaw
(
"
created_at < current_date - interval '1' hour
"
)
* Code verifiers must be stored between the moment:
console
.
log
(
'
After:
'
,
await
AuthCodeVerifier
.
all
())
* - the user ask for a login to `auth.binets.fr`: codeVerifier is created
* - the user as entered his login: codeVerifier is deleted
*
* => If the user never enter his login, codeVerifier is never deleted.
* Therefor we need to execute this cron regularly
* */
export
const
cronRemoveOldCodeVerifiers
=
async
({
response
})
=>
{
const
willBeDeleted
=
await
AuthCodeVerifier
.
query
().
whereRaw
(
sqlRequest
)
await
AuthCodeVerifier
.
query
().
delete
().
whereRaw
(
sqlRequest
)
return
response
.
ok
({
message
:
'
Old code verifiers successfully deleted
'
,
deletedCodeVerifiersCreatedAt
:
willBeDeleted
.
map
(({
createdAt
})
=>
createdAt
.
toString
()),
})
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment