fix: a crawl cancel waits for its job, and a stale crawl is ended
Cancelling a running crawl records cancel_requested_at and leaves the row running until its job stops and writes cancelled, so no second crawl starts and the row cannot be deleted or pruned meanwhile. The job writes heartbeat_at every minute; a running crawl without a heartbeat for 10 minutes is ended by the next start or delete.
This commit is contained in:
31
updates/202611040002_add_golem15_seo_crawls_heartbeat.go
Normal file
31
updates/202611040002_add_golem15_seo_crawls_heartbeat.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package updates
|
||||
|
||||
import (
|
||||
"github.com/go-gormigrate/gormigrate/v2"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// addCrawlsHeartbeat adds heartbeat_at and cancel_requested_at to
|
||||
// golem15_seo_crawls (P33-60): a running crawl's job writes heartbeat_at
|
||||
// every minute, so a crawl whose job is gone is recognised and ended; a
|
||||
// cancel of a running crawl records cancel_requested_at and leaves the
|
||||
// terminal status to the job.
|
||||
var addCrawlsHeartbeat = []*gormigrate.Migration{
|
||||
{
|
||||
ID: "202611040002_add_golem15_seo_crawls_heartbeat",
|
||||
Migrate: func(tx *gorm.DB) error {
|
||||
return tx.Exec(`ALTER TABLE golem15_seo_crawls
|
||||
ADD COLUMN heartbeat_at TIMESTAMP(0) NULL,
|
||||
ADD COLUMN cancel_requested_at TIMESTAMP(0) NULL`).Error
|
||||
},
|
||||
Rollback: func(tx *gorm.DB) error {
|
||||
return tx.Exec(`ALTER TABLE golem15_seo_crawls
|
||||
DROP COLUMN IF EXISTS cancel_requested_at,
|
||||
DROP COLUMN IF EXISTS heartbeat_at`).Error
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
Register(addCrawlsHeartbeat...)
|
||||
}
|
||||
Reference in New Issue
Block a user