Skip to content
This repository has been archived by the owner on Jul 15, 2024. It is now read-only.

Adding support for reading and modifying tasks #3

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.2.2]

### Added
* Add `Duration` struct to ease usage of delays and other methods using string duration formats
* Add Default impl for `Duration`
Expand All @@ -27,6 +29,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Moved `ComRuntime` to `planif::com` module

## [0.2.1]

### Updated
* Update documentation, add deny missing_docs

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ license = "MIT"
repository = "https://github.com/mattrobineau/planif"
version = "1.0.0"
edition = "2021"
keywords = ["scheduled", "task", "windows"]
keywords = ["scheduled", "task", "windows", "schedule", "scheduler"]
categories = ["os::windows-apis"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
30 changes: 15 additions & 15 deletions examples/boot_task.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use planif::enums::TaskCreationFlags;
use planif::schedule_builder::{Action, ComRuntime, ScheduleBuilder};
// use planif::enums::TaskCreationFlags;
// use planif::schedule_builder::{Action, ComRuntime, ScheduleBuilder};

fn main() -> Result<(), Box<dyn std::error::Error>> {
let com = ComRuntime::new()?;
let sb = ScheduleBuilder::new(&com).unwrap();
sb.create_boot()
.author("Matt")?
.description("Test Time Trigger")?
.trigger("test_time_trigger", true)?
.action(Action::new("test_time_action", "notepad.exe", "", ""))?
.start_boundary("2022-04-28T02:14:08.660633427+00:00")?
.build()?
.register("TimeTaskName", TaskCreationFlags::CreateOrUpdate as i32)?;
Ok(())
}
// fn main() -> Result<(), Box<dyn std::error::Error>> {
// let com = ComRuntime::new()?;
// let sb = ScheduleBuilder::new(&com).unwrap();
// sb.create_boot()
// .author("Matt")?
// .description("Test Time Trigger")?
// .trigger("test_time_trigger", true)?
// .action(Action::new("test_time_action", "notepad.exe", "", ""))?
// .start_boundary("2022-04-28T02:14:08.660633427+00:00")?
// .build()?
// .register("TimeTaskName", TaskCreationFlags::CreateOrUpdate as i32)?;
// Ok(())
// }
34 changes: 17 additions & 17 deletions examples/daily_task.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
use chrono::prelude::*;
use planif::enums::TaskCreationFlags;
use planif::schedule_builder::{Action, ComRuntime, ScheduleBuilder};
// use chrono::prelude::*;
// use planif::enums::TaskCreationFlags;
// use planif::schedule_builder::{Action, ComRuntime, ScheduleBuilder};

fn main() -> Result<(), Box<dyn std::error::Error>> {
let com = ComRuntime::new()?;
// fn main() -> Result<(), Box<dyn std::error::Error>> {
// let com = ComRuntime::new()?;

let sb = ScheduleBuilder::new(&com).unwrap();
sb.create_daily()
.author("Matt")?
.description("Test Trigger")?
.trigger("test_trigger", true)?
.days_interval(1)?
.action(Action::new("test", "notepad.exe", "", ""))?
.start_boundary(&Local::now().to_rfc3339())?
.build()?
.register("TaskName", TaskCreationFlags::CreateOrUpdate as i32)?;
// let sb = ScheduleBuilder::new(&com).unwrap();
// sb.create_daily()
// .author("Matt")?
// .description("Test Trigger")?
// .trigger("test_trigger", true)?
// .days_interval(1)?
// .action(Action::new("test", "notepad.exe", "", ""))?
// .start_boundary(&Local::now().to_rfc3339())?
// .build()?
// .register("TaskName", TaskCreationFlags::CreateOrUpdate as i32)?;

Ok(())
}
// Ok(())
// }
42 changes: 21 additions & 21 deletions examples/folder_task.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
use chrono::{Duration, Local};
use planif::enums::TaskCreationFlags;
use planif::schedule_builder::{Action, ScheduleBuilder};
// use chrono::{Duration, Local};
// use planif::enums::TaskCreationFlags;
// use planif::schedule_builder::{Action, ScheduleBuilder};

fn main() -> Result<(), Box<dyn std::error::Error>> {
let sb = ScheduleBuilder::new().unwrap();
// fn main() -> Result<(), Box<dyn std::error::Error>> {
// let sb = ScheduleBuilder::new().unwrap();

sb.create_time()
.author("Matt")?
.description("Test Time Trigger in folder")?
.in_folder("Test folder")?
.trigger("test_time_folder_trigger", true)?
.action(Action::new("test_time_action", "notepad.exe", "", ""))?
.start_boundary(
&Local::now()
.checked_add_signed(Duration::seconds(5))
.unwrap()
.to_rfc3339(),
)?
.build()?
.register("Time Folder Task", TaskCreationFlags::CreateOrUpdate as i32)?;
// sb.create_time()
// .author("Matt")?
// .description("Test Time Trigger in folder")?
// .in_folder("Test folder")?
// .trigger("test_time_folder_trigger", true)?
// .action(Action::new("test_time_action", "notepad.exe", "", ""))?
// .start_boundary(
// &Local::now()
// .checked_add_signed(Duration::seconds(5))
// .unwrap()
// .to_rfc3339(),
// )?
// .build()?
// .register("Time Folder Task", TaskCreationFlags::CreateOrUpdate as i32)?;

Ok(())
}
// Ok(())
// }
32 changes: 16 additions & 16 deletions examples/logon_task.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
use planif::enums::TaskCreationFlags;
use planif::schedule_builder::{Action, ComRuntime, ScheduleBuilder};
// use planif::enums::TaskCreationFlags;
// use planif::schedule_builder::{Action, ComRuntime, ScheduleBuilder};

fn main() -> Result<(), Box<dyn std::error::Error>> {
let com = ComRuntime::new()?;
let sb = ScheduleBuilder::new(&com).unwrap();
sb.create_logon()
.author("Matt")?
.description("Test Time Trigger")?
.trigger("test_time_trigger", true)?
.action(Action::new("test_time_action", "notepad.exe", "", ""))?
.start_boundary("2022-04-28T02:14:08.660633427+00:00")?
.user_id("")?
.build()?
.register("TimeTaskName", TaskCreationFlags::CreateOrUpdate as i32)?;
Ok(())
}
// fn main() -> Result<(), Box<dyn std::error::Error>> {
// let com = ComRuntime::new()?;
// let sb = ScheduleBuilder::new(&com).unwrap();
// sb.create_logon()
// .author("Matt")?
// .description("Test Time Trigger")?
// .trigger("test_time_trigger", true)?
// .action(Action::new("test_time_action", "notepad.exe", "", ""))?
// .start_boundary("2022-04-28T02:14:08.660633427+00:00")?
// .user_id("")?
// .build()?
// .register("TimeTaskName", TaskCreationFlags::CreateOrUpdate as i32)?;
// Ok(())
// }
42 changes: 21 additions & 21 deletions examples/monthly_dow_task.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
use chrono::prelude::*;
use planif::enums::{DayOfWeek, Month, TaskCreationFlags, WeekOfMonth};
use planif::schedule_builder::{Action, ComRuntime, MonthlyDOW, ScheduleBuilder};
// use chrono::prelude::*;
// use planif::enums::{DayOfWeek, Month, TaskCreationFlags, WeekOfMonth};
// use planif::schedule_builder::{Action, ComRuntime, MonthlyDOW, ScheduleBuilder};

fn main() -> Result<(), Box<dyn std::error::Error>> {
let com = ComRuntime::new()?;
let builder: ScheduleBuilder<MonthlyDOW> = ScheduleBuilder::new(&com)?
.create_monthly_dow()
.author("Matt")?
.description("Test Trigger")?
.trigger("MyTrigger", true)?
.action(Action::new("test", "notepad.exe", "", ""))?
.months_of_year(vec![Month::January])?
.days_of_week(vec![DayOfWeek::Monday])?
.weeks_of_month(vec![WeekOfMonth::First])?
.start_boundary(&Local::now().to_rfc3339())?;
// fn main() -> Result<(), Box<dyn std::error::Error>> {
// let com = ComRuntime::new()?;
// let builder: ScheduleBuilder<MonthlyDOW> = ScheduleBuilder::new(&com)?
// .create_monthly_dow()
// .author("Matt")?
// .description("Test Trigger")?
// .trigger("MyTrigger", true)?
// .action(Action::new("test", "notepad.exe", "", ""))?
// .months_of_year(vec![Month::January])?
// .days_of_week(vec![DayOfWeek::Monday])?
// .weeks_of_month(vec![WeekOfMonth::First])?
// .start_boundary(&Local::now().to_rfc3339())?;

builder.build()?.register(
"MonthlyDOWTaskName",
TaskCreationFlags::CreateOrUpdate as i32,
)?;
// builder.build()?.register(
// "MonthlyDOWTaskName",
// TaskCreationFlags::CreateOrUpdate as i32,
// )?;

Ok(())
}
// Ok(())
// }
38 changes: 19 additions & 19 deletions examples/monthly_task.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
use chrono::prelude::*;
use planif::enums::{DayOfMonth, Month, TaskCreationFlags};
use planif::schedule_builder::{Action, ComRuntime, Monthly, ScheduleBuilder};
// use chrono::prelude::*;
// use planif::enums::{DayOfMonth, Month, TaskCreationFlags};
// use planif::schedule_builder::{Action, ComRuntime, Monthly, ScheduleBuilder};

fn main() -> Result<(), Box<dyn std::error::Error>> {
let com = ComRuntime::new()?;
let builder: ScheduleBuilder<Monthly> = ScheduleBuilder::new(&com)?
.create_monthly()
.author("Matt")?
.description("Test Trigger")?
.trigger("MyTrigger", true)?
.action(Action::new("test", "notepad.exe", "", ""))?
.days_of_month(vec![DayOfMonth::Day(1), DayOfMonth::Day(15)])?
.months_of_year(vec![Month::December])?
.start_boundary(&Local::now().to_rfc3339())?;
// fn main() -> Result<(), Box<dyn std::error::Error>> {
// let com = ComRuntime::new()?;
// let builder: ScheduleBuilder<Monthly> = ScheduleBuilder::new(&com)?
// .create_monthly()
// .author("Matt")?
// .description("Test Trigger")?
// .trigger("MyTrigger", true)?
// .action(Action::new("test", "notepad.exe", "", ""))?
// .days_of_month(vec![DayOfMonth::Day(1), DayOfMonth::Day(15)])?
// .months_of_year(vec![Month::December])?
// .start_boundary(&Local::now().to_rfc3339())?;

builder
.build()?
.register("MonthlyTaskName", TaskCreationFlags::CreateOrUpdate as i32)?;
// builder
// .build()?
// .register("MonthlyTaskName", TaskCreationFlags::CreateOrUpdate as i32)?;

Ok(())
}
// Ok(())
// }
62 changes: 31 additions & 31 deletions examples/multiple_tasks.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
use chrono::prelude::*;
use planif::enums::TaskCreationFlags;
use planif::schedule_builder::{Action, ComRuntime, ScheduleBuilder};
// use chrono::prelude::*;
// use planif::enums::TaskCreationFlags;
// use planif::schedule_builder::{Action, ComRuntime, ScheduleBuilder};

fn main() -> Result<(), Box<dyn std::error::Error>> {
let com = ComRuntime::new()?;
// fn main() -> Result<(), Box<dyn std::error::Error>> {
// let com = ComRuntime::new()?;

if true {
let sb = ScheduleBuilder::new(&com).unwrap();
sb.create_daily()
.author("Matt")?
.description("Test Trigger 1")?
.trigger("test_trigger_1", true)?
.days_interval(1)?
.action(Action::new("test", "notepad.exe", "", ""))?
.start_boundary(&Local::now().to_rfc3339())?
.build()?
.register("TaskName1", TaskCreationFlags::CreateOrUpdate as i32)?;
}
// if true {
// let sb = ScheduleBuilder::new(&com).unwrap();
// sb.create_daily()
// .author("Matt")?
// .description("Test Trigger 1")?
// .trigger("test_trigger_1", true)?
// .days_interval(1)?
// .action(Action::new("test", "notepad.exe", "", ""))?
// .start_boundary(&Local::now().to_rfc3339())?
// .build()?
// .register("TaskName1", TaskCreationFlags::CreateOrUpdate as i32)?;
// }

if true {
let sb2 = ScheduleBuilder::new(&com).unwrap();
sb2.create_daily()
.author("Matt")?
.description("Test Trigger 2")?
.trigger("test_trigger_2", true)?
.days_interval(1)?
.action(Action::new("test", "notepad.exe", "", ""))?
.start_boundary(&Local::now().to_rfc3339())?
.build()?
.register("TaskName2", TaskCreationFlags::CreateOrUpdate as i32)?;
}
Ok(())
}
// if true {
// let sb2 = ScheduleBuilder::new(&com).unwrap();
// sb2.create_daily()
// .author("Matt")?
// .description("Test Trigger 2")?
// .trigger("test_trigger_2", true)?
// .days_interval(1)?
// .action(Action::new("test", "notepad.exe", "", ""))?
// .start_boundary(&Local::now().to_rfc3339())?
// .build()?
// .register("TaskName2", TaskCreationFlags::CreateOrUpdate as i32)?;
// }
// Ok(())
// }
46 changes: 21 additions & 25 deletions examples/various_settings_task.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
use chrono::prelude::*;
use planif::enums::TaskCreationFlags;
<<<<<<< HEAD
use planif::schedule_builder::{Action, ComRuntime, ScheduleBuilder};
=======
use planif::schedule_builder::{Action, ScheduleBuilder};
>>>>>>> origin/main
use planif::settings::Settings;
// use chrono::prelude::*;
// use planif::enums::TaskCreationFlags;
// use planif::schedule_builder::{Action, ComRuntime, ScheduleBuilder};
// use planif::settings::Settings;

fn main() -> Result<(), Box<dyn std::error::Error>> {
let com = ComRuntime::new()?;
let sb = ScheduleBuilder::new(&com).unwrap();
let mut settings = Settings::new();
settings.run_only_if_idle = Some(true);
// fn main() -> Result<(), Box<dyn std::error::Error>> {
// let com = ComRuntime::new()?;
// let sb = ScheduleBuilder::new(&com).unwrap();
// let mut settings = Settings::new();
// settings.run_only_if_idle = Some(true);

sb.create_daily()
.author("Matt")?
.description("Test Trigger")?
.settings(settings)?
.trigger("test_trigger", true)?
.days_interval(1)?
.action(Action::new("test", "notepad.exe", "", ""))?
.start_boundary(&Local::now().to_rfc3339())?
.build()?
.register("TaskName", TaskCreationFlags::CreateOrUpdate as i32)?;
// sb.create_daily()
// .author("Matt")?
// .description("Test Trigger")?
// .settings(settings)?
// .trigger("test_trigger", true)?
// .days_interval(1)?
// .action(Action::new("test", "notepad.exe", "", ""))?
// .start_boundary(&Local::now().to_rfc3339())?
// .build()?
// .register("TaskName", TaskCreationFlags::CreateOrUpdate as i32)?;

Ok(())
}
// Ok(())
// }
Loading