Skip to content

Commit 93422a0

Browse files
emmaling27Convex, Inc.
authored andcommitted
Add _scheduled_job_args system table (#42976)
Add a new system table for storing scheduled job arguments with an index on job id. GitOrigin-RevId: 67da6cdabced9c277b6b2b050a35d6ee3c72e562
1 parent d2de546 commit 93422a0

File tree

5 files changed

+80
-2
lines changed

5 files changed

+80
-2
lines changed

crates/migrations_model/src/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub type DatabaseVersion = i64;
3030
// migrations unless explicitly dropping support.
3131
// Add a user name next to the version when you make a change to highlight merge
3232
// conflicts.
33-
pub const DATABASE_VERSION: DatabaseVersion = 122; // emma
33+
pub const DATABASE_VERSION: DatabaseVersion = 123; // emma
3434

3535
pub struct MigrationExecutor<RT: Runtime> {
3636
pub db: Database<RT>,
@@ -81,6 +81,11 @@ impl<RT: Runtime> MigrationExecutor<RT> {
8181
// table for each component, _schema_validation_progress
8282
MigrationCompletionCriterion::MigrationComplete(to_version)
8383
},
84+
123 => {
85+
// This is an empty migration because we added a new system
86+
// table for each component, _scheduled_job_args
87+
MigrationCompletionCriterion::MigrationComplete(to_version)
88+
},
8489
// NOTE: Make sure to increase DATABASE_VERSION when adding new migrations.
8590
_ => anyhow::bail!("Version did not define a migration! {}", to_version),
8691
};

crates/model/src/lib.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ use crate::{
199199
exports::ExportsTable,
200200
external_packages::EXTERNAL_PACKAGES_TABLE,
201201
log_sinks::LOG_SINKS_TABLE,
202+
scheduled_jobs::args::{
203+
ScheduledJobArgsTable,
204+
SCHEDULED_JOBS_ARGS_TABLE,
205+
},
202206
};
203207

204208
pub mod airbyte_import;
@@ -266,9 +270,10 @@ enum DefaultTableNumber {
266270
CronNextRun = 35,
267271
IndexBackfills = 36,
268272
SchemaValidationProgress = 37,
273+
ScheduledJobArgs = 38,
269274
// Keep this number and your user name up to date. The number makes it easy to know
270275
// what to use next. The username on the same line detects merge conflicts
271-
// Next Number - 38 - emma
276+
// Next Number - 39 - emma
272277
}
273278

274279
impl From<DefaultTableNumber> for TableNumber {
@@ -312,6 +317,7 @@ impl From<DefaultTableNumber> for &'static dyn ErasedSystemTable {
312317
DefaultTableNumber::CronNextRun => &CronNextRunTable,
313318
DefaultTableNumber::IndexBackfills => &IndexBackfillTable,
314319
DefaultTableNumber::SchemaValidationProgress => &SchemaValidationProgressTable,
320+
DefaultTableNumber::ScheduledJobArgs => &ScheduledJobArgsTable,
315321
}
316322
}
317323
}
@@ -553,6 +559,7 @@ pub fn component_system_tables() -> Vec<&'static dyn ErasedSystemTable> {
553559
vec![
554560
&FileStorageTable,
555561
&ScheduledJobsTable,
562+
&ScheduledJobArgsTable,
556563
&CronJobsTable,
557564
&CronJobLogsTable,
558565
&CronNextRunTable,
@@ -629,6 +636,7 @@ pub static FIRST_SEEN_TABLE: LazyLock<BTreeMap<TableName, DatabaseVersion>> = La
629636
CANONICAL_URLS_TABLE.clone() => 116,
630637
INDEX_BACKFILLS_TABLE.clone() => 120,
631638
SCHEMA_VALIDATION_PROGRESS_TABLE.clone() => 122,
639+
SCHEDULED_JOBS_ARGS_TABLE.clone() => 123,
632640
}
633641
});
634642

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
use std::sync::LazyLock;
2+
3+
use database::system_tables::{
4+
SystemIndex,
5+
SystemTable,
6+
};
7+
use value::TableName;
8+
9+
use crate::scheduled_jobs::types::ScheduledJobArgs;
10+
11+
pub static SCHEDULED_JOBS_ARGS_TABLE: LazyLock<TableName> = LazyLock::new(|| {
12+
"_scheduled_job_args"
13+
.parse()
14+
.expect("_scheduled_job_args is not a valid system table name")
15+
});
16+
17+
pub struct ScheduledJobArgsTable;
18+
19+
impl SystemTable for ScheduledJobArgsTable {
20+
type Metadata = ScheduledJobArgs;
21+
22+
fn table_name() -> &'static TableName {
23+
&SCHEDULED_JOBS_ARGS_TABLE
24+
}
25+
26+
fn indexes() -> Vec<SystemIndex<Self>> {
27+
vec![]
28+
}
29+
}

crates/model/src/scheduled_jobs/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ use crate::{
6969
SystemTable,
7070
};
7171

72+
pub mod args;
7273
pub mod types;
7374
pub mod virtual_table;
7475

crates/model/src/scheduled_jobs/types.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,3 +270,38 @@ mod state {
270270

271271
codegen_convex_serialization!(ScheduledJobState, SerializedScheduledJobState);
272272
}
273+
274+
#[derive(Debug, Clone, PartialEq)]
275+
#[cfg_attr(any(test, feature = "testing"), derive(proptest_derive::Arbitrary))]
276+
pub struct ScheduledJobArgs {
277+
#[cfg_attr(
278+
any(test, feature = "testing"),
279+
proptest(
280+
strategy = "proptest::arbitrary::any_with::<ConvexArray>((0..4).into()).\
281+
prop_map(args_to_bytes).prop_filter_map(\"invalid json\", |b| b.ok())"
282+
)
283+
)]
284+
args: ByteBuf,
285+
}
286+
287+
#[derive(Debug, Serialize, Deserialize)]
288+
#[serde(rename_all = "camelCase")]
289+
pub struct SerializedScheduledJobArgs {
290+
args: ByteBuf,
291+
}
292+
293+
impl From<ScheduledJobArgs> for SerializedScheduledJobArgs {
294+
fn from(value: ScheduledJobArgs) -> SerializedScheduledJobArgs {
295+
SerializedScheduledJobArgs { args: value.args }
296+
}
297+
}
298+
299+
impl TryFrom<SerializedScheduledJobArgs> for ScheduledJobArgs {
300+
type Error = anyhow::Error;
301+
302+
fn try_from(value: SerializedScheduledJobArgs) -> anyhow::Result<Self> {
303+
Ok(ScheduledJobArgs { args: value.args })
304+
}
305+
}
306+
307+
codegen_convex_serialization!(ScheduledJobArgs, SerializedScheduledJobArgs);

0 commit comments

Comments
 (0)