mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(backup): run scheduled job transitions in the caller's account (#4965)
startBackupJob and stopBackupJob schedule transitionJob, completeJob and abortJob on the backup-job-scheduler executor. That thread has no request context, so the account-aware job, recovery-point and vault stores, and regionResolver.buildArn, all resolved the default account 000000000000. A job started from any other account was therefore never found on the scheduler thread: it stayed CREATED (or ABORTING) forever, no recovery point was written, and the vault kept NumberOfRecoveryPoints=0, so DeleteBackupVault's non-empty guard let the vault be deleted. Capture the caller's account on the request thread and run each scheduled body under RequestScopes.runAs, the idiom EcsService, EksService and DynamoDbService already use for background work.
This commit is contained in:
1 parent
0bae2f0e35
commit
e25f488bf3
2 files changed
+88
-6
No files matched your search
@@ -7,6 +7,7 @@ import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.AwsArnUtils;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.common.RequestScopes;
|
||||
import io.github.hectorvent.floci.core.storage.StorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
import io.github.hectorvent.floci.services.backup.model.*;
|
||||
@@ -598,11 +599,16 @@ public class BackupService {
|
||||
job.setCreationDate(now);
|
||||
job.setExpectedCompletionDate(now + jobCompletionDelaySeconds);
|
||||
job.setStartBy(now + 3600L);
|
||||
job.setAccountId(regionResolver.getAccountId());
|
||||
String accountId = regionResolver.getAccountId();
|
||||
job.setAccountId(accountId);
|
||||
jobStore.put(jobId, job);
|
||||
|
||||
scheduler.schedule(() -> transitionJob(jobId, vaultName, region), 1, TimeUnit.SECONDS);
|
||||
scheduler.schedule(() -> completeJob(jobId, vaultName, region), jobCompletionDelaySeconds, TimeUnit.SECONDS);
|
||||
// The scheduler thread has no request context; run in the caller's account
|
||||
// so the account-aware stores and buildArn resolve the right partition.
|
||||
scheduler.schedule(() -> RequestScopes.runAs(accountId,
|
||||
() -> transitionJob(jobId, vaultName, region)), 1, TimeUnit.SECONDS);
|
||||
scheduler.schedule(() -> RequestScopes.runAs(accountId,
|
||||
() -> completeJob(jobId, vaultName, region)), jobCompletionDelaySeconds, TimeUnit.SECONDS);
|
||||
|
||||
return job;
|
||||
}
|
||||
@@ -622,7 +628,8 @@ public class BackupService {
|
||||
job.setState("ABORTING");
|
||||
job.setStatusMessage("Job stop requested");
|
||||
jobStore.put(jobId, job);
|
||||
scheduler.schedule(() -> abortJob(jobId), 1, TimeUnit.SECONDS);
|
||||
String accountId = regionResolver.getAccountId();
|
||||
scheduler.schedule(() -> RequestScopes.runAs(accountId, () -> abortJob(jobId)), 1, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
public List<BackupJob> listBackupJobs(String byVaultName, String byState,
|
||||
|
||||
Reference in new issue
Block a user