Skip to content

Commit 23f8cb9

Browse files
goffrieConvex, Inc.
authored andcommitted
Store ComponentId in CronJob (#36317)
.. so that we can correctly determine the component when re-querying it GitOrigin-RevId: 98638fc28efafb3cddddbfbd52b186098d4dbb08
1 parent 2682864 commit 23f8cb9

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

crates/application/src/cron_jobs/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ impl<RT: Runtime> CronJobExecutor<RT> {
642642
.begin_with_usage(Identity::Unknown(None), usage_tracker)
643643
.await?;
644644
// Verify that the cron job has not changed.
645-
let new_job = CronModel::new(&mut tx, ComponentId::Root)
645+
let new_job = CronModel::new(&mut tx, expected_state.component)
646646
.get(expected_state.id)
647647
.await?;
648648
Ok((new_job.as_ref() == Some(expected_state)).then_some(tx))

crates/model/src/cron_jobs/mod.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ impl<'a, RT: Runtime> CronModel<'a, RT> {
392392
.await?
393393
.context("No next run found")?
394394
.into_value();
395-
Ok(Some(CronJob::new(cron, next_run)))
395+
Ok(Some(CronJob::new(cron, self.component, next_run)))
396396
}
397397

398398
pub async fn list(&mut self) -> anyhow::Result<BTreeMap<CronIdentifier, CronJob>> {
@@ -406,7 +406,10 @@ impl<'a, RT: Runtime> CronModel<'a, RT> {
406406
.await?
407407
.context("No next run found")?
408408
.into_value();
409-
cron_jobs.insert(cron.name.clone(), CronJob::new(cron, next_run));
409+
cron_jobs.insert(
410+
cron.name.clone(),
411+
CronJob::new(cron, self.component, next_run),
412+
);
410413
}
411414
Ok(cron_jobs)
412415
}
@@ -476,7 +479,7 @@ pub async fn stream_cron_jobs_to_run<'a, RT: Runtime>(tx: &'a mut Transaction<RT
476479
.await?
477480
.context("No cron job found")?
478481
.parse()?;
479-
Ok::<_, anyhow::Error>(CronJob::new(job, next_run.into_value()))
482+
Ok::<_, anyhow::Error>(CronJob::new(job, namespace.into(), next_run.into_value()))
480483
};
481484

482485
// Initialize streaming query for each namespace

crates/model/src/cron_jobs/types.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use anyhow::{
1111
Context,
1212
};
1313
use common::{
14+
components::ComponentId,
1415
document::ParsedDocument,
1516
log_lines::RawLogLines,
1617
types::Timestamp,
@@ -53,6 +54,9 @@ pub struct CronJob {
5354
// Id into _cron_jobs table
5455
pub id: ResolvedDocumentId,
5556

57+
// The component that defined the job
58+
pub component: ComponentId,
59+
5660
// Unique identifier of a cron
5761
pub name: CronIdentifier,
5862

@@ -66,10 +70,15 @@ pub struct CronJob {
6670
}
6771

6872
impl CronJob {
69-
pub(crate) fn new(cron: ParsedDocument<CronJobMetadata>, next_run: CronNextRun) -> Self {
73+
pub(crate) fn new(
74+
cron: ParsedDocument<CronJobMetadata>,
75+
component: ComponentId,
76+
next_run: CronNextRun,
77+
) -> Self {
7078
let (id, cron) = cron.into_id_and_value();
7179
Self {
7280
id,
81+
component,
7382
name: cron.name,
7483
cron_spec: cron.cron_spec,
7584
state: next_run.state,

0 commit comments

Comments
 (0)