Skip to content

Commit d4e188b

Browse files
committed
Further work on schedule task history
1 parent 3e440a1 commit d4e188b

17 files changed

Lines changed: 349 additions & 132 deletions

File tree

src/Libraries/SmartStore.Core/Domain/Tasks/ScheduleTask.cs

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-

2-
using System;
1+
using System;
32
using System.Collections.Generic;
4-
using System.ComponentModel.DataAnnotations;
53
using System.ComponentModel.DataAnnotations.Schema;
64
using System.Diagnostics;
75
using SmartStore.Core.Data.Hooks;
@@ -49,45 +47,16 @@ public class ScheduleTask : BaseEntity, ICloneable<ScheduleTask>
4947
[Index("IX_NextRun_Enabled", 0)]
5048
public DateTime? NextRunUtc { get; set; }
5149

52-
[Index("IX_LastStart_LastEnd", 0)]
53-
public DateTime? LastStartUtc { get; set; }
54-
55-
[Index("IX_LastStart_LastEnd", 1)]
56-
public DateTime? LastEndUtc { get; set; }
57-
58-
public DateTime? LastSuccessUtc { get; set; }
59-
60-
public string LastError { get; set; }
61-
50+
/// <summary>
51+
/// Indicates whether the task is hidden.
52+
/// </summary>
6253
public bool IsHidden { get; set; }
6354

64-
/// <summary>
65-
/// Gets or sets a value indicating the current percentual progress for a running task
66-
/// </summary>
67-
public int? ProgressPercent { get; set; }
68-
69-
/// <summary>
70-
/// Gets or sets the current progress message for a running task
71-
/// </summary>
72-
public string ProgressMessage { get; set; }
73-
7455
/// <summary>
7556
/// Indicates whether the task runs separately on each server.
7657
/// </summary>
7758
public bool RunPerMachine { get; set; }
7859

79-
/// <summary>
80-
/// Gets a value indicating whether a task is running
81-
/// </summary>
82-
public bool IsRunning
83-
{
84-
get
85-
{
86-
var result = LastStartUtc.HasValue && LastStartUtc.Value > LastEndUtc.GetValueOrDefault();
87-
return result;
88-
}
89-
}
90-
9160
/// <summary>
9261
/// Gets a value indicating whether a task is scheduled for execution (Enabled = true and NextRunUtc &lt;= UtcNow )
9362
/// </summary>

src/Libraries/SmartStore.Core/Domain/Tasks/ScheduleTaskHistory.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace SmartStore.Core.Domain.Tasks
66
{
77
[Hookable(false)]
8-
public class ScheduleTaskHistory : BaseEntity
8+
public class ScheduleTaskHistory : BaseEntity, ICloneable<ScheduleTaskHistory>
99
{
1010
/// <summary>
1111
/// Gets or sets the schedule task identifier.
@@ -60,5 +60,17 @@ public class ScheduleTaskHistory : BaseEntity
6060
/// Gets or sets the schedule task.
6161
/// </summary>
6262
public virtual ScheduleTask ScheduleTask { get; set; }
63+
64+
public ScheduleTaskHistory Clone()
65+
{
66+
var clone = (ScheduleTaskHistory)this.MemberwiseClone();
67+
clone.ScheduleTask = this.ScheduleTask.Clone();
68+
return clone;
69+
}
70+
71+
object ICloneable.Clone()
72+
{
73+
return Clone();
74+
}
6375
}
6476
}

src/Libraries/SmartStore.Data/Mapping/Tasks/ScheduleTaskMap.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,8 @@ public ScheduleTaskMap()
1212
Property(t => t.Name).HasMaxLength(500).IsRequired();
1313
Property(t => t.Type).HasMaxLength(800).IsRequired();
1414
Property(t => t.Alias).HasMaxLength(500);
15-
Property(t => t.LastError).HasMaxLength(1000);
16-
Property(t => t.ProgressMessage).HasMaxLength(1000).IsOptional();
1715
Property(t => t.CronExpression).HasMaxLength(1000);
1816

19-
Ignore(t => t.IsRunning);
2017
Ignore(t => t.IsPending);
2118
}
2219
}

src/Libraries/SmartStore.Data/Migrations/201806231547270_ScheduleTaskHistory.Designer.cs

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
namespace SmartStore.Data.Migrations
2+
{
3+
using System;
4+
using System.Data.Entity.Migrations;
5+
6+
public partial class ScheduleTaskHistory : DbMigration
7+
{
8+
public override void Up()
9+
{
10+
DropIndex("dbo.ScheduleTask", "IX_LastStart_LastEnd");
11+
CreateTable(
12+
"dbo.ScheduleTaskHistory",
13+
c => new
14+
{
15+
Id = c.Int(nullable: false, identity: true),
16+
ScheduleTaskId = c.Int(nullable: false),
17+
IsRunning = c.Boolean(nullable: false),
18+
MachineName = c.String(maxLength: 400),
19+
StartedOnUtc = c.DateTime(nullable: false),
20+
FinishedOnUtc = c.DateTime(),
21+
SucceededOnUtc = c.DateTime(),
22+
Error = c.String(maxLength: 1000),
23+
ProgressPercent = c.Int(),
24+
ProgressMessage = c.String(maxLength: 1000),
25+
})
26+
.PrimaryKey(t => t.Id)
27+
.ForeignKey("dbo.ScheduleTask", t => t.ScheduleTaskId, cascadeDelete: true)
28+
.Index(t => t.ScheduleTaskId)
29+
.Index(t => new { t.MachineName, t.IsRunning })
30+
.Index(t => new { t.StartedOnUtc, t.FinishedOnUtc }, name: "IX_Started_Finished");
31+
32+
AddColumn("dbo.ScheduleTask", "RunPerMachine", c => c.Boolean(nullable: false));
33+
DropColumn("dbo.ScheduleTask", "LastStartUtc");
34+
DropColumn("dbo.ScheduleTask", "LastEndUtc");
35+
DropColumn("dbo.ScheduleTask", "LastSuccessUtc");
36+
DropColumn("dbo.ScheduleTask", "LastError");
37+
DropColumn("dbo.ScheduleTask", "ProgressPercent");
38+
DropColumn("dbo.ScheduleTask", "ProgressMessage");
39+
DropColumn("dbo.ScheduleTask", "RowVersion");
40+
}
41+
42+
public override void Down()
43+
{
44+
AddColumn("dbo.ScheduleTask", "RowVersion", c => c.Binary(nullable: false, fixedLength: true, timestamp: true, storeType: "rowversion"));
45+
AddColumn("dbo.ScheduleTask", "ProgressMessage", c => c.String(maxLength: 1000));
46+
AddColumn("dbo.ScheduleTask", "ProgressPercent", c => c.Int());
47+
AddColumn("dbo.ScheduleTask", "LastError", c => c.String(maxLength: 1000));
48+
AddColumn("dbo.ScheduleTask", "LastSuccessUtc", c => c.DateTime());
49+
AddColumn("dbo.ScheduleTask", "LastEndUtc", c => c.DateTime());
50+
AddColumn("dbo.ScheduleTask", "LastStartUtc", c => c.DateTime());
51+
DropForeignKey("dbo.ScheduleTaskHistory", "ScheduleTaskId", "dbo.ScheduleTask");
52+
DropIndex("dbo.ScheduleTaskHistory", "IX_Started_Finished");
53+
DropIndex("dbo.ScheduleTaskHistory", new[] { "MachineName", "IsRunning" });
54+
DropIndex("dbo.ScheduleTaskHistory", new[] { "ScheduleTaskId" });
55+
DropColumn("dbo.ScheduleTask", "RunPerMachine");
56+
DropTable("dbo.ScheduleTaskHistory");
57+
CreateIndex("dbo.ScheduleTask", new[] { "LastStartUtc", "LastEndUtc" }, name: "IX_LastStart_LastEnd");
58+
}
59+
}
60+
}

src/Libraries/SmartStore.Data/Migrations/201806231547270_ScheduleTaskHistory.resx

Lines changed: 126 additions & 0 deletions
Large diffs are not rendered by default.

src/Libraries/SmartStore.Data/SmartStore.Data.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,10 @@
591591
<Compile Include="Migrations\201806051221399_RefundReturnRequests.Designer.cs">
592592
<DependentUpon>201806051221399_RefundReturnRequests.cs</DependentUpon>
593593
</Compile>
594+
<Compile Include="Migrations\201806231547270_ScheduleTaskHistory.cs" />
595+
<Compile Include="Migrations\201806231547270_ScheduleTaskHistory.Designer.cs">
596+
<DependentUpon>201806231547270_ScheduleTaskHistory.cs</DependentUpon>
597+
</Compile>
594598
<Compile Include="ObjectContextBase.SaveChanges.cs" />
595599
<Compile Include="Setup\Builder\ActivityLogTypeMigrator.cs" />
596600
<Compile Include="Setup\Builder\PermissionMigrator.cs" />
@@ -1064,6 +1068,9 @@
10641068
<EmbeddedResource Include="Migrations\201806051221399_RefundReturnRequests.resx">
10651069
<DependentUpon>201806051221399_RefundReturnRequests.cs</DependentUpon>
10661070
</EmbeddedResource>
1071+
<EmbeddedResource Include="Migrations\201806231547270_ScheduleTaskHistory.resx">
1072+
<DependentUpon>201806231547270_ScheduleTaskHistory.cs</DependentUpon>
1073+
</EmbeddedResource>
10671074
<EmbeddedResource Include="Sql\Indexes.sql" />
10681075
<EmbeddedResource Include="Sql\StoredProcedures.sql" />
10691076
</ItemGroup>

src/Libraries/SmartStore.Services/DataExchange/Export/DataExportTask.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public DataExportTask(
2222

2323
public void Execute(TaskExecutionContext ctx)
2424
{
25-
var profileId = ctx.ScheduleTask.Alias.ToInt();
25+
var profileId = ctx.ScheduleTaskHistory.ScheduleTask.Alias.ToInt();
2626
var profile = _exportProfileService.GetExportProfileById(profileId);
2727

2828
// Load provider.

src/Libraries/SmartStore.Services/DataExchange/Export/ExportProfileService.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public virtual ExportProfile InsertExportProfile(
7878
{
7979
task = new ScheduleTask
8080
{
81-
CronExpression = "0 */6 * * *", // every six hours
81+
CronExpression = "0 */6 * * *", // Every six hours.
8282
Type = typeof(DataExportTask).AssemblyQualifiedNameWithoutVersion(),
8383
Enabled = false,
8484
StopOnError = false,
@@ -88,7 +88,6 @@ public virtual ExportProfile InsertExportProfile(
8888
else
8989
{
9090
task = cloneProfile.ScheduleTask.Clone();
91-
task.LastEndUtc = task.LastStartUtc = task.LastSuccessUtc = null;
9291
}
9392

9493
task.Name = string.Concat(name, " Task");

src/Libraries/SmartStore.Services/DataExchange/Import/DataImportTask.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public DataImportTask(
1818

1919
public void Execute(TaskExecutionContext ctx)
2020
{
21-
var profileId = ctx.ScheduleTask.Alias.ToInt();
21+
var profileId = ctx.ScheduleTaskHistory.ScheduleTask.Alias.ToInt();
2222
var profile = _importProfileService.GetImportProfileById(profileId);
2323

2424
var request = new DataImportRequest(profile);

0 commit comments

Comments
 (0)