Skip to content

Commit

Permalink
chore: Cleanup Datetime from timestamp (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aursen authored Jun 17, 2024
1 parent 1df0651 commit 866df92
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 39 deletions.
9 changes: 2 additions & 7 deletions cli/src/processor/crontab.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use chrono::{DateTime, Utc};
use chrono::DateTime;
use sablier_cron::Schedule;
use std::str::FromStr;

Expand All @@ -9,12 +9,7 @@ pub fn get(client: &Client, schedule: String) -> Result<(), CliError> {
let schedule = Schedule::from_str(schedule.as_str()).unwrap();

let mut i = 0;
for t in schedule.after(&DateTime::<Utc>::from_naive_utc_and_offset(
DateTime::from_timestamp(clock.unix_timestamp, 0)
.unwrap()
.naive_utc(),
Utc,
)) {
for t in schedule.after(&DateTime::from_timestamp(clock.unix_timestamp, 0).unwrap()) {
println!("{:#?}", t);
i += 1;
if i > 8 {
Expand Down
8 changes: 2 additions & 6 deletions plugin/src/builders/thread_exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,10 @@ pub async fn build_thread_exec_tx(
// If there was a simulation error, stop packing and exit now.
Err(err) => {
if let solana_client::client_error::ClientErrorKind::RpcError(
solana_client::rpc_request::RpcError::RpcResponseError {
code,
message: _,
data: _,
},
solana_client::rpc_request::RpcError::RpcResponseError { code, .. },
) = err.kind
{
if code.eq(&JSON_RPC_SERVER_ERROR_MIN_CONTEXT_SLOT_NOT_REACHED) {
if code == JSON_RPC_SERVER_ERROR_MIN_CONTEXT_SLOT_NOT_REACHED {
return Err(GeyserPluginError::Custom(
"RPC client has not reached min context slot".into(),
));
Expand Down
31 changes: 10 additions & 21 deletions plugin/src/observers/thread.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
use std::{
collections::{HashMap, HashSet},
fmt::Debug,
str::FromStr,
sync::{atomic::AtomicU64, Arc},
};

use chrono::{DateTime, Utc};
use chrono::DateTime;
use log::info;
use pyth_sdk_solana::PriceFeed;
use sablier_cron::Schedule;
Expand All @@ -14,6 +7,12 @@ use solana_geyser_plugin_interface::geyser_plugin_interface::{
GeyserPluginError, Result as PluginResult,
};
use solana_program::{clock::Clock, pubkey::Pubkey};
use std::{
collections::{HashMap, HashSet},
fmt::Debug,
str::FromStr,
sync::{atomic::AtomicU64, Arc},
};
use tokio::sync::RwLock;

#[derive(Default)]
Expand Down Expand Up @@ -221,11 +220,7 @@ impl ThreadObserver {
} else {
// Otherwise, index the thread according to its trigger type.
match thread.trigger() {
Trigger::Account {
address,
offset: _,
size: _,
} => {
Trigger::Account { address, .. } => {
// Index the thread by its trigger's account pubkey.
let mut w_account_threads = self.account_threads.write().await;
w_account_threads
Expand All @@ -246,10 +241,7 @@ impl ThreadObserver {
w_now_threads.insert(thread_pubkey);
drop(w_now_threads);
}
Trigger::Cron {
schedule,
skippable: _,
} => {
Trigger::Cron { schedule, .. } => {
// Find a reference timestamp for calculating the thread's upcoming target time.
let reference_timestamp = match thread.exec_context() {
None => thread.created_at().unix_timestamp,
Expand Down Expand Up @@ -372,10 +364,7 @@ fn next_moment(after: i64, schedule: String) -> Option<i64> {
match Schedule::from_str(&schedule) {
Err(_) => None,
Ok(schedule) => schedule
.next_after(&DateTime::<Utc>::from_naive_utc_and_offset(
DateTime::from_timestamp(after, 0).unwrap().naive_utc(),
Utc,
))
.next_after(&DateTime::from_timestamp(after, 0).unwrap())
.take()
.map(|datetime| datetime.timestamp()),
}
Expand Down
7 changes: 2 additions & 5 deletions programs/thread/src/instructions/thread_kickoff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{
};

use anchor_lang::prelude::*;
use chrono::{DateTime, Utc};
use chrono::DateTime;
use pyth_sdk_solana::state::SolanaPriceAccount;
use sablier_cron::Schedule;
use sablier_network_program::state::{Worker, WorkerAccount};
Expand Down Expand Up @@ -265,10 +265,7 @@ pub fn handler(ctx: Context<ThreadKickoff>) -> Result<()> {
fn next_timestamp(after: i64, schedule: String) -> Option<i64> {
Schedule::from_str(&schedule)
.unwrap()
.next_after(&DateTime::<Utc>::from_naive_utc_and_offset(
DateTime::from_timestamp(after, 0).unwrap().naive_utc(),
Utc,
))
.next_after(&DateTime::from_timestamp(after, 0).unwrap())
.take()
.map(|datetime| datetime.timestamp())
}

0 comments on commit 866df92

Please sign in to comment.